--- old/modules/base/src/main/java/com/sun/javafx/binding/ExpressionHelper.java 2015-08-31 10:22:31.501218103 -0400 +++ new/modules/base/src/main/java/com/sun/javafx/binding/ExpressionHelper.java 2015-08-31 10:22:31.365218104 -0400 @@ -28,7 +28,6 @@ import javafx.beans.InvalidationListener; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; -import sun.util.logging.PlatformLogger; import java.util.Arrays; --- old/modules/base/src/test/java/javafx/beans/value/ObservableBooleanValueStub.java 2015-08-31 10:22:32.337218093 -0400 +++ new/modules/base/src/test/java/javafx/beans/value/ObservableBooleanValueStub.java 2015-08-31 10:22:32.125218095 -0400 @@ -46,4 +46,9 @@ public Boolean getValue() { return value; } + + @Override + public void fireValueChangedEvent() { + super.fireValueChangedEvent(); + } } --- old/modules/base/src/test/java/javafx/beans/value/ObservableDoubleValueStub.java 2015-08-31 10:22:33.109218084 -0400 +++ new/modules/base/src/test/java/javafx/beans/value/ObservableDoubleValueStub.java 2015-08-31 10:22:32.929218086 -0400 @@ -47,23 +47,28 @@ return value; } - @Override - public int intValue() { - return (int)value; - } + @Override + public int intValue() { + return (int) value; + } - @Override - public long longValue() { - return (long)value; - } + @Override + public long longValue() { + return (long) value; + } - @Override - public float floatValue() { - return (float)value; - } + @Override + public float floatValue() { + return (float) value; + } - @Override - public double doubleValue() { - return value; - } + @Override + public double doubleValue() { + return value; + } + + @Override + public void fireValueChangedEvent() { + super.fireValueChangedEvent(); + } } --- old/modules/base/src/test/java/javafx/beans/value/ObservableFloatValueStub.java 2015-08-31 10:22:33.737218077 -0400 +++ new/modules/base/src/test/java/javafx/beans/value/ObservableFloatValueStub.java 2015-08-31 10:22:33.601218079 -0400 @@ -47,23 +47,28 @@ return value; } - @Override - public int intValue() { - return (int)value; - } + @Override + public int intValue() { + return (int) value; + } + + @Override + public long longValue() { + return (long) value; + } - @Override - public long longValue() { - return (long)value; - } + @Override + public float floatValue() { + return value; + } - @Override - public float floatValue() { - return value; - } + @Override + public double doubleValue() { + return value; + } - @Override - public double doubleValue() { - return value; - } + @Override + public void fireValueChangedEvent() { + super.fireValueChangedEvent(); + } } --- old/modules/base/src/test/java/javafx/beans/value/ObservableObjectValueStub.java 2015-08-31 10:22:34.409218070 -0400 +++ new/modules/base/src/test/java/javafx/beans/value/ObservableObjectValueStub.java 2015-08-31 10:22:34.209218072 -0400 @@ -46,4 +46,10 @@ public T getValue() { return value; } + + @Override + public void fireValueChangedEvent() { + super.fireValueChangedEvent(); + } + } --- old/modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/ControlTestUtils.java 2015-08-31 10:22:35.013218063 -0400 +++ new/modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/ControlTestUtils.java 2015-08-31 10:22:34.877218065 -0400 @@ -40,7 +40,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; -import com.sun.javafx.binding.ExpressionHelperUtility; +import test.com.sun.javafx.binding.ExpressionHelperUtility; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; --- old/modules/controls/src/test/java/javafx/scene/control/TableViewTest.java 2015-08-31 10:22:35.689218055 -0400 +++ new/modules/controls/src/test/java/javafx/scene/control/TableViewTest.java 2015-08-31 10:22:35.473218058 -0400 @@ -54,7 +54,7 @@ import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; -import javafx.collections.MockSetObserver; +import test.javafx.collections.MockSetObserver; import javafx.collections.ObservableList; import javafx.collections.transformation.SortedList; import javafx.event.Event; --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/com/sun/javafx/binding/ExpressionHelperBaseShim.java 2015-08-31 10:22:36.197218050 -0400 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.sun.javafx.binding; + +public class ExpressionHelperBaseShim extends ExpressionHelperBase { + + public static int trim(int size, Object[] listeners) { + return ExpressionHelperBase.trim(size, listeners); + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/com/sun/javafx/binding/ExpressionHelperShim.java 2015-08-31 10:22:36.865218042 -0400 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.sun.javafx.binding; + +public class ExpressionHelperShim { + + public static void fireValueChangedEvent(ExpressionHelper helper) { + helper.fireValueChangedEvent(); + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/com/sun/javafx/event/CompositeEventHandlerShim.java 2015-08-31 10:22:37.569218034 -0400 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.sun.javafx.event; + +import javafx.event.EventHandler; +import javafx.event.WeakEventHandler; + +public class CompositeEventHandlerShim { + + public static boolean containsHandler(CompositeEventHandler handler, final EventHandler eventHandler) { + return handler.containsHandler(eventHandler); + } + + public static boolean containsFilter(CompositeEventHandler handler, final WeakEventHandler eventHandler) { + return handler.containsFilter(eventHandler); + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/beans/property/ReadOnlyListPropertyBaseShim.java 2015-08-31 10:22:38.233218027 -0400 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.beans.property; + +import javafx.collections.ListChangeListener; + +public class ReadOnlyListPropertyBaseShim { + + public static void fireValueChangedEvent(ReadOnlyListPropertyBase base) { + base.fireValueChangedEvent(); + } + + public static void fireValueChangedEvent(ReadOnlyListPropertyBase base, + ListChangeListener.Change change) { + base.fireValueChangedEvent(change); + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/beans/property/ReadOnlyMapPropertyBaseShim.java 2015-08-31 10:22:38.933218019 -0400 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.beans.property; + +import javafx.collections.MapChangeListener; + +public class ReadOnlyMapPropertyBaseShim { + + public static void fireValueChangedEvent(ReadOnlyMapPropertyBase base) { + base.fireValueChangedEvent(); + } + + public static void fireValueChangedEvent(ReadOnlyMapPropertyBase base, + MapChangeListener.Change change) { + base.fireValueChangedEvent(change); + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/beans/property/ReadOnlyObjectPropertyBaseShim.java 2015-08-31 10:22:39.717218010 -0400 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.beans.property; + +public class ReadOnlyObjectPropertyBaseShim { + + public static void fireValueChangedEvent(ReadOnlyObjectPropertyBase base) { + base.fireValueChangedEvent(); + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/beans/property/ReadOnlySetPropertyBaseShim.java 2015-08-31 10:22:40.513218001 -0400 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.beans.property; + +public class ReadOnlySetPropertyBaseShim { + + public static void fireValueChangedEvent(ReadOnlySetPropertyBase base) { + base.fireValueChangedEvent(); + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/collections/ListChangeBuilderShim.java 2015-08-31 10:22:41.249217993 -0400 @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package javafx.collections; + +import java.util.List; + +public class ListChangeBuilderShim { + + private ListChangeBuilder lcb; + + public ListChangeBuilderShim(ObservableListBase list) { + lcb = new ListChangeBuilder(list); + } + + public ListChangeBuilder getBuilder() { + return lcb; + } + + public void beginChange() { + lcb.beginChange(); + } + + public void endChange() { + lcb.endChange(); + } + + public void nextRemove(int idx, List removed) { + lcb.nextRemove(idx, removed); + } + + public void nextRemove(int idx, E removed) { + lcb.nextRemove(idx, removed); + } + + public void nextAdd(int from, int to) { + lcb.nextAdd(from, to); + } + + public void nextPermutation(int from, int to, int[] perm) { + lcb.nextPermutation(from, to, perm); + } + + public void nextReplace(int from, int to, List removed) { + lcb.nextReplace(from, to, removed); + } + + public final void nextUpdate(int pos) { + lcb.nextUpdate(pos); + } + + public final void nextSet(int idx, E old) { + lcb.nextSet(idx, old); + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/collections/ObservableListWrapperShim.java 2015-08-31 10:22:42.053217984 -0400 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package javafx.collections; + +import com.sun.javafx.collections.ListListenerHelper; +import com.sun.javafx.collections.ObservableListWrapper; +import java.util.List; +import javafx.beans.InvalidationListener; + +public class ObservableListWrapperShim extends ObservableListWrapper { + + + public ObservableListWrapperShim(List list) { + super(list); + } + + //------------------------------------ + + public static final void fireChange( + ObservableListWrapper wrapper, + ListChangeListener.Change change) { + wrapper.fireChange(change); + } + + public static final void beginChange(ObservableListWrapper wrapper) { + wrapper.beginChange(); + } + + public static final void endChange(ObservableListWrapper wrapper) { + wrapper.endChange(); + } + + public static final void nextUpdate(ObservableListWrapper wrapper, int i) { + wrapper.nextUpdate(i); + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/event/EventTypeShim.java 2015-08-31 10:22:42.713217976 -0400 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.event; + +import java.util.List; + +public class EventTypeShim { + + public static Object getEventTypeSerialization(List path) { + return new EventType.EventTypeSerialization(path); + } + + public static class EventTypeSerializationShim extends EventType.EventTypeSerialization { + + public EventTypeSerializationShim(List path) { + super(path); + } + + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/util/converter/DateTimeStringConverterShim.java 2015-08-31 10:22:43.385217969 -0400 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.util.converter; + +import java.text.DateFormat; +import java.util.Locale; + +public class DateTimeStringConverterShim { + + public static int getTimeStyle(DateTimeStringConverter tsc) { + return tsc.timeStyle; + } + + public static String getPattern(DateTimeStringConverter tsc) { + return tsc.pattern; + } + + public static int getDateStyle(DateTimeStringConverter tsc) { + return tsc.dateStyle; + } + + public static DateFormat getDateFormat(DateTimeStringConverter tsc) { + return tsc.getDateFormat(); + } + + public static DateFormat getDateFormatVar(DateTimeStringConverter tsc) { + return tsc.dateFormat; + } + + public static Locale getLocale(DateTimeStringConverter tsc) { + return tsc.locale; + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/util/converter/LocalDateStringConverterShim.java 2015-08-31 10:22:44.201217960 -0400 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.util.converter; + +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.util.Locale; + +public class LocalDateStringConverterShim { + + public static DateTimeFormatter getldtConverterFormatter(LocalDateStringConverter c) { + return c.ldtConverter.formatter; + } + //----------------------------------------------------- + + //--------- + public static Locale getldtConverterLocale(LocalDateStringConverter c) { + return c.ldtConverter.locale; + } + + public static DateTimeFormatter getldtConverterParser(LocalDateStringConverter c) { + return c.ldtConverter.parser; + } + + public static FormatStyle getldtConverterTimeStyle(LocalDateStringConverter c) { + return c.ldtConverter.timeStyle; + } + + public static FormatStyle getldtConverterDateStyle(LocalDateStringConverter c) { + return c.ldtConverter.dateStyle; + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/util/converter/LocalDateTimeStringConverterShim.java 2015-08-31 10:22:44.845217953 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.util.converter; + +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.util.Locale; + +public class LocalDateTimeStringConverterShim { + + public static DateTimeFormatter getldtConverterParser(LocalDateTimeStringConverter c) { + return c.ldtConverter.parser; + } + + public static DateTimeFormatter getldtConverterFormatter(LocalDateTimeStringConverter c) { + return c.ldtConverter.formatter; + } + + public static Locale getldtConverterLocale(LocalDateTimeStringConverter c) { + return c.ldtConverter.locale; + } + + public static FormatStyle getldtConverterTimeStyle(LocalDateTimeStringConverter c) { + return c.ldtConverter.timeStyle; + } + + public static FormatStyle getldtConverterDateStyle(LocalDateTimeStringConverter c) { + return c.ldtConverter.dateStyle; + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/util/converter/LocalTimeStringConverterShim.java 2015-08-31 10:22:45.581217944 -0400 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.util.converter; + +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.util.Locale; + +public class LocalTimeStringConverterShim { + + public static Locale getldtConverterLocale(LocalTimeStringConverter c) { + return c.ldtConverter.locale; + } + + public static FormatStyle getldtConverterDateStyle(LocalTimeStringConverter c) { + return c.ldtConverter.dateStyle; + } + + public static FormatStyle getldtConverterTimeStyle(LocalTimeStringConverter c) { + return c.ldtConverter.timeStyle; + } + + public static DateTimeFormatter getldtConverterParser(LocalTimeStringConverter c) { + return c.ldtConverter.parser; + } + + public static DateTimeFormatter getldtConverterFormatter(LocalTimeStringConverter c) { + return c.ldtConverter.formatter; + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/javafx/util/converter/NumberStringConverterShim.java 2015-08-31 10:22:46.245217937 -0400 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.util.converter; + +import java.text.NumberFormat; +import java.util.Locale; + +public class NumberStringConverterShim { + + public static NumberFormat getNumberFormatVar(NumberStringConverter nsc) { + return nsc.numberFormat; + } + + public static NumberFormat getNumberFormat(NumberStringConverter nsc) { + return nsc.getNumberFormat(); + } + + public static String getPattern(NumberStringConverter nsc) { + return nsc.pattern; + } + + //----------------------------------------------------- + public static Locale getLocale(NumberStringConverter nsc) { + return nsc.locale; + } + +} --- old/modules/base/src/test/java/com/sun/javafx/binding/BidirectionalBindingTest.java 2015-08-31 10:22:47.117217927 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,330 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import javafx.beans.binding.Bindings; -import javafx.beans.property.*; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import java.util.Arrays; -import java.util.Collection; -import javafx.beans.value.ObservableValue; - -import static org.junit.Assert.*; - -@RunWith(Parameterized.class) -public class BidirectionalBindingTest { - - @FunctionalInterface - public static interface PropertyFactory { - Property createProperty(); - } - - public static class Factory { - - private PropertyFactory propertyFactory; - private T[] values; - public Factory(PropertyFactory propertyFactory, T[] values) { - this.propertyFactory = propertyFactory; - this.values = values; - } - public Property createProperty() { - return propertyFactory.createProperty(); - } - public T[] getValues() { - return values; - } - } - - private Factory factory; - private Property op1; - private Property op2; - private Property op3; - private Property op4; - private T[] v; - - public BidirectionalBindingTest(Factory factory) { - this.factory = factory; - } - - @Before - public void setUp() { - op1 = factory.createProperty(); - op2 = factory.createProperty(); - op3 = factory.createProperty(); - op4 = factory.createProperty(); - v = factory.getValues(); - op1.setValue(v[0]); - op2.setValue(v[1]); - } - - @Test - public void testBind() { - Bindings.bindBidirectional(op1, op2); - Bindings.bindBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(v[1], op1.getValue()); - assertEquals(v[1], op2.getValue()); - - op1.setValue(v[2]); - assertEquals(v[2], op1.getValue()); - assertEquals(v[2], op2.getValue()); - - op2.setValue(v[3]); - assertEquals(v[3], op1.getValue()); - assertEquals(v[3], op2.getValue()); - } - - @Test - public void testUnbind() { - // unbind non-existing binding => no-op - Bindings.unbindBidirectional(op1, op2); - - // unbind properties of different beans - Bindings.bindBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(v[1], op1.getValue()); - assertEquals(v[1], op2.getValue()); - - Bindings.unbindBidirectional(op1, op2); - System.gc(); - assertEquals(v[1], op1.getValue()); - assertEquals(v[1], op2.getValue()); - - op1.setValue(v[2]); - assertEquals(v[2], op1.getValue()); - assertEquals(v[1], op2.getValue()); - - op2.setValue(v[3]); - assertEquals(v[2], op1.getValue()); - assertEquals(v[3], op2.getValue()); - } - - @Test - public void testChaining() { - op3.setValue(v[2]); - Bindings.bindBidirectional(op1, op2); - Bindings.bindBidirectional(op2, op3); - System.gc(); // making sure we did not not overdo weak references - assertEquals(v[2], op1.getValue()); - assertEquals(v[2], op2.getValue()); - assertEquals(v[2], op3.getValue()); - - op1.setValue(v[3]); - assertEquals(v[3], op1.getValue()); - assertEquals(v[3], op2.getValue()); - assertEquals(v[3], op3.getValue()); - - op2.setValue(v[0]); - assertEquals(v[0], op1.getValue()); - assertEquals(v[0], op2.getValue()); - assertEquals(v[0], op3.getValue()); - - op3.setValue(v[1]); - assertEquals(v[1], op1.getValue()); - assertEquals(v[1], op2.getValue()); - assertEquals(v[1], op3.getValue()); - - // now unbind - Bindings.unbindBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(v[1], op1.getValue()); - assertEquals(v[1], op2.getValue()); - assertEquals(v[1], op3.getValue()); - - op1.setValue(v[2]); - assertEquals(v[2], op1.getValue()); - assertEquals(v[1], op2.getValue()); - assertEquals(v[1], op3.getValue()); - - op2.setValue(v[3]); - assertEquals(v[2], op1.getValue()); - assertEquals(v[3], op2.getValue()); - assertEquals(v[3], op3.getValue()); - - op3.setValue(v[0]); - assertEquals(v[2], op1.getValue()); - assertEquals(v[0], op2.getValue()); - assertEquals(v[0], op3.getValue()); - } - - private int getListenerCount(ObservableValue v) { - return ExpressionHelperUtility.getChangeListeners(v).size(); - } - - @Test - public void testWeakReferencing() { - Bindings.bindBidirectional(op1, op2); - - assertEquals(1, getListenerCount(op1)); - assertEquals(1, getListenerCount(op2)); - - op1 = null; - System.gc(); - op2.setValue(v[2]); - assertEquals(0, getListenerCount(op2)); - - Bindings.bindBidirectional(op2, op3); - assertEquals(1, getListenerCount(op2)); - assertEquals(1, getListenerCount(op3)); - - op3 = null; - System.gc(); - op2.setValue(v[0]); - assertEquals(0, getListenerCount(op2)); - } - - @Test - public void testHashCode() { - final int hc1 = BidirectionalBinding.bind(op1, op2).hashCode(); - final int hc2 = BidirectionalBinding.bind(op2, op1).hashCode(); - assertEquals(hc1, hc2); - } - - @Test - public void testEquals() { - final BidirectionalBinding golden = BidirectionalBinding.bind(op1, op2); - - assertTrue(golden.equals(golden)); - assertFalse(golden.equals(null)); - assertFalse(golden.equals(op1)); - assertTrue(golden.equals(BidirectionalBinding.bind(op1, op2))); - assertTrue(golden.equals(BidirectionalBinding.bind(op2, op1))); - assertFalse(golden.equals(BidirectionalBinding.bind(op1, op3))); - assertFalse(golden.equals(BidirectionalBinding.bind(op3, op1))); - assertFalse(golden.equals(BidirectionalBinding.bind(op3, op2))); - assertFalse(golden.equals(BidirectionalBinding.bind(op2, op3))); - } - - @Test - public void testEqualsWithGCedProperty() { - final BidirectionalBinding binding1 = BidirectionalBinding.bind(op1, op2); - final BidirectionalBinding binding2 = BidirectionalBinding.bind(op1, op2); - final BidirectionalBinding binding3 = BidirectionalBinding.bind(op2, op1); - final BidirectionalBinding binding4 = BidirectionalBinding.bind(op2, op1); - op1 = null; - System.gc(); - - assertTrue(binding1.equals(binding1)); - assertFalse(binding1.equals(binding2)); - assertFalse(binding1.equals(binding3)); - - assertTrue(binding3.equals(binding3)); - assertFalse(binding3.equals(binding1)); - assertFalse(binding3.equals(binding4)); - } - - @Test(expected=NullPointerException.class) - public void testBind_Null_X() { - Bindings.bindBidirectional(null, op2); - } - - @Test(expected=NullPointerException.class) - public void testBind_X_Null() { - Bindings.bindBidirectional(op1, null); - } - - @Test(expected=IllegalArgumentException.class) - public void testBind_X_Self() { - Bindings.bindBidirectional(op1, op1); - } - - @Test(expected=NullPointerException.class) - public void testUnbind_Null_X() { - Bindings.unbindBidirectional(null, op2); - } - - @Test(expected=NullPointerException.class) - public void testUnbind_X_Null() { - Bindings.unbindBidirectional(op1, null); - } - - @Test(expected=IllegalArgumentException.class) - public void testUnbind_X_Self() { - Bindings.unbindBidirectional(op1, op1); - } - - @Test - public void testBrokenBind() { - Bindings.bindBidirectional(op1, op2); - op1.bind(op3); - assertEquals(op3.getValue(), op1.getValue()); - assertEquals(op2.getValue(), op1.getValue()); - - op2.setValue(v[2]); - assertEquals(op3.getValue(), op1.getValue()); - assertEquals(op2.getValue(), op1.getValue()); - } - - @Test - public void testDoubleBrokenBind() { - Bindings.bindBidirectional(op1, op2); - op1.bind(op3); - op4.setValue(v[0]); - - op2.bind(op4); - assertEquals(op4.getValue(), op2.getValue()); - assertEquals(op3.getValue(), op1.getValue()); - // Test that bidirectional binding was unbound in this case - op3.setValue(v[0]); - op4.setValue(v[1]); - assertEquals(op4.getValue(), op2.getValue()); - assertEquals(op3.getValue(), op1.getValue()); - assertEquals(v[0], op1.getValue()); - assertEquals(v[1], op2.getValue()); - } - - @Parameterized.Parameters - public static Collection parameters() { - final Boolean[] booleanData = new Boolean[] {true, false, true, false}; - final Double[] doubleData = new Double[] {2348.2345, -92.214, -214.0214, -908.214}; - final Float[] floatData = new Float[] {-3592.9f, 234872.8347f, 3897.274f, 3958.938745f}; - final Integer[] integerData = new Integer[] {248, -9384, -234, -34}; - final Long[] longData = new Long[] {9823984L, 2908934L, -234234L, 9089234L}; - final Object[] objectData = new Object[] {new Object(), new Object(), new Object(), new Object()}; - final String[] stringData = new String[] {"A", "B", "C", "D"}; - - return Arrays.asList(new Object[][] { - { new Factory(() -> new SimpleBooleanProperty(), booleanData) }, - { new Factory(() -> new SimpleDoubleProperty(), doubleData) }, - { new Factory(() -> new SimpleFloatProperty(), floatData) }, - { new Factory(() -> new SimpleIntegerProperty(), integerData) }, - { new Factory(() -> new SimpleLongProperty(), longData) }, - { new Factory(() -> new SimpleObjectProperty<>(), objectData) }, - { new Factory(() -> new SimpleStringProperty(), stringData) }, - { new Factory(() -> new ReadOnlyBooleanWrapper(), booleanData) }, - { new Factory(() -> new ReadOnlyDoubleWrapper(), doubleData) }, - { new Factory(() -> new ReadOnlyFloatWrapper(), floatData) }, - { new Factory(() -> new ReadOnlyIntegerWrapper(), integerData) }, - { new Factory(() -> new ReadOnlyLongWrapper(), longData) }, - { new Factory(() -> new ReadOnlyObjectWrapper<>(), objectData) }, - { new Factory(() -> new ReadOnlyStringWrapper(), stringData) }, - }); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/BidirectionalBindingTest.java 2015-08-31 10:22:46.981217929 -0400 @@ -0,0 +1,331 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.BidirectionalBinding; +import javafx.beans.binding.Bindings; +import javafx.beans.property.*; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; +import java.util.Collection; +import javafx.beans.value.ObservableValue; + +import static org.junit.Assert.*; + +@RunWith(Parameterized.class) +public class BidirectionalBindingTest { + + @FunctionalInterface + public static interface PropertyFactory { + Property createProperty(); + } + + public static class Factory { + + private PropertyFactory propertyFactory; + private T[] values; + public Factory(PropertyFactory propertyFactory, T[] values) { + this.propertyFactory = propertyFactory; + this.values = values; + } + public Property createProperty() { + return propertyFactory.createProperty(); + } + public T[] getValues() { + return values; + } + } + + private Factory factory; + private Property op1; + private Property op2; + private Property op3; + private Property op4; + private T[] v; + + public BidirectionalBindingTest(Factory factory) { + this.factory = factory; + } + + @Before + public void setUp() { + op1 = factory.createProperty(); + op2 = factory.createProperty(); + op3 = factory.createProperty(); + op4 = factory.createProperty(); + v = factory.getValues(); + op1.setValue(v[0]); + op2.setValue(v[1]); + } + + @Test + public void testBind() { + Bindings.bindBidirectional(op1, op2); + Bindings.bindBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(v[1], op1.getValue()); + assertEquals(v[1], op2.getValue()); + + op1.setValue(v[2]); + assertEquals(v[2], op1.getValue()); + assertEquals(v[2], op2.getValue()); + + op2.setValue(v[3]); + assertEquals(v[3], op1.getValue()); + assertEquals(v[3], op2.getValue()); + } + + @Test + public void testUnbind() { + // unbind non-existing binding => no-op + Bindings.unbindBidirectional(op1, op2); + + // unbind properties of different beans + Bindings.bindBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(v[1], op1.getValue()); + assertEquals(v[1], op2.getValue()); + + Bindings.unbindBidirectional(op1, op2); + System.gc(); + assertEquals(v[1], op1.getValue()); + assertEquals(v[1], op2.getValue()); + + op1.setValue(v[2]); + assertEquals(v[2], op1.getValue()); + assertEquals(v[1], op2.getValue()); + + op2.setValue(v[3]); + assertEquals(v[2], op1.getValue()); + assertEquals(v[3], op2.getValue()); + } + + @Test + public void testChaining() { + op3.setValue(v[2]); + Bindings.bindBidirectional(op1, op2); + Bindings.bindBidirectional(op2, op3); + System.gc(); // making sure we did not not overdo weak references + assertEquals(v[2], op1.getValue()); + assertEquals(v[2], op2.getValue()); + assertEquals(v[2], op3.getValue()); + + op1.setValue(v[3]); + assertEquals(v[3], op1.getValue()); + assertEquals(v[3], op2.getValue()); + assertEquals(v[3], op3.getValue()); + + op2.setValue(v[0]); + assertEquals(v[0], op1.getValue()); + assertEquals(v[0], op2.getValue()); + assertEquals(v[0], op3.getValue()); + + op3.setValue(v[1]); + assertEquals(v[1], op1.getValue()); + assertEquals(v[1], op2.getValue()); + assertEquals(v[1], op3.getValue()); + + // now unbind + Bindings.unbindBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(v[1], op1.getValue()); + assertEquals(v[1], op2.getValue()); + assertEquals(v[1], op3.getValue()); + + op1.setValue(v[2]); + assertEquals(v[2], op1.getValue()); + assertEquals(v[1], op2.getValue()); + assertEquals(v[1], op3.getValue()); + + op2.setValue(v[3]); + assertEquals(v[2], op1.getValue()); + assertEquals(v[3], op2.getValue()); + assertEquals(v[3], op3.getValue()); + + op3.setValue(v[0]); + assertEquals(v[2], op1.getValue()); + assertEquals(v[0], op2.getValue()); + assertEquals(v[0], op3.getValue()); + } + + private int getListenerCount(ObservableValue v) { + return ExpressionHelperUtility.getChangeListeners(v).size(); + } + + @Test + public void testWeakReferencing() { + Bindings.bindBidirectional(op1, op2); + + assertEquals(1, getListenerCount(op1)); + assertEquals(1, getListenerCount(op2)); + + op1 = null; + System.gc(); + op2.setValue(v[2]); + assertEquals(0, getListenerCount(op2)); + + Bindings.bindBidirectional(op2, op3); + assertEquals(1, getListenerCount(op2)); + assertEquals(1, getListenerCount(op3)); + + op3 = null; + System.gc(); + op2.setValue(v[0]); + assertEquals(0, getListenerCount(op2)); + } + + @Test + public void testHashCode() { + final int hc1 = BidirectionalBinding.bind(op1, op2).hashCode(); + final int hc2 = BidirectionalBinding.bind(op2, op1).hashCode(); + assertEquals(hc1, hc2); + } + + @Test + public void testEquals() { + final BidirectionalBinding golden = BidirectionalBinding.bind(op1, op2); + + assertTrue(golden.equals(golden)); + assertFalse(golden.equals(null)); + assertFalse(golden.equals(op1)); + assertTrue(golden.equals(BidirectionalBinding.bind(op1, op2))); + assertTrue(golden.equals(BidirectionalBinding.bind(op2, op1))); + assertFalse(golden.equals(BidirectionalBinding.bind(op1, op3))); + assertFalse(golden.equals(BidirectionalBinding.bind(op3, op1))); + assertFalse(golden.equals(BidirectionalBinding.bind(op3, op2))); + assertFalse(golden.equals(BidirectionalBinding.bind(op2, op3))); + } + + @Test + public void testEqualsWithGCedProperty() { + final BidirectionalBinding binding1 = BidirectionalBinding.bind(op1, op2); + final BidirectionalBinding binding2 = BidirectionalBinding.bind(op1, op2); + final BidirectionalBinding binding3 = BidirectionalBinding.bind(op2, op1); + final BidirectionalBinding binding4 = BidirectionalBinding.bind(op2, op1); + op1 = null; + System.gc(); + + assertTrue(binding1.equals(binding1)); + assertFalse(binding1.equals(binding2)); + assertFalse(binding1.equals(binding3)); + + assertTrue(binding3.equals(binding3)); + assertFalse(binding3.equals(binding1)); + assertFalse(binding3.equals(binding4)); + } + + @Test(expected=NullPointerException.class) + public void testBind_Null_X() { + Bindings.bindBidirectional(null, op2); + } + + @Test(expected=NullPointerException.class) + public void testBind_X_Null() { + Bindings.bindBidirectional(op1, null); + } + + @Test(expected=IllegalArgumentException.class) + public void testBind_X_Self() { + Bindings.bindBidirectional(op1, op1); + } + + @Test(expected=NullPointerException.class) + public void testUnbind_Null_X() { + Bindings.unbindBidirectional(null, op2); + } + + @Test(expected=NullPointerException.class) + public void testUnbind_X_Null() { + Bindings.unbindBidirectional(op1, null); + } + + @Test(expected=IllegalArgumentException.class) + public void testUnbind_X_Self() { + Bindings.unbindBidirectional(op1, op1); + } + + @Test + public void testBrokenBind() { + Bindings.bindBidirectional(op1, op2); + op1.bind(op3); + assertEquals(op3.getValue(), op1.getValue()); + assertEquals(op2.getValue(), op1.getValue()); + + op2.setValue(v[2]); + assertEquals(op3.getValue(), op1.getValue()); + assertEquals(op2.getValue(), op1.getValue()); + } + + @Test + public void testDoubleBrokenBind() { + Bindings.bindBidirectional(op1, op2); + op1.bind(op3); + op4.setValue(v[0]); + + op2.bind(op4); + assertEquals(op4.getValue(), op2.getValue()); + assertEquals(op3.getValue(), op1.getValue()); + // Test that bidirectional binding was unbound in this case + op3.setValue(v[0]); + op4.setValue(v[1]); + assertEquals(op4.getValue(), op2.getValue()); + assertEquals(op3.getValue(), op1.getValue()); + assertEquals(v[0], op1.getValue()); + assertEquals(v[1], op2.getValue()); + } + + @Parameterized.Parameters + public static Collection parameters() { + final Boolean[] booleanData = new Boolean[] {true, false, true, false}; + final Double[] doubleData = new Double[] {2348.2345, -92.214, -214.0214, -908.214}; + final Float[] floatData = new Float[] {-3592.9f, 234872.8347f, 3897.274f, 3958.938745f}; + final Integer[] integerData = new Integer[] {248, -9384, -234, -34}; + final Long[] longData = new Long[] {9823984L, 2908934L, -234234L, 9089234L}; + final Object[] objectData = new Object[] {new Object(), new Object(), new Object(), new Object()}; + final String[] stringData = new String[] {"A", "B", "C", "D"}; + + return Arrays.asList(new Object[][] { + { new Factory(() -> new SimpleBooleanProperty(), booleanData) }, + { new Factory(() -> new SimpleDoubleProperty(), doubleData) }, + { new Factory(() -> new SimpleFloatProperty(), floatData) }, + { new Factory(() -> new SimpleIntegerProperty(), integerData) }, + { new Factory(() -> new SimpleLongProperty(), longData) }, + { new Factory(() -> new SimpleObjectProperty<>(), objectData) }, + { new Factory(() -> new SimpleStringProperty(), stringData) }, + { new Factory(() -> new ReadOnlyBooleanWrapper(), booleanData) }, + { new Factory(() -> new ReadOnlyDoubleWrapper(), doubleData) }, + { new Factory(() -> new ReadOnlyFloatWrapper(), floatData) }, + { new Factory(() -> new ReadOnlyIntegerWrapper(), integerData) }, + { new Factory(() -> new ReadOnlyLongWrapper(), longData) }, + { new Factory(() -> new ReadOnlyObjectWrapper<>(), objectData) }, + { new Factory(() -> new ReadOnlyStringWrapper(), stringData) }, + }); + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/BidirectionalBindingWithConversionTest.java 2015-08-31 10:22:47.765217920 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,316 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import javafx.beans.InvalidationListener; -import javafx.beans.binding.Bindings; -import javafx.beans.property.*; -import javafx.beans.value.ChangeListener; -import javafx.util.StringConverter; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import java.text.DateFormat; -import java.text.ParseException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.Locale; - -import static org.junit.Assert.*; - -@RunWith(Parameterized.class) -public class BidirectionalBindingWithConversionTest { - - public static interface Functions { - PropertyMock create0(); - PropertyMock create1(); - void bind(PropertyMock obj0, PropertyMock obj1); - void unbind(Object obj0, Object obj1); - Object createBindingDirectly(PropertyMock op0, PropertyMock op1); - void check0(U obj0, U obj1); - void check1(V obj0, V obj1); - } - - private final Functions func; - private final S[] v0; - private final T[] v1; - - private PropertyMock op0; - private PropertyMock op1; - - public BidirectionalBindingWithConversionTest(Functions func, S[] v0, T[] v1) { - this.op0 = func.create0(); - this.op1 = func.create1(); - this.func = func; - this.v0 = v0; - this.v1 = v1; - } - - @Before - public void setUp() { - op0.setValue(v0[0]); - op1.setValue(v1[1]); - } - - @Test - public void testBind() { - func.bind(op0, op1); - System.gc(); // making sure we did not not overdo weak references - func.check0(v0[1], op0.getValue()); - func.check1(v1[1], op1.getValue()); - - op0.setValue(v0[2]); - func.check0(v0[2], op0.getValue()); - func.check1(v1[2], op1.getValue()); - - op1.setValue(v1[3]); - func.check0(v0[3], op0.getValue()); - func.check1(v1[3], op1.getValue()); - } - - @Test - public void testUnbind() { - // unbind non-existing binding => no-op - func.unbind(op0, op1); - - // unbind properties of different beans - func.bind(op0, op1); - System.gc(); // making sure we did not not overdo weak references - func.check0(v0[1], op0.getValue()); - func.check1(v1[1], op1.getValue()); - - func.unbind(op0, op1); - System.gc(); - func.check0(v0[1], op0.getValue()); - func.check1(v1[1], op1.getValue()); - - op0.setValue(v0[2]); - func.check0(v0[2], op0.getValue()); - func.check1(v1[1], op1.getValue()); - - op1.setValue(v1[3]); - func.check0(v0[2], op0.getValue()); - func.check1(v1[3], op1.getValue()); - } - - @Test - public void testWeakReferencing() { - func.bind(op0, op1); - assertEquals(1, op0.getListenerCount()); - assertEquals(1, op1.getListenerCount()); - - op0 = null; - System.gc(); - op1.setValue(v1[2]); - assertEquals(0, op1.getListenerCount()); - - this.op0 = func.create0(); - func.bind(op0, op1); - assertEquals(1, op0.getListenerCount()); - assertEquals(1, op1.getListenerCount()); - - op1 = null; - System.gc(); - op0.setValue(v0[3]); - assertEquals(0, op0.getListenerCount()); - } - - @Test(expected=NullPointerException.class) - public void testBind_Null_X() { - func.bind(null, op1); - } - - @Test(expected=NullPointerException.class) - public void testBind_X_Null() { - func.bind(op0, null); - } - - @Test(expected=NullPointerException.class) - public void testUnbind_Null_X() { - func.unbind(null, op1); - } - - @Test(expected=NullPointerException.class) - public void testUnbind_X_Null() { - func.unbind(op0, null); - } - - @Test(expected=IllegalArgumentException.class) - public void testUnbind_X_Self() { - func.unbind(op0, op0); - } - - @Parameterized.Parameters - public static Collection parameters() { - final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US); - final Date[] dates = new Date[] {new Date(), new Date(0), new Date(Integer.MAX_VALUE), new Date(Long.MAX_VALUE)}; - final String[] strings = new String[] {format.format(dates[0]), format.format(dates[1]), format.format(dates[2]), format.format(dates[3])}; - - final StringConverter converter = new StringConverter() { - @Override - public String toString(Date object) { - return format.format(object); - } - - @Override - public Date fromString(String string) { - try { - return format.parse(string); - } catch (ParseException e) { - return null; - } - } - }; - - return Arrays.asList(new Object[][] { - // Format - { - new Functions() { - @Override - public PropertyMock create0() { - return new StringPropertyMock(); - } - @Override - public PropertyMock create1() { - return new ObjectPropertyMock(); - } - @Override - public void bind(PropertyMock op0, PropertyMock op1) { - Bindings.bindBidirectional(op0, op1, format); - } - @Override - public void unbind(Object op0, Object op1) { - Bindings.unbindBidirectional(op0, op1); - } - @Override - public Object createBindingDirectly(PropertyMock op0, PropertyMock op1) { - return BidirectionalBinding.bind(op0, op1, format); - } - - @Override - public void check0(String obj0, String obj1) { - assertEquals(obj0, obj1); - } - - @Override - public void check1(Date obj0, Date obj1) { - assertEquals(obj0.toString(), obj1.toString()); - } - }, - strings, - dates - }, - // Converter - { - new Functions() { - @Override - public PropertyMock create0() { - return new StringPropertyMock(); - } - @Override - public PropertyMock create1() { - return new ObjectPropertyMock(); - } - @Override - public void bind(PropertyMock op0, PropertyMock op1) { - Bindings.bindBidirectional(op0, op1, converter); - } - @Override - public void unbind(Object op0, Object op1) { - Bindings.unbindBidirectional(op0, op1); - } - @Override - public Object createBindingDirectly(PropertyMock op0, PropertyMock op1) { - return BidirectionalBinding.bind(op0, op1, converter); - } - - @Override - public void check0(String obj0, String obj1) { - assertEquals(obj0, obj1); - } - - @Override - public void check1(Date obj0, Date obj1) { - assertEquals(obj0.toString(), obj1.toString()); - } - }, - strings, - dates - }, - }); - } - - private interface PropertyMock extends Property { - int getListenerCount(); - } - - private static class ObjectPropertyMock extends SimpleObjectProperty implements PropertyMock { - - private int listenerCount = 0; - - @Override - public int getListenerCount() { - return listenerCount; - } - - @Override - public void addListener(ChangeListener listener) { - super.addListener(listener); - listenerCount++; - } - - @Override - public void removeListener(ChangeListener listener) { - super.removeListener(listener); - listenerCount--; - } - } - - private static class StringPropertyMock extends SimpleStringProperty implements PropertyMock { - - private int listenerCount = 0; - - @Override - public int getListenerCount() { - return listenerCount; - } - - @Override - public void addListener(ChangeListener listener) { - super.addListener(listener); - listenerCount++; - } - - @Override - public void removeListener(ChangeListener listener) { - super.removeListener(listener); - listenerCount--; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/BidirectionalBindingWithConversionTest.java 2015-08-31 10:22:47.629217921 -0400 @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.BidirectionalBinding; +import javafx.beans.InvalidationListener; +import javafx.beans.binding.Bindings; +import javafx.beans.property.*; +import javafx.beans.value.ChangeListener; +import javafx.util.StringConverter; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.text.DateFormat; +import java.text.ParseException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.Locale; + +import static org.junit.Assert.*; + +@RunWith(Parameterized.class) +public class BidirectionalBindingWithConversionTest { + + public static interface Functions { + PropertyMock create0(); + PropertyMock create1(); + void bind(PropertyMock obj0, PropertyMock obj1); + void unbind(Object obj0, Object obj1); + Object createBindingDirectly(PropertyMock op0, PropertyMock op1); + void check0(U obj0, U obj1); + void check1(V obj0, V obj1); + } + + private final Functions func; + private final S[] v0; + private final T[] v1; + + private PropertyMock op0; + private PropertyMock op1; + + public BidirectionalBindingWithConversionTest(Functions func, S[] v0, T[] v1) { + this.op0 = func.create0(); + this.op1 = func.create1(); + this.func = func; + this.v0 = v0; + this.v1 = v1; + } + + @Before + public void setUp() { + op0.setValue(v0[0]); + op1.setValue(v1[1]); + } + + @Test + public void testBind() { + func.bind(op0, op1); + System.gc(); // making sure we did not not overdo weak references + func.check0(v0[1], op0.getValue()); + func.check1(v1[1], op1.getValue()); + + op0.setValue(v0[2]); + func.check0(v0[2], op0.getValue()); + func.check1(v1[2], op1.getValue()); + + op1.setValue(v1[3]); + func.check0(v0[3], op0.getValue()); + func.check1(v1[3], op1.getValue()); + } + + @Test + public void testUnbind() { + // unbind non-existing binding => no-op + func.unbind(op0, op1); + + // unbind properties of different beans + func.bind(op0, op1); + System.gc(); // making sure we did not not overdo weak references + func.check0(v0[1], op0.getValue()); + func.check1(v1[1], op1.getValue()); + + func.unbind(op0, op1); + System.gc(); + func.check0(v0[1], op0.getValue()); + func.check1(v1[1], op1.getValue()); + + op0.setValue(v0[2]); + func.check0(v0[2], op0.getValue()); + func.check1(v1[1], op1.getValue()); + + op1.setValue(v1[3]); + func.check0(v0[2], op0.getValue()); + func.check1(v1[3], op1.getValue()); + } + + @Test + public void testWeakReferencing() { + func.bind(op0, op1); + assertEquals(1, op0.getListenerCount()); + assertEquals(1, op1.getListenerCount()); + + op0 = null; + System.gc(); + op1.setValue(v1[2]); + assertEquals(0, op1.getListenerCount()); + + this.op0 = func.create0(); + func.bind(op0, op1); + assertEquals(1, op0.getListenerCount()); + assertEquals(1, op1.getListenerCount()); + + op1 = null; + System.gc(); + op0.setValue(v0[3]); + assertEquals(0, op0.getListenerCount()); + } + + @Test(expected=NullPointerException.class) + public void testBind_Null_X() { + func.bind(null, op1); + } + + @Test(expected=NullPointerException.class) + public void testBind_X_Null() { + func.bind(op0, null); + } + + @Test(expected=NullPointerException.class) + public void testUnbind_Null_X() { + func.unbind(null, op1); + } + + @Test(expected=NullPointerException.class) + public void testUnbind_X_Null() { + func.unbind(op0, null); + } + + @Test(expected=IllegalArgumentException.class) + public void testUnbind_X_Self() { + func.unbind(op0, op0); + } + + @Parameterized.Parameters + public static Collection parameters() { + final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US); + final Date[] dates = new Date[] {new Date(), new Date(0), new Date(Integer.MAX_VALUE), new Date(Long.MAX_VALUE)}; + final String[] strings = new String[] {format.format(dates[0]), format.format(dates[1]), format.format(dates[2]), format.format(dates[3])}; + + final StringConverter converter = new StringConverter() { + @Override + public String toString(Date object) { + return format.format(object); + } + + @Override + public Date fromString(String string) { + try { + return format.parse(string); + } catch (ParseException e) { + return null; + } + } + }; + + return Arrays.asList(new Object[][] { + // Format + { + new Functions() { + @Override + public PropertyMock create0() { + return new StringPropertyMock(); + } + @Override + public PropertyMock create1() { + return new ObjectPropertyMock(); + } + @Override + public void bind(PropertyMock op0, PropertyMock op1) { + Bindings.bindBidirectional(op0, op1, format); + } + @Override + public void unbind(Object op0, Object op1) { + Bindings.unbindBidirectional(op0, op1); + } + @Override + public Object createBindingDirectly(PropertyMock op0, PropertyMock op1) { + return BidirectionalBinding.bind(op0, op1, format); + } + + @Override + public void check0(String obj0, String obj1) { + assertEquals(obj0, obj1); + } + + @Override + public void check1(Date obj0, Date obj1) { + assertEquals(obj0.toString(), obj1.toString()); + } + }, + strings, + dates + }, + // Converter + { + new Functions() { + @Override + public PropertyMock create0() { + return new StringPropertyMock(); + } + @Override + public PropertyMock create1() { + return new ObjectPropertyMock(); + } + @Override + public void bind(PropertyMock op0, PropertyMock op1) { + Bindings.bindBidirectional(op0, op1, converter); + } + @Override + public void unbind(Object op0, Object op1) { + Bindings.unbindBidirectional(op0, op1); + } + @Override + public Object createBindingDirectly(PropertyMock op0, PropertyMock op1) { + return BidirectionalBinding.bind(op0, op1, converter); + } + + @Override + public void check0(String obj0, String obj1) { + assertEquals(obj0, obj1); + } + + @Override + public void check1(Date obj0, Date obj1) { + assertEquals(obj0.toString(), obj1.toString()); + } + }, + strings, + dates + }, + }); + } + + private interface PropertyMock extends Property { + int getListenerCount(); + } + + private static class ObjectPropertyMock extends SimpleObjectProperty implements PropertyMock { + + private int listenerCount = 0; + + @Override + public int getListenerCount() { + return listenerCount; + } + + @Override + public void addListener(ChangeListener listener) { + super.addListener(listener); + listenerCount++; + } + + @Override + public void removeListener(ChangeListener listener) { + super.removeListener(listener); + listenerCount--; + } + } + + private static class StringPropertyMock extends SimpleStringProperty implements PropertyMock { + + private int listenerCount = 0; + + @Override + public int getListenerCount() { + return listenerCount; + } + + @Override + public void addListener(ChangeListener listener) { + super.addListener(listener); + listenerCount++; + } + + @Override + public void removeListener(ChangeListener listener) { + super.removeListener(listener); + listenerCount--; + } + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/BidirectionalContentBindingListTest.java 2015-08-31 10:22:48.433217912 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,281 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import javafx.beans.binding.Bindings; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import org.junit.Before; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.*; - -public class BidirectionalContentBindingListTest { - - private ObservableList op1; - private ObservableList op2; - private ObservableList op3; - private List list0; - private List list1; - private List list2; - - @Before - public void setUp() { - list0 = new ArrayList(); - list1 = new ArrayList(Arrays.asList(-1)); - list2 = new ArrayList(Arrays.asList(2, 1)); - - op1 = FXCollections.observableArrayList(list1); - op2 = FXCollections.observableArrayList(list2); - op3 = FXCollections.observableArrayList(list0); - } - - @Test - public void testBind() { - final List list2_sorted = new ArrayList(Arrays.asList(1, 2)); - - Bindings.bindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(list2, op1); - assertEquals(list2, op2); - - op1.setAll(list1); - assertEquals(list1, op1); - assertEquals(list1, op2); - - op1.setAll(list0); - assertEquals(list0, op1); - assertEquals(list0, op2); - - op1.setAll(list2); - assertEquals(list2, op1); - assertEquals(list2, op2); - - FXCollections.sort(op1); - assertEquals(list2_sorted, op1); - assertEquals(list2_sorted, op2); - - op2.setAll(list1); - assertEquals(list1, op1); - assertEquals(list1, op2); - - op2.setAll(list0); - assertEquals(list0, op1); - assertEquals(list0, op2); - - op2.setAll(list2); - assertEquals(list2, op1); - assertEquals(list2, op2); - - FXCollections.sort(op2); - assertEquals(list2_sorted, op1); - assertEquals(list2_sorted, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_Null_X() { - Bindings.bindContentBidirectional(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_X_Null() { - Bindings.bindContentBidirectional(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testBind_X_Self() { - Bindings.bindContentBidirectional(op1, op1); - } - - @Test - public void testUnbind() { - // unbind non-existing binding => no-op - Bindings.unbindContentBidirectional(op1, op2); - - Bindings.bindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(list2, op1); - assertEquals(list2, op2); - - Bindings.unbindContentBidirectional(op1, op2); - System.gc(); - assertEquals(list2, op1); - assertEquals(list2, op2); - - op1.setAll(list1); - assertEquals(list1, op1); - assertEquals(list2, op2); - - op2.setAll(list0); - assertEquals(list1, op1); - assertEquals(list0, op2); - - // unbind in flipped order - Bindings.bindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(list0, op1); - assertEquals(list0, op2); - - Bindings.unbindContentBidirectional(op2, op1); - System.gc(); - assertEquals(list0, op1); - assertEquals(list0, op2); - - op1.setAll(list1); - assertEquals(list1, op1); - assertEquals(list0, op2); - - op2.setAll(list2); - assertEquals(list1, op1); - assertEquals(list2, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_Null_X() { - Bindings.unbindContentBidirectional(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_X_Null() { - Bindings.unbindContentBidirectional(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testUnbind_X_Self() { - Bindings.unbindContentBidirectional(op1, op1); - } - - @Test - public void testChaining() { - Bindings.bindContentBidirectional(op1, op2); - Bindings.bindContentBidirectional(op2, op3); - System.gc(); // making sure we did not not overdo weak references - assertEquals(list0, op1); - assertEquals(list0, op2); - assertEquals(list0, op3); - - op1.setAll(list1); - assertEquals(list1, op1); - assertEquals(list1, op2); - assertEquals(list1, op3); - - op2.setAll(list2); - assertEquals(list2, op1); - assertEquals(list2, op2); - assertEquals(list2, op3); - - op3.setAll(list0); - assertEquals(list0, op1); - assertEquals(list0, op2); - assertEquals(list0, op3); - - // now unbind - Bindings.unbindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(list0, op1); - assertEquals(list0, op2); - assertEquals(list0, op3); - - op1.setAll(list1); - assertEquals(list1, op1); - assertEquals(list0, op2); - assertEquals(list0, op3); - - op2.setAll(list2); - assertEquals(list1, op1); - assertEquals(list2, op2); - assertEquals(list2, op3); - - op3.setAll(list0); - assertEquals(list1, op1); - assertEquals(list0, op2); - assertEquals(list0, op3); - } - - @Test - public void testHashCode() { - final int hc1 = BidirectionalContentBinding.bind(op1, op2).hashCode(); - BidirectionalContentBinding.unbind(op1, op2); - final int hc2 = BidirectionalContentBinding.bind(op2, op1).hashCode(); - assertEquals(hc1, hc2); - } - - @Test - public void testEquals() { - final Object golden = BidirectionalContentBinding.bind(op1, op2); - BidirectionalContentBinding.unbind(op1, op2); - - assertTrue(golden.equals(golden)); - assertFalse(golden.equals(null)); - assertFalse(golden.equals(op1)); - assertTrue(golden.equals(BidirectionalContentBinding.bind(op1, op2))); - BidirectionalContentBinding.unbind(op1, op2); - assertTrue(golden.equals(BidirectionalContentBinding.bind(op2, op1))); - BidirectionalContentBinding.unbind(op1, op2); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op1, op3))); - BidirectionalContentBinding.unbind(op1, op3); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op1))); - BidirectionalContentBinding.unbind(op1, op3); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op2))); - BidirectionalContentBinding.unbind(op2, op3); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op2, op3))); - BidirectionalContentBinding.unbind(op2, op3); - } - - @Test - public void testEqualsWithGCedProperty() { - final Object binding1 = BidirectionalContentBinding.bind(op1, op2); - BidirectionalContentBinding.unbind(op1, op2); - final Object binding2 = BidirectionalContentBinding.bind(op1, op2); - BidirectionalContentBinding.unbind(op1, op2); - final Object binding3 = BidirectionalContentBinding.bind(op2, op1); - BidirectionalContentBinding.unbind(op1, op2); - final Object binding4 = BidirectionalContentBinding.bind(op2, op1); - BidirectionalContentBinding.unbind(op1, op2); - op1 = null; - System.gc(); - - assertTrue(binding1.equals(binding1)); - assertFalse(binding1.equals(binding2)); - assertFalse(binding1.equals(binding3)); - - assertTrue(binding3.equals(binding3)); - assertFalse(binding3.equals(binding1)); - assertFalse(binding3.equals(binding4)); - } - - @Test - public void testChangeValue() { - Bindings.bindContentBidirectional(op1, op2); - assertEquals(2, op2.get(0).intValue()); - op1.set(0, 1); - assertEquals(1, op2.get(0).intValue()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/BidirectionalContentBindingListTest.java 2015-08-31 10:22:48.301217914 -0400 @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.BidirectionalContentBinding; +import javafx.beans.binding.Bindings; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.*; + +public class BidirectionalContentBindingListTest { + + private ObservableList op1; + private ObservableList op2; + private ObservableList op3; + private List list0; + private List list1; + private List list2; + + @Before + public void setUp() { + list0 = new ArrayList(); + list1 = new ArrayList(Arrays.asList(-1)); + list2 = new ArrayList(Arrays.asList(2, 1)); + + op1 = FXCollections.observableArrayList(list1); + op2 = FXCollections.observableArrayList(list2); + op3 = FXCollections.observableArrayList(list0); + } + + @Test + public void testBind() { + final List list2_sorted = new ArrayList(Arrays.asList(1, 2)); + + Bindings.bindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(list2, op1); + assertEquals(list2, op2); + + op1.setAll(list1); + assertEquals(list1, op1); + assertEquals(list1, op2); + + op1.setAll(list0); + assertEquals(list0, op1); + assertEquals(list0, op2); + + op1.setAll(list2); + assertEquals(list2, op1); + assertEquals(list2, op2); + + FXCollections.sort(op1); + assertEquals(list2_sorted, op1); + assertEquals(list2_sorted, op2); + + op2.setAll(list1); + assertEquals(list1, op1); + assertEquals(list1, op2); + + op2.setAll(list0); + assertEquals(list0, op1); + assertEquals(list0, op2); + + op2.setAll(list2); + assertEquals(list2, op1); + assertEquals(list2, op2); + + FXCollections.sort(op2); + assertEquals(list2_sorted, op1); + assertEquals(list2_sorted, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_Null_X() { + Bindings.bindContentBidirectional(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_X_Null() { + Bindings.bindContentBidirectional(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testBind_X_Self() { + Bindings.bindContentBidirectional(op1, op1); + } + + @Test + public void testUnbind() { + // unbind non-existing binding => no-op + Bindings.unbindContentBidirectional(op1, op2); + + Bindings.bindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(list2, op1); + assertEquals(list2, op2); + + Bindings.unbindContentBidirectional(op1, op2); + System.gc(); + assertEquals(list2, op1); + assertEquals(list2, op2); + + op1.setAll(list1); + assertEquals(list1, op1); + assertEquals(list2, op2); + + op2.setAll(list0); + assertEquals(list1, op1); + assertEquals(list0, op2); + + // unbind in flipped order + Bindings.bindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(list0, op1); + assertEquals(list0, op2); + + Bindings.unbindContentBidirectional(op2, op1); + System.gc(); + assertEquals(list0, op1); + assertEquals(list0, op2); + + op1.setAll(list1); + assertEquals(list1, op1); + assertEquals(list0, op2); + + op2.setAll(list2); + assertEquals(list1, op1); + assertEquals(list2, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_Null_X() { + Bindings.unbindContentBidirectional(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_X_Null() { + Bindings.unbindContentBidirectional(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testUnbind_X_Self() { + Bindings.unbindContentBidirectional(op1, op1); + } + + @Test + public void testChaining() { + Bindings.bindContentBidirectional(op1, op2); + Bindings.bindContentBidirectional(op2, op3); + System.gc(); // making sure we did not not overdo weak references + assertEquals(list0, op1); + assertEquals(list0, op2); + assertEquals(list0, op3); + + op1.setAll(list1); + assertEquals(list1, op1); + assertEquals(list1, op2); + assertEquals(list1, op3); + + op2.setAll(list2); + assertEquals(list2, op1); + assertEquals(list2, op2); + assertEquals(list2, op3); + + op3.setAll(list0); + assertEquals(list0, op1); + assertEquals(list0, op2); + assertEquals(list0, op3); + + // now unbind + Bindings.unbindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(list0, op1); + assertEquals(list0, op2); + assertEquals(list0, op3); + + op1.setAll(list1); + assertEquals(list1, op1); + assertEquals(list0, op2); + assertEquals(list0, op3); + + op2.setAll(list2); + assertEquals(list1, op1); + assertEquals(list2, op2); + assertEquals(list2, op3); + + op3.setAll(list0); + assertEquals(list1, op1); + assertEquals(list0, op2); + assertEquals(list0, op3); + } + + @Test + public void testHashCode() { + final int hc1 = BidirectionalContentBinding.bind(op1, op2).hashCode(); + BidirectionalContentBinding.unbind(op1, op2); + final int hc2 = BidirectionalContentBinding.bind(op2, op1).hashCode(); + assertEquals(hc1, hc2); + } + + @Test + public void testEquals() { + final Object golden = BidirectionalContentBinding.bind(op1, op2); + BidirectionalContentBinding.unbind(op1, op2); + + assertTrue(golden.equals(golden)); + assertFalse(golden.equals(null)); + assertFalse(golden.equals(op1)); + assertTrue(golden.equals(BidirectionalContentBinding.bind(op1, op2))); + BidirectionalContentBinding.unbind(op1, op2); + assertTrue(golden.equals(BidirectionalContentBinding.bind(op2, op1))); + BidirectionalContentBinding.unbind(op1, op2); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op1, op3))); + BidirectionalContentBinding.unbind(op1, op3); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op1))); + BidirectionalContentBinding.unbind(op1, op3); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op2))); + BidirectionalContentBinding.unbind(op2, op3); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op2, op3))); + BidirectionalContentBinding.unbind(op2, op3); + } + + @Test + public void testEqualsWithGCedProperty() { + final Object binding1 = BidirectionalContentBinding.bind(op1, op2); + BidirectionalContentBinding.unbind(op1, op2); + final Object binding2 = BidirectionalContentBinding.bind(op1, op2); + BidirectionalContentBinding.unbind(op1, op2); + final Object binding3 = BidirectionalContentBinding.bind(op2, op1); + BidirectionalContentBinding.unbind(op1, op2); + final Object binding4 = BidirectionalContentBinding.bind(op2, op1); + BidirectionalContentBinding.unbind(op1, op2); + op1 = null; + System.gc(); + + assertTrue(binding1.equals(binding1)); + assertFalse(binding1.equals(binding2)); + assertFalse(binding1.equals(binding3)); + + assertTrue(binding3.equals(binding3)); + assertFalse(binding3.equals(binding1)); + assertFalse(binding3.equals(binding4)); + } + + @Test + public void testChangeValue() { + Bindings.bindContentBidirectional(op1, op2); + assertEquals(2, op2.get(0).intValue()); + op1.set(0, 1); + assertEquals(1, op2.get(0).intValue()); + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/BidirectionalContentBindingMapTest.java 2015-08-31 10:22:49.145217904 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,293 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import javafx.beans.binding.Bindings; -import javafx.collections.FXCollections; -import javafx.collections.ObservableMap; -import org.junit.Before; -import org.junit.Test; - -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.*; - -public class BidirectionalContentBindingMapTest { - - private static final String key1 = "Key1"; - private static final String key2_1 = "Key2_1"; - private static final String key2_2 = "Key2_2"; - - private ObservableMap op1; - private ObservableMap op2; - private ObservableMap op3; - private Map map0; - private Map map1; - private Map map2; - - @Before - public void setUp() { - map0 = new HashMap(); - map1 = new HashMap(); - map1.put(key1, -1); - map2 = new HashMap(); - map2.put(key2_1, 2); - map2.put(key2_2, 1); - - op1 = FXCollections.observableMap(map1); - op2 = FXCollections.observableMap(map2); - op3 = FXCollections.observableMap(map0); - } - - @Test - public void testBind() { - Bindings.bindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(map2, op1); - assertEquals(map2, op2); - - op1.clear(); - op1.putAll(map1); - assertEquals(map1, op1); - assertEquals(map1, op2); - - op1.clear(); - op1.putAll(map0); - assertEquals(map0, op1); - assertEquals(map0, op2); - - op1.clear(); - op1.putAll(map2); - assertEquals(map2, op1); - assertEquals(map2, op2); - - op2.clear(); - op2.putAll(map1); - assertEquals(map1, op1); - assertEquals(map1, op2); - - op2.clear(); - op2.putAll(map0); - assertEquals(map0, op1); - assertEquals(map0, op2); - - op2.clear(); - op2.putAll(map2); - assertEquals(map2, op1); - assertEquals(map2, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_Null_X() { - Bindings.bindContentBidirectional(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_X_Null() { - Bindings.bindContentBidirectional(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testBind_X_Self() { - Bindings.bindContentBidirectional(op1, op1); - } - - @Test - public void testUnbind() { - // unbind non-existing binding => no-op - Bindings.unbindContentBidirectional(op1, op2); - - Bindings.bindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(map2, op1); - assertEquals(map2, op2); - - Bindings.unbindContentBidirectional(op1, op2); - System.gc(); - assertEquals(map2, op1); - assertEquals(map2, op2); - - op1.clear(); - op1.putAll(map1); - assertEquals(map1, op1); - assertEquals(map2, op2); - - op2.clear(); - op2.putAll(map0); - assertEquals(map1, op1); - assertEquals(map0, op2); - - // unbind in flipped order - Bindings.bindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(map0, op1); - assertEquals(map0, op2); - - Bindings.unbindContentBidirectional(op2, op1); - System.gc(); - assertEquals(map0, op1); - assertEquals(map0, op2); - - op1.clear(); - op1.putAll(map1); - assertEquals(map1, op1); - assertEquals(map0, op2); - - op2.clear(); - op2.putAll(map2); - assertEquals(map1, op1); - assertEquals(map2, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_Null_X() { - Bindings.unbindContentBidirectional(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_X_Null() { - Bindings.unbindContentBidirectional(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testUnbind_X_Self() { - Bindings.unbindContentBidirectional(op1, op1); - } - - @Test - public void testChaining() { - Bindings.bindContentBidirectional(op1, op2); - Bindings.bindContentBidirectional(op2, op3); - System.gc(); // making sure we did not not overdo weak references - assertEquals(map0, op1); - assertEquals(map0, op2); - assertEquals(map0, op3); - - op1.clear(); - op1.putAll(map1); - assertEquals(map1, op1); - assertEquals(map1, op2); - assertEquals(map1, op3); - - op2.clear(); - op2.putAll(map2); - assertEquals(map2, op1); - assertEquals(map2, op2); - assertEquals(map2, op3); - - op3.clear(); - op3.putAll(map0); - assertEquals(map0, op1); - assertEquals(map0, op2); - assertEquals(map0, op3); - - // now unbind - Bindings.unbindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(map0, op1); - assertEquals(map0, op2); - assertEquals(map0, op3); - - op1.clear(); - op1.putAll(map1); - assertEquals(map1, op1); - assertEquals(map0, op2); - assertEquals(map0, op3); - - op2.clear(); - op2.putAll(map2); - assertEquals(map1, op1); - assertEquals(map2, op2); - assertEquals(map2, op3); - - op3.clear(); - op3.putAll(map0); - assertEquals(map1, op1); - assertEquals(map0, op2); - assertEquals(map0, op3); - } - - @Test - public void testHashCode() { - final int hc1 = BidirectionalContentBinding.bind(op1, op2).hashCode(); - BidirectionalContentBinding.unbind(op1, op2); - final int hc2 = BidirectionalContentBinding.bind(op2, op1).hashCode(); - assertEquals(hc1, hc2); - } - - @Test - public void testEquals() { - final Object golden = BidirectionalContentBinding.bind(op1, op2); - BidirectionalContentBinding.unbind(op1, op2); - - assertTrue(golden.equals(golden)); - assertFalse(golden.equals(null)); - assertFalse(golden.equals(op1)); - assertTrue(golden.equals(BidirectionalContentBinding.bind(op1, op2))); - BidirectionalContentBinding.unbind(op1, op2); - assertTrue(golden.equals(BidirectionalContentBinding.bind(op2, op1))); - BidirectionalContentBinding.unbind(op1, op2); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op1, op3))); - BidirectionalContentBinding.unbind(op1, op3); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op1))); - BidirectionalContentBinding.unbind(op1, op3); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op2))); - BidirectionalContentBinding.unbind(op2, op3); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op2, op3))); - BidirectionalContentBinding.unbind(op2, op3); - } - - @Test - public void testEqualsWithGCedProperty() { - final Object binding1 = BidirectionalContentBinding.bind(op1, op2); - BidirectionalContentBinding.unbind(op1, op2); - final Object binding2 = BidirectionalContentBinding.bind(op1, op2); - BidirectionalContentBinding.unbind(op1, op2); - final Object binding3 = BidirectionalContentBinding.bind(op2, op1); - BidirectionalContentBinding.unbind(op1, op2); - final Object binding4 = BidirectionalContentBinding.bind(op2, op1); - BidirectionalContentBinding.unbind(op1, op2); - op1 = null; - System.gc(); - - assertTrue(binding1.equals(binding1)); - assertFalse(binding1.equals(binding2)); - assertFalse(binding1.equals(binding3)); - - assertTrue(binding3.equals(binding3)); - assertFalse(binding3.equals(binding1)); - assertFalse(binding3.equals(binding4)); - } - - @Test - public void testChangeValue() { - Bindings.bindContentBidirectional(op1, op2); - assertEquals(2, op2.get(key2_1).intValue()); - op1.put(key2_1, 1); - assertEquals(1, op2.get(key2_1).intValue()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/BidirectionalContentBindingMapTest.java 2015-08-31 10:22:48.937217907 -0400 @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.BidirectionalContentBinding; +import javafx.beans.binding.Bindings; +import javafx.collections.FXCollections; +import javafx.collections.ObservableMap; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +public class BidirectionalContentBindingMapTest { + + private static final String key1 = "Key1"; + private static final String key2_1 = "Key2_1"; + private static final String key2_2 = "Key2_2"; + + private ObservableMap op1; + private ObservableMap op2; + private ObservableMap op3; + private Map map0; + private Map map1; + private Map map2; + + @Before + public void setUp() { + map0 = new HashMap(); + map1 = new HashMap(); + map1.put(key1, -1); + map2 = new HashMap(); + map2.put(key2_1, 2); + map2.put(key2_2, 1); + + op1 = FXCollections.observableMap(map1); + op2 = FXCollections.observableMap(map2); + op3 = FXCollections.observableMap(map0); + } + + @Test + public void testBind() { + Bindings.bindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(map2, op1); + assertEquals(map2, op2); + + op1.clear(); + op1.putAll(map1); + assertEquals(map1, op1); + assertEquals(map1, op2); + + op1.clear(); + op1.putAll(map0); + assertEquals(map0, op1); + assertEquals(map0, op2); + + op1.clear(); + op1.putAll(map2); + assertEquals(map2, op1); + assertEquals(map2, op2); + + op2.clear(); + op2.putAll(map1); + assertEquals(map1, op1); + assertEquals(map1, op2); + + op2.clear(); + op2.putAll(map0); + assertEquals(map0, op1); + assertEquals(map0, op2); + + op2.clear(); + op2.putAll(map2); + assertEquals(map2, op1); + assertEquals(map2, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_Null_X() { + Bindings.bindContentBidirectional(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_X_Null() { + Bindings.bindContentBidirectional(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testBind_X_Self() { + Bindings.bindContentBidirectional(op1, op1); + } + + @Test + public void testUnbind() { + // unbind non-existing binding => no-op + Bindings.unbindContentBidirectional(op1, op2); + + Bindings.bindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(map2, op1); + assertEquals(map2, op2); + + Bindings.unbindContentBidirectional(op1, op2); + System.gc(); + assertEquals(map2, op1); + assertEquals(map2, op2); + + op1.clear(); + op1.putAll(map1); + assertEquals(map1, op1); + assertEquals(map2, op2); + + op2.clear(); + op2.putAll(map0); + assertEquals(map1, op1); + assertEquals(map0, op2); + + // unbind in flipped order + Bindings.bindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(map0, op1); + assertEquals(map0, op2); + + Bindings.unbindContentBidirectional(op2, op1); + System.gc(); + assertEquals(map0, op1); + assertEquals(map0, op2); + + op1.clear(); + op1.putAll(map1); + assertEquals(map1, op1); + assertEquals(map0, op2); + + op2.clear(); + op2.putAll(map2); + assertEquals(map1, op1); + assertEquals(map2, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_Null_X() { + Bindings.unbindContentBidirectional(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_X_Null() { + Bindings.unbindContentBidirectional(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testUnbind_X_Self() { + Bindings.unbindContentBidirectional(op1, op1); + } + + @Test + public void testChaining() { + Bindings.bindContentBidirectional(op1, op2); + Bindings.bindContentBidirectional(op2, op3); + System.gc(); // making sure we did not not overdo weak references + assertEquals(map0, op1); + assertEquals(map0, op2); + assertEquals(map0, op3); + + op1.clear(); + op1.putAll(map1); + assertEquals(map1, op1); + assertEquals(map1, op2); + assertEquals(map1, op3); + + op2.clear(); + op2.putAll(map2); + assertEquals(map2, op1); + assertEquals(map2, op2); + assertEquals(map2, op3); + + op3.clear(); + op3.putAll(map0); + assertEquals(map0, op1); + assertEquals(map0, op2); + assertEquals(map0, op3); + + // now unbind + Bindings.unbindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(map0, op1); + assertEquals(map0, op2); + assertEquals(map0, op3); + + op1.clear(); + op1.putAll(map1); + assertEquals(map1, op1); + assertEquals(map0, op2); + assertEquals(map0, op3); + + op2.clear(); + op2.putAll(map2); + assertEquals(map1, op1); + assertEquals(map2, op2); + assertEquals(map2, op3); + + op3.clear(); + op3.putAll(map0); + assertEquals(map1, op1); + assertEquals(map0, op2); + assertEquals(map0, op3); + } + + @Test + public void testHashCode() { + final int hc1 = BidirectionalContentBinding.bind(op1, op2).hashCode(); + BidirectionalContentBinding.unbind(op1, op2); + final int hc2 = BidirectionalContentBinding.bind(op2, op1).hashCode(); + assertEquals(hc1, hc2); + } + + @Test + public void testEquals() { + final Object golden = BidirectionalContentBinding.bind(op1, op2); + BidirectionalContentBinding.unbind(op1, op2); + + assertTrue(golden.equals(golden)); + assertFalse(golden.equals(null)); + assertFalse(golden.equals(op1)); + assertTrue(golden.equals(BidirectionalContentBinding.bind(op1, op2))); + BidirectionalContentBinding.unbind(op1, op2); + assertTrue(golden.equals(BidirectionalContentBinding.bind(op2, op1))); + BidirectionalContentBinding.unbind(op1, op2); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op1, op3))); + BidirectionalContentBinding.unbind(op1, op3); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op1))); + BidirectionalContentBinding.unbind(op1, op3); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op2))); + BidirectionalContentBinding.unbind(op2, op3); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op2, op3))); + BidirectionalContentBinding.unbind(op2, op3); + } + + @Test + public void testEqualsWithGCedProperty() { + final Object binding1 = BidirectionalContentBinding.bind(op1, op2); + BidirectionalContentBinding.unbind(op1, op2); + final Object binding2 = BidirectionalContentBinding.bind(op1, op2); + BidirectionalContentBinding.unbind(op1, op2); + final Object binding3 = BidirectionalContentBinding.bind(op2, op1); + BidirectionalContentBinding.unbind(op1, op2); + final Object binding4 = BidirectionalContentBinding.bind(op2, op1); + BidirectionalContentBinding.unbind(op1, op2); + op1 = null; + System.gc(); + + assertTrue(binding1.equals(binding1)); + assertFalse(binding1.equals(binding2)); + assertFalse(binding1.equals(binding3)); + + assertTrue(binding3.equals(binding3)); + assertFalse(binding3.equals(binding1)); + assertFalse(binding3.equals(binding4)); + } + + @Test + public void testChangeValue() { + Bindings.bindContentBidirectional(op1, op2); + assertEquals(2, op2.get(key2_1).intValue()); + op1.put(key2_1, 1); + assertEquals(1, op2.get(key2_1).intValue()); + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/BidirectionalContentBindingSetTest.java 2015-08-31 10:22:49.773217897 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,281 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import javafx.beans.binding.Bindings; -import javafx.collections.FXCollections; -import javafx.collections.ObservableSet; -import org.junit.Before; -import org.junit.Test; - -import java.util.HashSet; -import java.util.Set; - -import static org.junit.Assert.*; - -public class BidirectionalContentBindingSetTest { - - private ObservableSet op1; - private ObservableSet op2; - private ObservableSet op3; - private Set set0; - private Set set1; - private Set set2; - - @Before - public void setUp() { - set0 = new HashSet(); - set1 = new HashSet(); - set1.add(-1); - set2 = new HashSet(); - set2.add(2); - set2.add(1); - - op1 = FXCollections.observableSet(set1); - op2 = FXCollections.observableSet(set2); - op3 = FXCollections.observableSet(set0); - } - - @Test - public void testBind() { - Bindings.bindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(set2, op1); - assertEquals(set2, op2); - - op1.clear(); - op1.addAll(set1); - assertEquals(set1, op1); - assertEquals(set1, op2); - - op1.clear(); - op1.addAll(set0); - assertEquals(set0, op1); - assertEquals(set0, op2); - - op1.clear(); - op1.addAll(set2); - assertEquals(set2, op1); - assertEquals(set2, op2); - - op2.clear(); - op2.addAll(set1); - assertEquals(set1, op1); - assertEquals(set1, op2); - - op2.clear(); - op2.addAll(set0); - assertEquals(set0, op1); - assertEquals(set0, op2); - - op2.clear(); - op2.addAll(set2); - assertEquals(set2, op1); - assertEquals(set2, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_Null_X() { - Bindings.bindContentBidirectional(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_X_Null() { - Bindings.bindContentBidirectional(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testBind_X_Self() { - Bindings.bindContentBidirectional(op1, op1); - } - - @Test - public void testUnbind() { - // unbind non-existing binding => no-op - Bindings.unbindContentBidirectional(op1, op2); - - Bindings.bindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(set2, op1); - assertEquals(set2, op2); - - Bindings.unbindContentBidirectional(op1, op2); - System.gc(); - assertEquals(set2, op1); - assertEquals(set2, op2); - - op1.clear(); - op1.addAll(set1); - assertEquals(set1, op1); - assertEquals(set2, op2); - - op2.clear(); - op2.addAll(set0); - assertEquals(set1, op1); - assertEquals(set0, op2); - - // unbind in flipped order - Bindings.bindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(set0, op1); - assertEquals(set0, op2); - - Bindings.unbindContentBidirectional(op2, op1); - System.gc(); - assertEquals(set0, op1); - assertEquals(set0, op2); - - op1.clear(); - op1.addAll(set1); - assertEquals(set1, op1); - assertEquals(set0, op2); - - op2.clear(); - op2.addAll(set2); - assertEquals(set1, op1); - assertEquals(set2, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_Null_X() { - Bindings.unbindContentBidirectional(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_X_Null() { - Bindings.unbindContentBidirectional(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testUnbind_X_Self() { - Bindings.unbindContentBidirectional(op1, op1); - } - - @Test - public void testChaining() { - Bindings.bindContentBidirectional(op1, op2); - Bindings.bindContentBidirectional(op2, op3); - System.gc(); // making sure we did not not overdo weak references - assertEquals(set0, op1); - assertEquals(set0, op2); - assertEquals(set0, op3); - - op1.clear(); - op1.addAll(set1); - assertEquals(set1, op1); - assertEquals(set1, op2); - assertEquals(set1, op3); - - op2.clear(); - op2.addAll(set2); - assertEquals(set2, op1); - assertEquals(set2, op2); - assertEquals(set2, op3); - - op3.clear(); - op3.addAll(set0); - assertEquals(set0, op1); - assertEquals(set0, op2); - assertEquals(set0, op3); - - // now unbind - Bindings.unbindContentBidirectional(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(set0, op1); - assertEquals(set0, op2); - assertEquals(set0, op3); - - op1.clear(); - op1.addAll(set1); - assertEquals(set1, op1); - assertEquals(set0, op2); - assertEquals(set0, op3); - - op2.clear(); - op2.addAll(set2); - assertEquals(set1, op1); - assertEquals(set2, op2); - assertEquals(set2, op3); - - op3.clear(); - op3.addAll(set0); - assertEquals(set1, op1); - assertEquals(set0, op2); - assertEquals(set0, op3); - } - - @Test - public void testHashCode() { - final int hc1 = BidirectionalContentBinding.bind(op1, op2).hashCode(); - BidirectionalContentBinding.unbind(op1, op2); - final int hc2 = BidirectionalContentBinding.bind(op2, op1).hashCode(); - assertEquals(hc1, hc2); - } - - @Test - public void testEquals() { - final Object golden = BidirectionalContentBinding.bind(op1, op2); - BidirectionalContentBinding.unbind(op1, op2); - - assertTrue(golden.equals(golden)); - assertFalse(golden.equals(null)); - assertFalse(golden.equals(op1)); - assertTrue(golden.equals(BidirectionalContentBinding.bind(op1, op2))); - BidirectionalContentBinding.unbind(op1, op2); - assertTrue(golden.equals(BidirectionalContentBinding.bind(op2, op1))); - BidirectionalContentBinding.unbind(op1, op2); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op1, op3))); - BidirectionalContentBinding.unbind(op1, op3); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op1))); - BidirectionalContentBinding.unbind(op1, op3); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op2))); - BidirectionalContentBinding.unbind(op2, op3); - assertFalse(golden.equals(BidirectionalContentBinding.bind(op2, op3))); - BidirectionalContentBinding.unbind(op2, op3); - } - - @Test - public void testEqualsWithGCedProperty() { - final Object binding1 = BidirectionalContentBinding.bind(op1, op2); - BidirectionalContentBinding.unbind(op1, op2); - final Object binding2 = BidirectionalContentBinding.bind(op1, op2); - BidirectionalContentBinding.unbind(op1, op2); - final Object binding3 = BidirectionalContentBinding.bind(op2, op1); - BidirectionalContentBinding.unbind(op1, op2); - final Object binding4 = BidirectionalContentBinding.bind(op2, op1); - BidirectionalContentBinding.unbind(op1, op2); - op1 = null; - System.gc(); - - assertTrue(binding1.equals(binding1)); - assertFalse(binding1.equals(binding2)); - assertFalse(binding1.equals(binding3)); - - assertTrue(binding3.equals(binding3)); - assertFalse(binding3.equals(binding1)); - assertFalse(binding3.equals(binding4)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/BidirectionalContentBindingSetTest.java 2015-08-31 10:22:49.637217899 -0400 @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.BidirectionalContentBinding; +import javafx.beans.binding.Bindings; +import javafx.collections.FXCollections; +import javafx.collections.ObservableSet; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.*; + +public class BidirectionalContentBindingSetTest { + + private ObservableSet op1; + private ObservableSet op2; + private ObservableSet op3; + private Set set0; + private Set set1; + private Set set2; + + @Before + public void setUp() { + set0 = new HashSet(); + set1 = new HashSet(); + set1.add(-1); + set2 = new HashSet(); + set2.add(2); + set2.add(1); + + op1 = FXCollections.observableSet(set1); + op2 = FXCollections.observableSet(set2); + op3 = FXCollections.observableSet(set0); + } + + @Test + public void testBind() { + Bindings.bindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(set2, op1); + assertEquals(set2, op2); + + op1.clear(); + op1.addAll(set1); + assertEquals(set1, op1); + assertEquals(set1, op2); + + op1.clear(); + op1.addAll(set0); + assertEquals(set0, op1); + assertEquals(set0, op2); + + op1.clear(); + op1.addAll(set2); + assertEquals(set2, op1); + assertEquals(set2, op2); + + op2.clear(); + op2.addAll(set1); + assertEquals(set1, op1); + assertEquals(set1, op2); + + op2.clear(); + op2.addAll(set0); + assertEquals(set0, op1); + assertEquals(set0, op2); + + op2.clear(); + op2.addAll(set2); + assertEquals(set2, op1); + assertEquals(set2, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_Null_X() { + Bindings.bindContentBidirectional(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_X_Null() { + Bindings.bindContentBidirectional(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testBind_X_Self() { + Bindings.bindContentBidirectional(op1, op1); + } + + @Test + public void testUnbind() { + // unbind non-existing binding => no-op + Bindings.unbindContentBidirectional(op1, op2); + + Bindings.bindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(set2, op1); + assertEquals(set2, op2); + + Bindings.unbindContentBidirectional(op1, op2); + System.gc(); + assertEquals(set2, op1); + assertEquals(set2, op2); + + op1.clear(); + op1.addAll(set1); + assertEquals(set1, op1); + assertEquals(set2, op2); + + op2.clear(); + op2.addAll(set0); + assertEquals(set1, op1); + assertEquals(set0, op2); + + // unbind in flipped order + Bindings.bindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(set0, op1); + assertEquals(set0, op2); + + Bindings.unbindContentBidirectional(op2, op1); + System.gc(); + assertEquals(set0, op1); + assertEquals(set0, op2); + + op1.clear(); + op1.addAll(set1); + assertEquals(set1, op1); + assertEquals(set0, op2); + + op2.clear(); + op2.addAll(set2); + assertEquals(set1, op1); + assertEquals(set2, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_Null_X() { + Bindings.unbindContentBidirectional(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_X_Null() { + Bindings.unbindContentBidirectional(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testUnbind_X_Self() { + Bindings.unbindContentBidirectional(op1, op1); + } + + @Test + public void testChaining() { + Bindings.bindContentBidirectional(op1, op2); + Bindings.bindContentBidirectional(op2, op3); + System.gc(); // making sure we did not not overdo weak references + assertEquals(set0, op1); + assertEquals(set0, op2); + assertEquals(set0, op3); + + op1.clear(); + op1.addAll(set1); + assertEquals(set1, op1); + assertEquals(set1, op2); + assertEquals(set1, op3); + + op2.clear(); + op2.addAll(set2); + assertEquals(set2, op1); + assertEquals(set2, op2); + assertEquals(set2, op3); + + op3.clear(); + op3.addAll(set0); + assertEquals(set0, op1); + assertEquals(set0, op2); + assertEquals(set0, op3); + + // now unbind + Bindings.unbindContentBidirectional(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(set0, op1); + assertEquals(set0, op2); + assertEquals(set0, op3); + + op1.clear(); + op1.addAll(set1); + assertEquals(set1, op1); + assertEquals(set0, op2); + assertEquals(set0, op3); + + op2.clear(); + op2.addAll(set2); + assertEquals(set1, op1); + assertEquals(set2, op2); + assertEquals(set2, op3); + + op3.clear(); + op3.addAll(set0); + assertEquals(set1, op1); + assertEquals(set0, op2); + assertEquals(set0, op3); + } + + @Test + public void testHashCode() { + final int hc1 = BidirectionalContentBinding.bind(op1, op2).hashCode(); + BidirectionalContentBinding.unbind(op1, op2); + final int hc2 = BidirectionalContentBinding.bind(op2, op1).hashCode(); + assertEquals(hc1, hc2); + } + + @Test + public void testEquals() { + final Object golden = BidirectionalContentBinding.bind(op1, op2); + BidirectionalContentBinding.unbind(op1, op2); + + assertTrue(golden.equals(golden)); + assertFalse(golden.equals(null)); + assertFalse(golden.equals(op1)); + assertTrue(golden.equals(BidirectionalContentBinding.bind(op1, op2))); + BidirectionalContentBinding.unbind(op1, op2); + assertTrue(golden.equals(BidirectionalContentBinding.bind(op2, op1))); + BidirectionalContentBinding.unbind(op1, op2); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op1, op3))); + BidirectionalContentBinding.unbind(op1, op3); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op1))); + BidirectionalContentBinding.unbind(op1, op3); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op3, op2))); + BidirectionalContentBinding.unbind(op2, op3); + assertFalse(golden.equals(BidirectionalContentBinding.bind(op2, op3))); + BidirectionalContentBinding.unbind(op2, op3); + } + + @Test + public void testEqualsWithGCedProperty() { + final Object binding1 = BidirectionalContentBinding.bind(op1, op2); + BidirectionalContentBinding.unbind(op1, op2); + final Object binding2 = BidirectionalContentBinding.bind(op1, op2); + BidirectionalContentBinding.unbind(op1, op2); + final Object binding3 = BidirectionalContentBinding.bind(op2, op1); + BidirectionalContentBinding.unbind(op1, op2); + final Object binding4 = BidirectionalContentBinding.bind(op2, op1); + BidirectionalContentBinding.unbind(op1, op2); + op1 = null; + System.gc(); + + assertTrue(binding1.equals(binding1)); + assertFalse(binding1.equals(binding2)); + assertFalse(binding1.equals(binding3)); + + assertTrue(binding3.equals(binding3)); + assertFalse(binding3.equals(binding1)); + assertFalse(binding3.equals(binding4)); + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/ContentBindingListTest.java 2015-08-31 10:22:50.401217890 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,222 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import javafx.beans.binding.Bindings; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import org.junit.Before; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.*; - -public class ContentBindingListTest { - - private List op1; - private ObservableList op2; - private ObservableList op3; - private List list0; - private List list1; - private List list2; - - @Before - public void setUp() { - list0 = new ArrayList(); - list1 = new ArrayList(Arrays.asList(0)); - list2 = new ArrayList(Arrays.asList(2, 1)); - - op1 = new ArrayList(list1); - op2 = FXCollections.observableArrayList(list2); - op3 = FXCollections.observableArrayList(list0); - } - - @Test - public void testBind() { - List list2_sorted = new ArrayList(Arrays.asList(1, 2)); - - Bindings.bindContent(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(list2, op1); - assertEquals(list2, op2); - - op2.setAll(list1); - assertEquals(list1, op1); - assertEquals(list1, op2); - - op2.setAll(list0); - assertEquals(list0, op1); - assertEquals(list0, op2); - - op2.setAll(list2); - assertEquals(list2, op1); - assertEquals(list2, op2); - - FXCollections.sort(op2); - assertEquals(list2_sorted, op1); - assertEquals(list2_sorted, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_Null_X() { - Bindings.bindContent(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_X_Null() { - Bindings.bindContent(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testBind_X_Self() { - Bindings.bindContent(op2, op2); - } - - @Test - public void testUnbind() { - // unbind non-existing binding => no-op - Bindings.unbindContent(op1, op2); - - Bindings.bindContent(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(list2, op1); - assertEquals(list2, op2); - - Bindings.unbindContent(op1, op2); - System.gc(); - assertEquals(list2, op1); - assertEquals(list2, op2); - - op1.clear(); - assertEquals(list0, op1); - assertEquals(list2, op2); - - op2.setAll(list1); - assertEquals(list0, op1); - assertEquals(list1, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_Null_X() { - Bindings.unbindContent(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_X_Null() { - Bindings.unbindContent(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testUnbind_X_Self() { - Bindings.unbindContent(op2, op2); - } - - @Test - public void testChaining() { - Bindings.bindContent(op1, op2); - Bindings.bindContent(op2, op3); - System.gc(); // making sure we did not not overdo weak references - assertEquals(list0, op1); - assertEquals(list0, op2); - assertEquals(list0, op3); - - op3.setAll(list1); - assertEquals(list1, op1); - assertEquals(list1, op2); - assertEquals(list1, op3); - - // now unbind - Bindings.unbindContent(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(list1, op1); - assertEquals(list1, op2); - assertEquals(list1, op3); - - op3.setAll(list2); - assertEquals(list1, op1); - assertEquals(list2, op2); - assertEquals(list2, op3); - } - - @Test - public void testHashCode() { - final int hc1 = ContentBinding.bind(op1, op2).hashCode(); - ContentBinding.unbind(op1, op2); - final int hc2 = ContentBinding.bind(op1, op2).hashCode(); - assertEquals(hc1, hc2); - } - - @Test - public void testEquals() { - final Object golden = ContentBinding.bind(op1, op2); - ContentBinding.unbind(op1, op2); - - assertTrue(golden.equals(golden)); - assertFalse(golden.equals(null)); - assertFalse(golden.equals(op1)); - assertTrue(golden.equals(ContentBinding.bind(op1, op2))); - ContentBinding.unbind(op1, op2); - assertFalse(golden.equals(ContentBinding.bind(op3, op2))); - ContentBinding.unbind(op2, op3); - assertFalse(golden.equals(ContentBinding.bind(op2, op3))); - ContentBinding.unbind(op2, op3); - } - - @Test - public void testEqualsWithGCedProperty() { - final Object binding1 = ContentBinding.bind(op1, op2); - ContentBinding.unbind(op1, op2); - final Object binding2 = ContentBinding.bind(op1, op2); - ContentBinding.unbind(op1, op2); - op1 = null; - System.gc(); - - assertTrue(binding1.equals(binding1)); - assertFalse(binding1.equals(binding2)); - } - - @Test - public void testAlreadyBound() { - // get the current exception handler before replacing with our own, - // as ListListenerHelper intercepts the exception otherwise - final Thread.UncaughtExceptionHandler exceptionHandler = - Thread.currentThread().getUncaughtExceptionHandler(); - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> { - throw new AssertionError("We don't expect any exceptions in this test!", e); - } - ); - - ContentBinding.bind(op1, op2); - ContentBinding.bind(op1, op2); - op2.remove(1); - - // reset the exception handler - Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/ContentBindingListTest.java 2015-08-31 10:22:50.269217892 -0400 @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.ContentBinding; +import javafx.beans.binding.Bindings; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.*; + +public class ContentBindingListTest { + + private List op1; + private ObservableList op2; + private ObservableList op3; + private List list0; + private List list1; + private List list2; + + @Before + public void setUp() { + list0 = new ArrayList(); + list1 = new ArrayList(Arrays.asList(0)); + list2 = new ArrayList(Arrays.asList(2, 1)); + + op1 = new ArrayList(list1); + op2 = FXCollections.observableArrayList(list2); + op3 = FXCollections.observableArrayList(list0); + } + + @Test + public void testBind() { + List list2_sorted = new ArrayList(Arrays.asList(1, 2)); + + Bindings.bindContent(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(list2, op1); + assertEquals(list2, op2); + + op2.setAll(list1); + assertEquals(list1, op1); + assertEquals(list1, op2); + + op2.setAll(list0); + assertEquals(list0, op1); + assertEquals(list0, op2); + + op2.setAll(list2); + assertEquals(list2, op1); + assertEquals(list2, op2); + + FXCollections.sort(op2); + assertEquals(list2_sorted, op1); + assertEquals(list2_sorted, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_Null_X() { + Bindings.bindContent(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_X_Null() { + Bindings.bindContent(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testBind_X_Self() { + Bindings.bindContent(op2, op2); + } + + @Test + public void testUnbind() { + // unbind non-existing binding => no-op + Bindings.unbindContent(op1, op2); + + Bindings.bindContent(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(list2, op1); + assertEquals(list2, op2); + + Bindings.unbindContent(op1, op2); + System.gc(); + assertEquals(list2, op1); + assertEquals(list2, op2); + + op1.clear(); + assertEquals(list0, op1); + assertEquals(list2, op2); + + op2.setAll(list1); + assertEquals(list0, op1); + assertEquals(list1, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_Null_X() { + Bindings.unbindContent(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_X_Null() { + Bindings.unbindContent(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testUnbind_X_Self() { + Bindings.unbindContent(op2, op2); + } + + @Test + public void testChaining() { + Bindings.bindContent(op1, op2); + Bindings.bindContent(op2, op3); + System.gc(); // making sure we did not not overdo weak references + assertEquals(list0, op1); + assertEquals(list0, op2); + assertEquals(list0, op3); + + op3.setAll(list1); + assertEquals(list1, op1); + assertEquals(list1, op2); + assertEquals(list1, op3); + + // now unbind + Bindings.unbindContent(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(list1, op1); + assertEquals(list1, op2); + assertEquals(list1, op3); + + op3.setAll(list2); + assertEquals(list1, op1); + assertEquals(list2, op2); + assertEquals(list2, op3); + } + + @Test + public void testHashCode() { + final int hc1 = ContentBinding.bind(op1, op2).hashCode(); + ContentBinding.unbind(op1, op2); + final int hc2 = ContentBinding.bind(op1, op2).hashCode(); + assertEquals(hc1, hc2); + } + + @Test + public void testEquals() { + final Object golden = ContentBinding.bind(op1, op2); + ContentBinding.unbind(op1, op2); + + assertTrue(golden.equals(golden)); + assertFalse(golden.equals(null)); + assertFalse(golden.equals(op1)); + assertTrue(golden.equals(ContentBinding.bind(op1, op2))); + ContentBinding.unbind(op1, op2); + assertFalse(golden.equals(ContentBinding.bind(op3, op2))); + ContentBinding.unbind(op2, op3); + assertFalse(golden.equals(ContentBinding.bind(op2, op3))); + ContentBinding.unbind(op2, op3); + } + + @Test + public void testEqualsWithGCedProperty() { + final Object binding1 = ContentBinding.bind(op1, op2); + ContentBinding.unbind(op1, op2); + final Object binding2 = ContentBinding.bind(op1, op2); + ContentBinding.unbind(op1, op2); + op1 = null; + System.gc(); + + assertTrue(binding1.equals(binding1)); + assertFalse(binding1.equals(binding2)); + } + + @Test + public void testAlreadyBound() { + // get the current exception handler before replacing with our own, + // as ListListenerHelper intercepts the exception otherwise + final Thread.UncaughtExceptionHandler exceptionHandler = + Thread.currentThread().getUncaughtExceptionHandler(); + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> { + throw new AssertionError("We don't expect any exceptions in this test!", e); + } + ); + + ContentBinding.bind(op1, op2); + ContentBinding.bind(op1, op2); + op2.remove(1); + + // reset the exception handler + Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/ContentBindingMapTest.java 2015-08-31 10:22:51.005217883 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import javafx.beans.binding.Bindings; -import javafx.collections.FXCollections; -import javafx.collections.ObservableMap; -import org.junit.Before; -import org.junit.Test; - -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.*; - -public class ContentBindingMapTest { - - private static final String key1 = "Key1"; - private static final String key2_1 = "Key2_1"; - private static final String key2_2 = "Key2_2"; - - private Map op1; - private ObservableMap op2; - private ObservableMap op3; - private Map map0; - private Map map1; - private Map map2; - - @Before - public void setUp() { - map0 = new HashMap(); - map1 = new HashMap(); - map1.put(key1, -1); - map2 = new HashMap(); - map2.put(key2_1, 2); - map2.put(key2_2, 1); - - op1 = new HashMap(map1); - op2 = FXCollections.observableMap(map2); - op3 = FXCollections.observableMap(map0); - } - - @Test - public void testBind() { - Bindings.bindContent(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(map2, op1); - assertEquals(map2, op2); - - op2.clear(); - op2.putAll(map1); - assertEquals(map1, op1); - assertEquals(map1, op2); - - op2.clear(); - op2.putAll(map0); - assertEquals(map0, op1); - assertEquals(map0, op2); - - op2.clear(); - op2.putAll(map2); - assertEquals(map2, op1); - assertEquals(map2, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_Null_X() { - Bindings.bindContent(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_X_Null() { - Bindings.bindContent(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testBind_X_Self() { - Bindings.bindContent(op2, op2); - } - - @Test - public void testUnbind() { - // unbind non-existing binding => no-op - Bindings.unbindContent(op1, op2); - - Bindings.bindContent(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(map2, op1); - assertEquals(map2, op2); - - Bindings.unbindContent(op1, op2); - System.gc(); - assertEquals(map2, op1); - assertEquals(map2, op2); - - op1.clear(); - assertEquals(map0, op1); - assertEquals(map2, op2); - - op2.clear(); - op2.putAll(map1); - assertEquals(map0, op1); - assertEquals(map1, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_Null_X() { - Bindings.unbindContent(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_X_Null() { - Bindings.unbindContent(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testUnbind_X_Self() { - Bindings.unbindContent(op2, op2); - } - - @Test - public void testChaining() { - Bindings.bindContent(op1, op2); - Bindings.bindContent(op2, op3); - System.gc(); // making sure we did not not overdo weak references - assertEquals(map0, op1); - assertEquals(map0, op2); - assertEquals(map0, op3); - - op3.clear(); - op3.putAll(map1); - assertEquals(map1, op1); - assertEquals(map1, op2); - assertEquals(map1, op3); - - // now unbind - Bindings.unbindContent(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(map1, op1); - assertEquals(map1, op2); - assertEquals(map1, op3); - - op3.clear(); - op3.putAll(map2); - assertEquals(map1, op1); - assertEquals(map2, op2); - assertEquals(map2, op3); - } - - @Test - public void testHashCode() { - final int hc1 = ContentBinding.bind(op1, op2).hashCode(); - ContentBinding.unbind(op1, op2); - final int hc2 = ContentBinding.bind(op1, op2).hashCode(); - assertEquals(hc1, hc2); - } - - @Test - public void testEquals() { - final Object golden = ContentBinding.bind(op1, op2); - ContentBinding.unbind(op1, op2); - - assertTrue(golden.equals(golden)); - assertFalse(golden.equals(null)); - assertFalse(golden.equals(op1)); - assertTrue(golden.equals(ContentBinding.bind(op1, op2))); - ContentBinding.unbind(op1, op2); - assertFalse(golden.equals(ContentBinding.bind(op3, op2))); - ContentBinding.unbind(op2, op3); - assertFalse(golden.equals(ContentBinding.bind(op2, op3))); - ContentBinding.unbind(op2, op3); - } - - @Test - public void testEqualsWithGCedProperty() { - final Object binding1 = ContentBinding.bind(op1, op2); - ContentBinding.unbind(op1, op2); - final Object binding2 = ContentBinding.bind(op1, op2); - ContentBinding.unbind(op1, op2); - op1 = null; - System.gc(); - - assertTrue(binding1.equals(binding1)); - assertFalse(binding1.equals(binding2)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/ContentBindingMapTest.java 2015-08-31 10:22:50.869217885 -0400 @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.ContentBinding; +import javafx.beans.binding.Bindings; +import javafx.collections.FXCollections; +import javafx.collections.ObservableMap; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +public class ContentBindingMapTest { + + private static final String key1 = "Key1"; + private static final String key2_1 = "Key2_1"; + private static final String key2_2 = "Key2_2"; + + private Map op1; + private ObservableMap op2; + private ObservableMap op3; + private Map map0; + private Map map1; + private Map map2; + + @Before + public void setUp() { + map0 = new HashMap(); + map1 = new HashMap(); + map1.put(key1, -1); + map2 = new HashMap(); + map2.put(key2_1, 2); + map2.put(key2_2, 1); + + op1 = new HashMap(map1); + op2 = FXCollections.observableMap(map2); + op3 = FXCollections.observableMap(map0); + } + + @Test + public void testBind() { + Bindings.bindContent(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(map2, op1); + assertEquals(map2, op2); + + op2.clear(); + op2.putAll(map1); + assertEquals(map1, op1); + assertEquals(map1, op2); + + op2.clear(); + op2.putAll(map0); + assertEquals(map0, op1); + assertEquals(map0, op2); + + op2.clear(); + op2.putAll(map2); + assertEquals(map2, op1); + assertEquals(map2, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_Null_X() { + Bindings.bindContent(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_X_Null() { + Bindings.bindContent(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testBind_X_Self() { + Bindings.bindContent(op2, op2); + } + + @Test + public void testUnbind() { + // unbind non-existing binding => no-op + Bindings.unbindContent(op1, op2); + + Bindings.bindContent(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(map2, op1); + assertEquals(map2, op2); + + Bindings.unbindContent(op1, op2); + System.gc(); + assertEquals(map2, op1); + assertEquals(map2, op2); + + op1.clear(); + assertEquals(map0, op1); + assertEquals(map2, op2); + + op2.clear(); + op2.putAll(map1); + assertEquals(map0, op1); + assertEquals(map1, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_Null_X() { + Bindings.unbindContent(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_X_Null() { + Bindings.unbindContent(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testUnbind_X_Self() { + Bindings.unbindContent(op2, op2); + } + + @Test + public void testChaining() { + Bindings.bindContent(op1, op2); + Bindings.bindContent(op2, op3); + System.gc(); // making sure we did not not overdo weak references + assertEquals(map0, op1); + assertEquals(map0, op2); + assertEquals(map0, op3); + + op3.clear(); + op3.putAll(map1); + assertEquals(map1, op1); + assertEquals(map1, op2); + assertEquals(map1, op3); + + // now unbind + Bindings.unbindContent(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(map1, op1); + assertEquals(map1, op2); + assertEquals(map1, op3); + + op3.clear(); + op3.putAll(map2); + assertEquals(map1, op1); + assertEquals(map2, op2); + assertEquals(map2, op3); + } + + @Test + public void testHashCode() { + final int hc1 = ContentBinding.bind(op1, op2).hashCode(); + ContentBinding.unbind(op1, op2); + final int hc2 = ContentBinding.bind(op1, op2).hashCode(); + assertEquals(hc1, hc2); + } + + @Test + public void testEquals() { + final Object golden = ContentBinding.bind(op1, op2); + ContentBinding.unbind(op1, op2); + + assertTrue(golden.equals(golden)); + assertFalse(golden.equals(null)); + assertFalse(golden.equals(op1)); + assertTrue(golden.equals(ContentBinding.bind(op1, op2))); + ContentBinding.unbind(op1, op2); + assertFalse(golden.equals(ContentBinding.bind(op3, op2))); + ContentBinding.unbind(op2, op3); + assertFalse(golden.equals(ContentBinding.bind(op2, op3))); + ContentBinding.unbind(op2, op3); + } + + @Test + public void testEqualsWithGCedProperty() { + final Object binding1 = ContentBinding.bind(op1, op2); + ContentBinding.unbind(op1, op2); + final Object binding2 = ContentBinding.bind(op1, op2); + ContentBinding.unbind(op1, op2); + op1 = null; + System.gc(); + + assertTrue(binding1.equals(binding1)); + assertFalse(binding1.equals(binding2)); + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/ContentBindingSetTest.java 2015-08-31 10:22:51.613217876 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import javafx.beans.binding.Bindings; -import javafx.collections.FXCollections; -import javafx.collections.ObservableSet; -import org.junit.Before; -import org.junit.Test; - -import java.util.HashSet; -import java.util.Set; - -import static org.junit.Assert.*; - -public class ContentBindingSetTest { - - private Set op1; - private ObservableSet op2; - private ObservableSet op3; - private Set set0; - private Set set1; - private Set set2; - - @Before - public void setUp() { - set0 = new HashSet(); - set1 = new HashSet(); - set1.add(-1); - set2 = new HashSet(2, 1); - set2.add(2); - set2.add(1); - - op1 = new HashSet(set1); - op2 = FXCollections.observableSet(set2); - op3 = FXCollections.observableSet(set0); - } - - @Test - public void testBind() { - Bindings.bindContent(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(set2, op1); - assertEquals(set2, op2); - - op2.clear(); - op2.addAll(set1); - assertEquals(set1, op1); - assertEquals(set1, op2); - - op2.clear(); - op2.addAll(set0); - assertEquals(set0, op1); - assertEquals(set0, op2); - - op2.clear(); - op2.addAll(set2); - assertEquals(set2, op1); - assertEquals(set2, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_Null_X() { - Bindings.bindContent(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testBind_X_Null() { - Bindings.bindContent(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testBind_X_Self() { - Bindings.bindContent(op2, op2); - } - - @Test - public void testUnbind() { - // unbind non-existing binding => no-op - Bindings.unbindContent(op1, op2); - - Bindings.bindContent(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(set2, op1); - assertEquals(set2, op2); - - Bindings.unbindContent(op1, op2); - System.gc(); - assertEquals(set2, op1); - assertEquals(set2, op2); - - op1.clear(); - assertEquals(set0, op1); - assertEquals(set2, op2); - - op2.clear(); - op2.addAll(set1); - assertEquals(set0, op1); - assertEquals(set1, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_Null_X() { - Bindings.unbindContent(null, op2); - } - - @Test(expected = NullPointerException.class) - public void testUnbind_X_Null() { - Bindings.unbindContent(op1, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testUnbind_X_Self() { - Bindings.unbindContent(op2, op2); - } - - @Test - public void testChaining() { - Bindings.bindContent(op1, op2); - Bindings.bindContent(op2, op3); - System.gc(); // making sure we did not not overdo weak references - assertEquals(set0, op1); - assertEquals(set0, op2); - assertEquals(set0, op3); - - op3.clear(); - op3.addAll(set1); - assertEquals(set1, op1); - assertEquals(set1, op2); - assertEquals(set1, op3); - - // now unbind - Bindings.unbindContent(op1, op2); - System.gc(); // making sure we did not not overdo weak references - assertEquals(set1, op1); - assertEquals(set1, op2); - assertEquals(set1, op3); - - op3.clear(); - op3.addAll(set2); - assertEquals(set1, op1); - assertEquals(set2, op2); - assertEquals(set2, op3); - } - - @Test - public void testHashCode() { - final int hc1 = ContentBinding.bind(op1, op2).hashCode(); - ContentBinding.unbind(op1, op2); - final int hc2 = ContentBinding.bind(op1, op2).hashCode(); - assertEquals(hc1, hc2); - } - - @Test - public void testEquals() { - final Object golden = ContentBinding.bind(op1, op2); - ContentBinding.unbind(op1, op2); - - assertTrue(golden.equals(golden)); - assertFalse(golden.equals(null)); - assertFalse(golden.equals(op1)); - assertTrue(golden.equals(ContentBinding.bind(op1, op2))); - ContentBinding.unbind(op1, op2); - assertFalse(golden.equals(ContentBinding.bind(op3, op2))); - ContentBinding.unbind(op2, op3); - assertFalse(golden.equals(ContentBinding.bind(op2, op3))); - ContentBinding.unbind(op2, op3); - } - - @Test - public void testEqualsWithGCedProperty() { - final Object binding1 = ContentBinding.bind(op1, op2); - ContentBinding.unbind(op1, op2); - final Object binding2 = ContentBinding.bind(op1, op2); - ContentBinding.unbind(op1, op2); - op1 = null; - System.gc(); - - assertTrue(binding1.equals(binding1)); - assertFalse(binding1.equals(binding2)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/ContentBindingSetTest.java 2015-08-31 10:22:51.481217878 -0400 @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.ContentBinding; +import javafx.beans.binding.Bindings; +import javafx.collections.FXCollections; +import javafx.collections.ObservableSet; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.*; + +public class ContentBindingSetTest { + + private Set op1; + private ObservableSet op2; + private ObservableSet op3; + private Set set0; + private Set set1; + private Set set2; + + @Before + public void setUp() { + set0 = new HashSet(); + set1 = new HashSet(); + set1.add(-1); + set2 = new HashSet(2, 1); + set2.add(2); + set2.add(1); + + op1 = new HashSet(set1); + op2 = FXCollections.observableSet(set2); + op3 = FXCollections.observableSet(set0); + } + + @Test + public void testBind() { + Bindings.bindContent(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(set2, op1); + assertEquals(set2, op2); + + op2.clear(); + op2.addAll(set1); + assertEquals(set1, op1); + assertEquals(set1, op2); + + op2.clear(); + op2.addAll(set0); + assertEquals(set0, op1); + assertEquals(set0, op2); + + op2.clear(); + op2.addAll(set2); + assertEquals(set2, op1); + assertEquals(set2, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_Null_X() { + Bindings.bindContent(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testBind_X_Null() { + Bindings.bindContent(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testBind_X_Self() { + Bindings.bindContent(op2, op2); + } + + @Test + public void testUnbind() { + // unbind non-existing binding => no-op + Bindings.unbindContent(op1, op2); + + Bindings.bindContent(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(set2, op1); + assertEquals(set2, op2); + + Bindings.unbindContent(op1, op2); + System.gc(); + assertEquals(set2, op1); + assertEquals(set2, op2); + + op1.clear(); + assertEquals(set0, op1); + assertEquals(set2, op2); + + op2.clear(); + op2.addAll(set1); + assertEquals(set0, op1); + assertEquals(set1, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_Null_X() { + Bindings.unbindContent(null, op2); + } + + @Test(expected = NullPointerException.class) + public void testUnbind_X_Null() { + Bindings.unbindContent(op1, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testUnbind_X_Self() { + Bindings.unbindContent(op2, op2); + } + + @Test + public void testChaining() { + Bindings.bindContent(op1, op2); + Bindings.bindContent(op2, op3); + System.gc(); // making sure we did not not overdo weak references + assertEquals(set0, op1); + assertEquals(set0, op2); + assertEquals(set0, op3); + + op3.clear(); + op3.addAll(set1); + assertEquals(set1, op1); + assertEquals(set1, op2); + assertEquals(set1, op3); + + // now unbind + Bindings.unbindContent(op1, op2); + System.gc(); // making sure we did not not overdo weak references + assertEquals(set1, op1); + assertEquals(set1, op2); + assertEquals(set1, op3); + + op3.clear(); + op3.addAll(set2); + assertEquals(set1, op1); + assertEquals(set2, op2); + assertEquals(set2, op3); + } + + @Test + public void testHashCode() { + final int hc1 = ContentBinding.bind(op1, op2).hashCode(); + ContentBinding.unbind(op1, op2); + final int hc2 = ContentBinding.bind(op1, op2).hashCode(); + assertEquals(hc1, hc2); + } + + @Test + public void testEquals() { + final Object golden = ContentBinding.bind(op1, op2); + ContentBinding.unbind(op1, op2); + + assertTrue(golden.equals(golden)); + assertFalse(golden.equals(null)); + assertFalse(golden.equals(op1)); + assertTrue(golden.equals(ContentBinding.bind(op1, op2))); + ContentBinding.unbind(op1, op2); + assertFalse(golden.equals(ContentBinding.bind(op3, op2))); + ContentBinding.unbind(op2, op3); + assertFalse(golden.equals(ContentBinding.bind(op2, op3))); + ContentBinding.unbind(op2, op3); + } + + @Test + public void testEqualsWithGCedProperty() { + final Object binding1 = ContentBinding.bind(op1, op2); + ContentBinding.unbind(op1, op2); + final Object binding2 = ContentBinding.bind(op1, op2); + ContentBinding.unbind(op1, op2); + op1 = null; + System.gc(); + + assertTrue(binding1.equals(binding1)); + assertFalse(binding1.equals(binding2)); + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/ErrorLoggingUtiltity.java 2015-08-31 10:22:52.213217870 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogManager; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - -import static org.junit.Assert.*; - -public class ErrorLoggingUtiltity { - - static { - // initialize PlatformLogger - Logging.getLogger(); - } - - // getLogManager will redirect existing PlatformLogger to the Logger - private static final Logger logger = LogManager.getLogManager().getLogger("javafx.beans"); - - Level level; - LogRecord lastRecord; - - Handler handler = new Handler() { - - @Override - public void publish(LogRecord record) { - lastRecord = record; - } - - @Override - public void flush() { - } - - @Override - public void close() throws SecurityException { - } - }; - - public void start() { - reset(); - level = logger.getLevel(); - logger.setLevel(Level.ALL); - logger.addHandler(handler); - } - - public void stop() { - logger.setLevel(level); - logger.removeHandler(handler); - } - - public void reset() { - lastRecord = null; - } - - public void checkFine(Class expectedException) { - check(Level.FINE, expectedException); - } - - public void check(Level expectedLevel, Class expectedException) { - assertNotNull(lastRecord); - assertEquals(expectedLevel, lastRecord.getLevel()); - assertEquals(expectedException, lastRecord.getThrown().getClass()); - reset(); - } - - public boolean isEmpty() { - return lastRecord == null; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/ErrorLoggingUtiltity.java 2015-08-31 10:22:52.077217871 -0400 @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.Logging; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogManager; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +import static org.junit.Assert.*; + +public class ErrorLoggingUtiltity { + + static { + // initialize PlatformLogger + Logging.getLogger(); + } + + // getLogManager will redirect existing PlatformLogger to the Logger + private static final Logger logger = LogManager.getLogManager().getLogger("javafx.beans"); + + Level level; + LogRecord lastRecord; + + Handler handler = new Handler() { + + @Override + public void publish(LogRecord record) { + lastRecord = record; + } + + @Override + public void flush() { + } + + @Override + public void close() throws SecurityException { + } + }; + + public void start() { + reset(); + level = logger.getLevel(); + logger.setLevel(Level.ALL); + logger.addHandler(handler); + } + + public void stop() { + logger.setLevel(level); + logger.removeHandler(handler); + } + + public void reset() { + lastRecord = null; + } + + public void checkFine(Class expectedException) { + check(Level.FINE, expectedException); + } + + public void check(Level expectedLevel, Class expectedException) { + assertNotNull(lastRecord); + assertEquals(expectedLevel, lastRecord.getLevel()); + assertEquals(expectedException, lastRecord.getThrown().getClass()); + reset(); + } + + public boolean isEmpty() { + return lastRecord == null; + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/ExpressionHelperBaseTest.java 2015-08-31 10:22:52.929217862 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import static org.junit.Assert.*; - -import javafx.beans.WeakListener; -import org.junit.Test; - -public class ExpressionHelperBaseTest { - - private static final Object listener = new Object(); - private static final Object listener2 = new Object(); - - private static final WeakListener validWeakListener = () -> false; - - private static final WeakListener gcedWeakListener = () -> true; - - @Test - public void testEmptyArray() { - Object[] array = new Object[0]; - assertEquals(0, ExpressionHelperBase.trim(0, array)); - assertArrayEquals(new Object[0], array); - - array = new Object[1]; - assertEquals(0, ExpressionHelperBase.trim(0, array)); - assertArrayEquals(new Object[1], array); - } - - @Test - public void testSingleElement() { - Object[] array = new Object[] {listener}; - assertEquals(1, ExpressionHelperBase.trim(1, array)); - assertArrayEquals(new Object[] {listener}, array); - - array = new Object[] {validWeakListener}; - assertEquals(1, ExpressionHelperBase.trim(1, array)); - assertArrayEquals(new Object[] {validWeakListener}, array); - - array = new Object[] {gcedWeakListener}; - assertEquals(0, ExpressionHelperBase.trim(1, array)); - assertArrayEquals(new Object[] {null}, array); - - array = new Object[] {listener, null}; - assertEquals(1, ExpressionHelperBase.trim(1, array)); - assertArrayEquals(new Object[] {listener, null}, array); - - array = new Object[] {validWeakListener, null}; - assertEquals(1, ExpressionHelperBase.trim(1, array)); - assertArrayEquals(new Object[] {validWeakListener, null}, array); - - array = new Object[] {gcedWeakListener, null}; - assertEquals(0, ExpressionHelperBase.trim(1, array)); - assertArrayEquals(new Object[] {null, null}, array); - } - - @Test - public void testMultipleElements() { - Object[] array = new Object[] {validWeakListener, listener, listener2}; - assertEquals(3, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {validWeakListener, listener, listener2}, array); - - array = new Object[] {listener, validWeakListener, listener2}; - assertEquals(3, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {listener, validWeakListener, listener2}, array); - - array = new Object[] {listener, listener2, validWeakListener}; - assertEquals(3, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {listener, listener2, validWeakListener}, array); - - array = new Object[] {validWeakListener, listener, listener2, null}; - assertEquals(3, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {validWeakListener, listener, listener2, null}, array); - - array = new Object[] {listener, validWeakListener, listener2, null}; - assertEquals(3, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {listener, validWeakListener, listener2, null}, array); - - array = new Object[] {listener, listener2, validWeakListener, null}; - assertEquals(3, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {listener, listener2, validWeakListener, null}, array); - - - array = new Object[] {gcedWeakListener, validWeakListener, listener}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {validWeakListener, listener, null}, array); - - array = new Object[] {gcedWeakListener, listener, validWeakListener}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {listener, validWeakListener, null}, array); - - array = new Object[] {gcedWeakListener, validWeakListener, listener, null}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {validWeakListener, listener, null, null}, array); - - array = new Object[] {gcedWeakListener, listener, validWeakListener, null}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {listener, validWeakListener, null, null}, array); - - - array = new Object[] {validWeakListener, gcedWeakListener, listener}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {validWeakListener, listener, null}, array); - - array = new Object[] {listener, gcedWeakListener, validWeakListener}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {listener, validWeakListener, null}, array); - - array = new Object[] {validWeakListener, gcedWeakListener, listener, null}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {validWeakListener, listener, null, null}, array); - - array = new Object[] {listener, gcedWeakListener, validWeakListener, null}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {listener, validWeakListener, null, null}, array); - - - array = new Object[] {validWeakListener, listener, gcedWeakListener}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {validWeakListener, listener, null}, array); - - array = new Object[] {listener, validWeakListener, gcedWeakListener}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {listener, validWeakListener, null}, array); - - array = new Object[] {validWeakListener, listener, gcedWeakListener, null}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {validWeakListener, listener, null, null}, array); - - array = new Object[] {listener, validWeakListener, gcedWeakListener, null}; - assertEquals(2, ExpressionHelperBase.trim(3, array)); - assertArrayEquals(new Object[] {listener, validWeakListener, null, null}, array); - - - array = new Object[] {gcedWeakListener, gcedWeakListener}; - assertEquals(0, ExpressionHelperBase.trim(2, array)); - assertArrayEquals(new Object[] {null, null}, array); - - array = new Object[] {gcedWeakListener, gcedWeakListener, null}; - assertEquals(0, ExpressionHelperBase.trim(2, array)); - assertArrayEquals(new Object[] {null, null, null}, array); - } - - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/ExpressionHelperBaseTest.java 2015-08-31 10:22:52.793217863 -0400 @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.ExpressionHelperBaseShim; +import static org.junit.Assert.*; + +import javafx.beans.WeakListener; +import org.junit.Test; + +public class ExpressionHelperBaseTest { + + private static final Object listener = new Object(); + private static final Object listener2 = new Object(); + + private static final WeakListener validWeakListener = () -> false; + + private static final WeakListener gcedWeakListener = () -> true; + + @Test + public void testEmptyArray() { + Object[] array = new Object[0]; + assertEquals(0, ExpressionHelperBaseShim.trim(0, array)); + assertArrayEquals(new Object[0], array); + + array = new Object[1]; + assertEquals(0, ExpressionHelperBaseShim.trim(0, array)); + assertArrayEquals(new Object[1], array); + } + + @Test + public void testSingleElement() { + Object[] array = new Object[] {listener}; + assertEquals(1, ExpressionHelperBaseShim.trim(1, array)); + assertArrayEquals(new Object[] {listener}, array); + + array = new Object[] {validWeakListener}; + assertEquals(1, ExpressionHelperBaseShim.trim(1, array)); + assertArrayEquals(new Object[] {validWeakListener}, array); + + array = new Object[] {gcedWeakListener}; + assertEquals(0, ExpressionHelperBaseShim.trim(1, array)); + assertArrayEquals(new Object[] {null}, array); + + array = new Object[] {listener, null}; + assertEquals(1, ExpressionHelperBaseShim.trim(1, array)); + assertArrayEquals(new Object[] {listener, null}, array); + + array = new Object[] {validWeakListener, null}; + assertEquals(1, ExpressionHelperBaseShim.trim(1, array)); + assertArrayEquals(new Object[] {validWeakListener, null}, array); + + array = new Object[] {gcedWeakListener, null}; + assertEquals(0, ExpressionHelperBaseShim.trim(1, array)); + assertArrayEquals(new Object[] {null, null}, array); + } + + @Test + public void testMultipleElements() { + Object[] array = new Object[] {validWeakListener, listener, listener2}; + assertEquals(3, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {validWeakListener, listener, listener2}, array); + + array = new Object[] {listener, validWeakListener, listener2}; + assertEquals(3, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {listener, validWeakListener, listener2}, array); + + array = new Object[] {listener, listener2, validWeakListener}; + assertEquals(3, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {listener, listener2, validWeakListener}, array); + + array = new Object[] {validWeakListener, listener, listener2, null}; + assertEquals(3, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {validWeakListener, listener, listener2, null}, array); + + array = new Object[] {listener, validWeakListener, listener2, null}; + assertEquals(3, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {listener, validWeakListener, listener2, null}, array); + + array = new Object[] {listener, listener2, validWeakListener, null}; + assertEquals(3, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {listener, listener2, validWeakListener, null}, array); + + array = new Object[] {gcedWeakListener, validWeakListener, listener}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {validWeakListener, listener, null}, array); + + array = new Object[] {gcedWeakListener, listener, validWeakListener}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {listener, validWeakListener, null}, array); + + array = new Object[] {gcedWeakListener, validWeakListener, listener, null}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {validWeakListener, listener, null, null}, array); + + array = new Object[] {gcedWeakListener, listener, validWeakListener, null}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {listener, validWeakListener, null, null}, array); + + + array = new Object[] {validWeakListener, gcedWeakListener, listener}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {validWeakListener, listener, null}, array); + + array = new Object[] {listener, gcedWeakListener, validWeakListener}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {listener, validWeakListener, null}, array); + + array = new Object[] {validWeakListener, gcedWeakListener, listener, null}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {validWeakListener, listener, null, null}, array); + + array = new Object[] {listener, gcedWeakListener, validWeakListener, null}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {listener, validWeakListener, null, null}, array); + + + array = new Object[] {validWeakListener, listener, gcedWeakListener}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {validWeakListener, listener, null}, array); + + array = new Object[] {listener, validWeakListener, gcedWeakListener}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {listener, validWeakListener, null}, array); + + array = new Object[] {validWeakListener, listener, gcedWeakListener, null}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {validWeakListener, listener, null, null}, array); + + array = new Object[] {listener, validWeakListener, gcedWeakListener, null}; + assertEquals(2, ExpressionHelperBaseShim.trim(3, array)); + assertArrayEquals(new Object[] {listener, validWeakListener, null, null}, array); + + + array = new Object[] {gcedWeakListener, gcedWeakListener}; + assertEquals(0, ExpressionHelperBaseShim.trim(2, array)); + assertArrayEquals(new Object[] {null, null}, array); + + array = new Object[] {gcedWeakListener, gcedWeakListener, null}; + assertEquals(0, ExpressionHelperBaseShim.trim(2, array)); + assertArrayEquals(new Object[] {null, null, null}, array); + } + + +} --- old/modules/base/src/test/java/com/sun/javafx/binding/ExpressionHelperTest.java 2015-08-31 10:22:53.545217855 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,646 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import javafx.beans.InvalidationListener; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.Observable; -import javafx.beans.WeakInvalidationListenerMock; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableValue; -import javafx.beans.value.ObservableValueStub; -import javafx.beans.value.WeakChangeListenerMock; -import org.junit.Before; -import org.junit.Test; - -import java.util.BitSet; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class ExpressionHelperTest { - - private static final Object UNDEFINED = new Object(); - private static final Object DATA_1 = new Object(); - private static final Object DATA_2 = new Object(); - - private ExpressionHelper helper; - private ObservableValueStub observable; - private InvalidationListenerMock[] invalidationListener; - private ChangeListenerMock[] changeListener; - - @Before - public void setUp() { - helper = null; - observable = new ObservableValueStub(DATA_1); - invalidationListener = new InvalidationListenerMock[] { - new InvalidationListenerMock(), new InvalidationListenerMock(), new InvalidationListenerMock(), new InvalidationListenerMock() - }; - changeListener = new ChangeListenerMock[] { - new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED) - }; - } - - @Test (expected = NullPointerException.class) - public void testAddInvalidation_Null_X() { - ExpressionHelper.addListener(helper, null, invalidationListener[0]); - } - - @Test (expected = NullPointerException.class) - public void testAddInvalidation_X_Null() { - ExpressionHelper.addListener(helper, observable, (InvalidationListener) null); - } - - @Test (expected = NullPointerException.class) - public void testRemoveInvalidation_Null() { - ExpressionHelper.removeListener(helper, (InvalidationListener) null); - } - - @Test (expected = NullPointerException.class) - public void testAddChange_Null_X() { - ExpressionHelper.addListener(helper, null, changeListener[0]); - } - - @Test (expected = NullPointerException.class) - public void testAddChange_X_Null() { - ExpressionHelper.addListener(helper, observable, (ChangeListener) null); - } - - @Test (expected = NullPointerException.class) - public void testRemoveChange_Null() { - ExpressionHelper.removeListener(helper, (ChangeListener) null); - } - - @Test - public void testEmptyHelper() { - // all of these calls should be no-ops - ExpressionHelper.removeListener(helper, invalidationListener[0]); - ExpressionHelper.removeListener(helper, changeListener[0]); - ExpressionHelper.fireValueChangedEvent(helper); - } - - @Test - public void testSingeInvalidation() { - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - - helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(null, 0); - - helper = ExpressionHelper.removeListener(helper, changeListener[1]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - - helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(null, 0); - - helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[1].check(observable, DATA_1, DATA_2, 1); - - helper = ExpressionHelper.removeListener(helper, changeListener[1]); - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - - helper = ExpressionHelper.removeListener(helper, invalidationListener[0]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - } - - @Test - public void testSingeChange() { - helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_1, DATA_2, 1); - - helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_2, DATA_1, 1); - invalidationListener[1].check(null, 0); - - helper = ExpressionHelper.removeListener(helper, changeListener[1]); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_1, DATA_2, 1); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_2, DATA_1, 1); - invalidationListener[1].check(observable, 1); - - helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_1, DATA_2, 1); - invalidationListener[1].check(null, 0); - - helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_2, DATA_1, 1); - changeListener[1].check(observable, DATA_2, DATA_1, 1); - - helper = ExpressionHelper.removeListener(helper, changeListener[1]); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_1, DATA_2, 1); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - - helper = ExpressionHelper.removeListener(helper, changeListener[0]); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testAddInvalidation() { - final InvalidationListener weakListener = new WeakInvalidationListenerMock(); - - helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); - helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); - - helper = ExpressionHelper.addListener(helper, observable, weakListener); - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - - helper = ExpressionHelper.addListener(helper, observable, weakListener); - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - - helper = ExpressionHelper.addListener(helper, observable, weakListener); - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[2]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - invalidationListener[2].check(observable, 1); - } - - @Test - public void testRemoveInvalidation() { - helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); - helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); - - helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); - - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); - - helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); - - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[2]); - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); - - helper = ExpressionHelper.removeListener(helper, invalidationListener[0]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].check(observable, 1); - invalidationListener[2].check(observable, 1); - - helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].check(null, 0); - invalidationListener[2].check(observable, 1); - - helper = ExpressionHelper.removeListener(helper, invalidationListener[2]); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].check(null, 0); - invalidationListener[2].check(null, 0); - } - - @Test - public void testAddInvalidationWhileLocked() { - final ChangeListener addingListener = new ChangeListener() { - int index = 0; - @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { - if (index < invalidationListener.length) { - helper = ExpressionHelper.addListener(helper, ExpressionHelperTest.this.observable, invalidationListener[index++]); - } - } - }; - helper = ExpressionHelper.addListener(helper, observable, addingListener); - helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); - - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - - invalidationListener[0].reset(); - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - - invalidationListener[1].reset(); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - - invalidationListener[2].reset(); - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - invalidationListener[2].check(observable, 1); - - invalidationListener[3].reset(); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - invalidationListener[2].check(observable, 1); - invalidationListener[3].check(observable, 1); - } - - @Test - public void testRemoveInvalidationWhileLocked() { - final ChangeListener removingListener = new ChangeListener() { - int index = 0; - @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { - if (index < invalidationListener.length) { - helper = ExpressionHelper.removeListener(helper, invalidationListener[index++]); - } - } - }; - helper = ExpressionHelper.addListener(helper, observable, removingListener); - helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[2]); - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); - - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].reset(); - invalidationListener[1].check(observable, 1); - invalidationListener[2].check(observable, 1); - - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].reset(); - invalidationListener[2].check(observable, 1); - - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].check(null, 0); - invalidationListener[2].reset(); - - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].check(null, 0); - invalidationListener[2].check(null, 0); - } - - @Test - public void testAddChange() { - final ChangeListener weakListener = new WeakChangeListenerMock(); - - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); - - helper = ExpressionHelper.addListener(helper, observable, weakListener); - helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_1, DATA_2, 1); - - helper = ExpressionHelper.addListener(helper, observable, weakListener); - helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_2, DATA_1, 1); - changeListener[1].check(observable, DATA_2, DATA_1, 1); - - helper = ExpressionHelper.addListener(helper, observable, weakListener); - helper = ExpressionHelper.addListener(helper, observable, changeListener[2]); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_1, DATA_2, 1); - changeListener[1].check(observable, DATA_1, DATA_2, 1); - changeListener[2].check(observable, DATA_1, DATA_2, 1); - } - - @Test - public void testRemoveChange() { - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); - - helper = ExpressionHelper.removeListener(helper, changeListener[1]); - - helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); - - helper = ExpressionHelper.removeListener(helper, changeListener[1]); - - helper = ExpressionHelper.addListener(helper, observable, changeListener[2]); - helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); - - helper = ExpressionHelper.removeListener(helper, changeListener[0]); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].check(observable, DATA_1, DATA_2, 1); - changeListener[2].check(observable, DATA_1, DATA_2, 1); - - helper = ExpressionHelper.removeListener(helper, changeListener[1]); - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[2].check(observable, DATA_2, DATA_1, 1); - - helper = ExpressionHelper.removeListener(helper, changeListener[2]); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[2].check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testAddChangeWhileLocked() { - final InvalidationListener addingListener = new InvalidationListener() { - int index = 0; - @Override public void invalidated(Observable observable) { - if (index < invalidationListener.length) { - helper = ExpressionHelper.addListener(helper, ExpressionHelperTest.this.observable, changeListener[index++]); - } - } - }; - helper = ExpressionHelper.addListener(helper, observable, addingListener); - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); - - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - - changeListener[0].reset(); - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_2, DATA_1, 1); - - changeListener[1].reset(); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_1, DATA_2, 1); - changeListener[1].check(observable, DATA_1, DATA_2, 1); - - changeListener[2].reset(); - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_2, DATA_1, 1); - changeListener[1].check(observable, DATA_2, DATA_1, 1); - changeListener[2].check(observable, DATA_2, DATA_1, 1); - - changeListener[3].reset(); - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, DATA_1, DATA_2, 1); - changeListener[1].check(observable, DATA_1, DATA_2, 1); - changeListener[2].check(observable, DATA_1, DATA_2, 1); - changeListener[3].check(observable, DATA_1, DATA_2, 1); - } - - @Test - public void testRemoveChangeWhileLocked() { - final InvalidationListener removingListener = new InvalidationListener() { - int index = 0; - @Override public void invalidated(Observable observable) { - if (index < invalidationListener.length) { - helper = ExpressionHelper.removeListener(helper, changeListener[index++]); - } - } - }; - helper = ExpressionHelper.addListener(helper, observable, removingListener); - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); - helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); - helper = ExpressionHelper.addListener(helper, observable, changeListener[2]); - helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); - - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].reset(); - changeListener[1].check(observable, DATA_1, DATA_2, 1); - changeListener[2].check(observable, DATA_1, DATA_2, 1); - - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].reset(); - changeListener[2].check(observable, DATA_2, DATA_1, 1); - - observable.set(DATA_2); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[2].reset(); - - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[2].check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testFireValueChangedEvent() { - helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); - helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); - - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - - observable.set(null); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(observable, DATA_1, null, 1); - - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - - observable.set(DATA_1); - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(observable, null, DATA_1, 1); - - ExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testExceptionNotPropagatedFromSingleInvalidation() { - helper = ExpressionHelper.addListener(helper, observable,(o) -> {throw new RuntimeException();}); - observable.set(null); - helper.fireValueChangedEvent(); - } - - @Test - public void testExceptionNotPropagatedFromMultipleInvalidation() { - BitSet called = new BitSet(); - - helper = ExpressionHelper.addListener(helper, observable, (o) -> {called.set(0); throw new RuntimeException();}); - helper = ExpressionHelper.addListener(helper, observable, (o) -> {called.set(1); throw new RuntimeException();}); - observable.set(null); - helper.fireValueChangedEvent(); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - } - - @Test - public void testExceptionNotPropagatedFromSingleChange() { - helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {throw new RuntimeException();}); - observable.set(null); - helper.fireValueChangedEvent(); - } - - @Test - public void testExceptionNotPropagatedFromMultipleChange() { - BitSet called = new BitSet(); - - helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {called.set(0); throw new RuntimeException();}); - helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {called.set(1); throw new RuntimeException();}); - observable.set(null); - helper.fireValueChangedEvent(); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - } - - @Test - public void testExceptionNotPropagatedFromMultipleChangeAndInvalidation() { - BitSet called = new BitSet(); - - helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {called.set(0); throw new RuntimeException();}); - helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {called.set(1); throw new RuntimeException();}); - helper = ExpressionHelper.addListener(helper, observable, (o) -> {called.set(2); throw new RuntimeException();}); - helper = ExpressionHelper.addListener(helper, observable, (o) -> {called.set(3); throw new RuntimeException();}); - observable.set(null); - helper.fireValueChangedEvent(); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - assertTrue(called.get(2)); - assertTrue(called.get(3)); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInSingleInvalidation() { - AtomicBoolean called = new AtomicBoolean(false); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); - - helper = ExpressionHelper.addListener(helper, observable,(o) -> {throw new RuntimeException();}); - observable.set(null); - helper.fireValueChangedEvent(); - - assertTrue(called.get()); - } - - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleInvalidation() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = ExpressionHelper.addListener(helper, observable, (o) -> {throw new RuntimeException();}); - helper = ExpressionHelper.addListener(helper, observable, (o) -> {throw new RuntimeException();}); - observable.set(null); - helper.fireValueChangedEvent(); - - assertEquals(2, called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInSingleChange() { - AtomicBoolean called = new AtomicBoolean(false); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); - helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {throw new RuntimeException();}); - observable.set(null); - helper.fireValueChangedEvent(); - - assertTrue(called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleChange() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {throw new RuntimeException();}); - helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {throw new RuntimeException();}); - observable.set(null); - helper.fireValueChangedEvent(); - - assertEquals(2, called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleChangeAndInvalidation() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> { throw new RuntimeException();}); - helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> { throw new RuntimeException();}); - helper = ExpressionHelper.addListener(helper, observable, (o) -> { throw new RuntimeException();}); - helper = ExpressionHelper.addListener(helper, observable, (o) -> {throw new RuntimeException();}); - observable.set(null); - helper.fireValueChangedEvent(); - - assertEquals(4, called.get()); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/ExpressionHelperTest.java 2015-08-31 10:22:53.409217856 -0400 @@ -0,0 +1,648 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.ExpressionHelper; +import com.sun.javafx.binding.ExpressionHelperShim; +import javafx.beans.InvalidationListener; +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.Observable; +import test.javafx.beans.WeakInvalidationListenerMock; +import javafx.beans.value.ChangeListener; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.ObservableValueStub; +import test.javafx.beans.value.WeakChangeListenerMock; +import org.junit.Before; +import org.junit.Test; + +import java.util.BitSet; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ExpressionHelperTest { + + private static final Object UNDEFINED = new Object(); + private static final Object DATA_1 = new Object(); + private static final Object DATA_2 = new Object(); + + private ExpressionHelper helper; + private ObservableValueStub observable; + private InvalidationListenerMock[] invalidationListener; + private ChangeListenerMock[] changeListener; + + @Before + public void setUp() { + helper = null; + observable = new ObservableValueStub(DATA_1); + invalidationListener = new InvalidationListenerMock[] { + new InvalidationListenerMock(), new InvalidationListenerMock(), new InvalidationListenerMock(), new InvalidationListenerMock() + }; + changeListener = new ChangeListenerMock[] { + new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED) + }; + } + + @Test (expected = NullPointerException.class) + public void testAddInvalidation_Null_X() { + ExpressionHelper.addListener(helper, null, invalidationListener[0]); + } + + @Test (expected = NullPointerException.class) + public void testAddInvalidation_X_Null() { + ExpressionHelper.addListener(helper, observable, (InvalidationListener) null); + } + + @Test (expected = NullPointerException.class) + public void testRemoveInvalidation_Null() { + ExpressionHelper.removeListener(helper, (InvalidationListener) null); + } + + @Test (expected = NullPointerException.class) + public void testAddChange_Null_X() { + ExpressionHelper.addListener(helper, null, changeListener[0]); + } + + @Test (expected = NullPointerException.class) + public void testAddChange_X_Null() { + ExpressionHelper.addListener(helper, observable, (ChangeListener) null); + } + + @Test (expected = NullPointerException.class) + public void testRemoveChange_Null() { + ExpressionHelper.removeListener(helper, (ChangeListener) null); + } + + @Test + public void testEmptyHelper() { + // all of these calls should be no-ops + ExpressionHelper.removeListener(helper, invalidationListener[0]); + ExpressionHelper.removeListener(helper, changeListener[0]); + ExpressionHelper.fireValueChangedEvent(helper); + } + + @Test + public void testSingeInvalidation() { + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + + helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(null, 0); + + helper = ExpressionHelper.removeListener(helper, changeListener[1]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + + helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(null, 0); + + helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[1].check(observable, DATA_1, DATA_2, 1); + + helper = ExpressionHelper.removeListener(helper, changeListener[1]); + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + + helper = ExpressionHelper.removeListener(helper, invalidationListener[0]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + } + + @Test + public void testSingeChange() { + helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_1, DATA_2, 1); + + helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_2, DATA_1, 1); + invalidationListener[1].check(null, 0); + + helper = ExpressionHelper.removeListener(helper, changeListener[1]); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_1, DATA_2, 1); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_2, DATA_1, 1); + invalidationListener[1].check(observable, 1); + + helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_1, DATA_2, 1); + invalidationListener[1].check(null, 0); + + helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_2, DATA_1, 1); + changeListener[1].check(observable, DATA_2, DATA_1, 1); + + helper = ExpressionHelper.removeListener(helper, changeListener[1]); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_1, DATA_2, 1); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + + helper = ExpressionHelper.removeListener(helper, changeListener[0]); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testAddInvalidation() { + final InvalidationListener weakListener = new WeakInvalidationListenerMock(); + + helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); + helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); + + helper = ExpressionHelper.addListener(helper, observable, weakListener); + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + + helper = ExpressionHelper.addListener(helper, observable, weakListener); + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + + helper = ExpressionHelper.addListener(helper, observable, weakListener); + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[2]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + invalidationListener[2].check(observable, 1); + } + + @Test + public void testRemoveInvalidation() { + helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); + helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); + + helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); + + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); + + helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); + + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[2]); + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); + + helper = ExpressionHelper.removeListener(helper, invalidationListener[0]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].check(observable, 1); + invalidationListener[2].check(observable, 1); + + helper = ExpressionHelper.removeListener(helper, invalidationListener[1]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].check(null, 0); + invalidationListener[2].check(observable, 1); + + helper = ExpressionHelper.removeListener(helper, invalidationListener[2]); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].check(null, 0); + invalidationListener[2].check(null, 0); + } + + @Test + public void testAddInvalidationWhileLocked() { + final ChangeListener addingListener = new ChangeListener() { + int index = 0; + @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { + if (index < invalidationListener.length) { + helper = ExpressionHelper.addListener(helper, ExpressionHelperTest.this.observable, invalidationListener[index++]); + } + } + }; + helper = ExpressionHelper.addListener(helper, observable, addingListener); + helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); + + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + + invalidationListener[0].reset(); + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + + invalidationListener[1].reset(); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + + invalidationListener[2].reset(); + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + invalidationListener[2].check(observable, 1); + + invalidationListener[3].reset(); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + invalidationListener[2].check(observable, 1); + invalidationListener[3].check(observable, 1); + } + + @Test + public void testRemoveInvalidationWhileLocked() { + final ChangeListener removingListener = new ChangeListener() { + int index = 0; + @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { + if (index < invalidationListener.length) { + helper = ExpressionHelper.removeListener(helper, invalidationListener[index++]); + } + } + }; + helper = ExpressionHelper.addListener(helper, observable, removingListener); + helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[2]); + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); + + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].reset(); + invalidationListener[1].check(observable, 1); + invalidationListener[2].check(observable, 1); + + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].reset(); + invalidationListener[2].check(observable, 1); + + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].check(null, 0); + invalidationListener[2].reset(); + + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].check(null, 0); + invalidationListener[2].check(null, 0); + } + + @Test + public void testAddChange() { + final ChangeListener weakListener = new WeakChangeListenerMock(); + + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); + + helper = ExpressionHelper.addListener(helper, observable, weakListener); + helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_1, DATA_2, 1); + + helper = ExpressionHelper.addListener(helper, observable, weakListener); + helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_2, DATA_1, 1); + changeListener[1].check(observable, DATA_2, DATA_1, 1); + + helper = ExpressionHelper.addListener(helper, observable, weakListener); + helper = ExpressionHelper.addListener(helper, observable, changeListener[2]); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_1, DATA_2, 1); + changeListener[1].check(observable, DATA_1, DATA_2, 1); + changeListener[2].check(observable, DATA_1, DATA_2, 1); + } + + @Test + public void testRemoveChange() { + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[1]); + + helper = ExpressionHelper.removeListener(helper, changeListener[1]); + + helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); + + helper = ExpressionHelper.removeListener(helper, changeListener[1]); + + helper = ExpressionHelper.addListener(helper, observable, changeListener[2]); + helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); + + helper = ExpressionHelper.removeListener(helper, changeListener[0]); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].check(observable, DATA_1, DATA_2, 1); + changeListener[2].check(observable, DATA_1, DATA_2, 1); + + helper = ExpressionHelper.removeListener(helper, changeListener[1]); + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[2].check(observable, DATA_2, DATA_1, 1); + + helper = ExpressionHelper.removeListener(helper, changeListener[2]); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[2].check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testAddChangeWhileLocked() { + final InvalidationListener addingListener = new InvalidationListener() { + int index = 0; + @Override public void invalidated(Observable observable) { + if (index < invalidationListener.length) { + helper = ExpressionHelper.addListener(helper, ExpressionHelperTest.this.observable, changeListener[index++]); + } + } + }; + helper = ExpressionHelper.addListener(helper, observable, addingListener); + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); + + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + + changeListener[0].reset(); + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_2, DATA_1, 1); + + changeListener[1].reset(); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_1, DATA_2, 1); + changeListener[1].check(observable, DATA_1, DATA_2, 1); + + changeListener[2].reset(); + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_2, DATA_1, 1); + changeListener[1].check(observable, DATA_2, DATA_1, 1); + changeListener[2].check(observable, DATA_2, DATA_1, 1); + + changeListener[3].reset(); + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, DATA_1, DATA_2, 1); + changeListener[1].check(observable, DATA_1, DATA_2, 1); + changeListener[2].check(observable, DATA_1, DATA_2, 1); + changeListener[3].check(observable, DATA_1, DATA_2, 1); + } + + @Test + public void testRemoveChangeWhileLocked() { + final InvalidationListener removingListener = new InvalidationListener() { + int index = 0; + @Override public void invalidated(Observable observable) { + if (index < invalidationListener.length) { + helper = ExpressionHelper.removeListener(helper, changeListener[index++]); + } + } + }; + helper = ExpressionHelper.addListener(helper, observable, removingListener); + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); + helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); + helper = ExpressionHelper.addListener(helper, observable, changeListener[2]); + helper = ExpressionHelper.addListener(helper, observable, changeListener[1]); + + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].reset(); + changeListener[1].check(observable, DATA_1, DATA_2, 1); + changeListener[2].check(observable, DATA_1, DATA_2, 1); + + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].reset(); + changeListener[2].check(observable, DATA_2, DATA_1, 1); + + observable.set(DATA_2); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[2].reset(); + + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[2].check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testFireValueChangedEvent() { + helper = ExpressionHelper.addListener(helper, observable, invalidationListener[0]); + helper = ExpressionHelper.addListener(helper, observable, changeListener[0]); + + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + + observable.set(null); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(observable, DATA_1, null, 1); + + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + + observable.set(DATA_1); + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(observable, null, DATA_1, 1); + + ExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testExceptionNotPropagatedFromSingleInvalidation() { + helper = ExpressionHelper.addListener(helper, observable,(o) -> {throw new RuntimeException();}); + observable.set(null); + ExpressionHelperShim.fireValueChangedEvent(helper); + } + + @Test + public void testExceptionNotPropagatedFromMultipleInvalidation() { + BitSet called = new BitSet(); + + helper = ExpressionHelper.addListener(helper, observable, (o) -> {called.set(0); throw new RuntimeException();}); + helper = ExpressionHelper.addListener(helper, observable, (o) -> {called.set(1); throw new RuntimeException();}); + observable.set(null); + ExpressionHelperShim.fireValueChangedEvent(helper); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + } + + @Test + public void testExceptionNotPropagatedFromSingleChange() { + helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {throw new RuntimeException();}); + observable.set(null); + ExpressionHelperShim.fireValueChangedEvent(helper); + } + + @Test + public void testExceptionNotPropagatedFromMultipleChange() { + BitSet called = new BitSet(); + + helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {called.set(0); throw new RuntimeException();}); + helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {called.set(1); throw new RuntimeException();}); + observable.set(null); + ExpressionHelperShim.fireValueChangedEvent(helper); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + } + + @Test + public void testExceptionNotPropagatedFromMultipleChangeAndInvalidation() { + BitSet called = new BitSet(); + + helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {called.set(0); throw new RuntimeException();}); + helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {called.set(1); throw new RuntimeException();}); + helper = ExpressionHelper.addListener(helper, observable, (o) -> {called.set(2); throw new RuntimeException();}); + helper = ExpressionHelper.addListener(helper, observable, (o) -> {called.set(3); throw new RuntimeException();}); + observable.set(null); + ExpressionHelperShim.fireValueChangedEvent(helper); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + assertTrue(called.get(2)); + assertTrue(called.get(3)); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInSingleInvalidation() { + AtomicBoolean called = new AtomicBoolean(false); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); + + helper = ExpressionHelper.addListener(helper, observable,(o) -> {throw new RuntimeException();}); + observable.set(null); + ExpressionHelperShim.fireValueChangedEvent(helper); + + assertTrue(called.get()); + } + + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleInvalidation() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = ExpressionHelper.addListener(helper, observable, (o) -> {throw new RuntimeException();}); + helper = ExpressionHelper.addListener(helper, observable, (o) -> {throw new RuntimeException();}); + observable.set(null); + ExpressionHelperShim.fireValueChangedEvent(helper); + + assertEquals(2, called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInSingleChange() { + AtomicBoolean called = new AtomicBoolean(false); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); + helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {throw new RuntimeException();}); + observable.set(null); + ExpressionHelperShim.fireValueChangedEvent(helper); + + assertTrue(called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleChange() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {throw new RuntimeException();}); + helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {throw new RuntimeException();}); + observable.set(null); + ExpressionHelperShim.fireValueChangedEvent(helper); + + assertEquals(2, called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleChangeAndInvalidation() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> { throw new RuntimeException();}); + helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> { throw new RuntimeException();}); + helper = ExpressionHelper.addListener(helper, observable, (o) -> { throw new RuntimeException();}); + helper = ExpressionHelper.addListener(helper, observable, (o) -> {throw new RuntimeException();}); + observable.set(null); + ExpressionHelperShim.fireValueChangedEvent(helper); + + assertEquals(4, called.get()); + } + +} --- old/modules/base/src/test/java/com/sun/javafx/binding/ExpressionHelperUtility.java 2015-08-31 10:22:54.217217847 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,380 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import javafx.beans.InvalidationListener; -import javafx.beans.Observable; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.collections.ListChangeListener; -import javafx.collections.MapChangeListener; -import javafx.collections.ObservableList; -import javafx.collections.ObservableMap; -import javafx.collections.ObservableSet; -import javafx.collections.SetChangeListener; - - -public class ExpressionHelperUtility { - - private static final String EXPRESSION_HELPER_SINGLE_INVALIDATION = "com.sun.javafx.binding.ExpressionHelper$SingleInvalidation"; - private static final String EXPRESSION_HELPER_SINGLE_CHANGE = "com.sun.javafx.binding.ExpressionHelper$SingleChange"; - private static final String EXPRESSION_HELPER_GENERIC = "com.sun.javafx.binding.ExpressionHelper$Generic"; - private static final String LIST_EXPRESSION_HELPER_SINGLE_INVALIDATION = "com.sun.javafx.binding.ListExpressionHelper$SingleInvalidation"; - private static final String LIST_EXPRESSION_HELPER_SINGLE_CHANGE = "com.sun.javafx.binding.ListExpressionHelper$SingleChange"; - private static final String LIST_EXPRESSION_HELPER_SINGLE_LIST_CHANGE = "com.sun.javafx.binding.ListExpressionHelper$SingleListChange"; - private static final String LIST_EXPRESSION_HELPER_GENERIC = "com.sun.javafx.binding.ListExpressionHelper$Generic"; - private static final String MAP_EXPRESSION_HELPER_SINGLE_INVALIDATION = "com.sun.javafx.binding.MapExpressionHelper$SingleInvalidation"; - private static final String MAP_EXPRESSION_HELPER_SINGLE_CHANGE = "com.sun.javafx.binding.MapExpressionHelper$SingleChange"; - private static final String MAP_EXPRESSION_HELPER_SINGLE_MAP_CHANGE = "com.sun.javafx.binding.MapExpressionHelper$SingleMapChange"; - private static final String MAP_EXPRESSION_HELPER_GENERIC = "com.sun.javafx.binding.MapExpressionHelper$Generic"; - private static final String SET_EXPRESSION_HELPER_SINGLE_INVALIDATION = "com.sun.javafx.binding.SetExpressionHelper$SingleInvalidation"; - private static final String SET_EXPRESSION_HELPER_SINGLE_CHANGE = "com.sun.javafx.binding.SetExpressionHelper$SingleChange"; - private static final String SET_EXPRESSION_HELPER_SINGLE_SET_CHANGE = "com.sun.javafx.binding.SetExpressionHelper$SingleSetChange"; - private static final String SET_EXPRESSION_HELPER_GENERIC = "com.sun.javafx.binding.SetExpressionHelper$Generic"; - - private ExpressionHelperUtility() {} - - - public static List getInvalidationListeners(Observable observable) { - final Object helper = getExpressionHelper(observable); - if (helper == null) { - return Collections.emptyList(); - } - final Class helperClass = helper.getClass(); - - try { - final Class clazz = Class.forName(EXPRESSION_HELPER_SINGLE_INVALIDATION); - if (clazz.isAssignableFrom(helperClass)) { - return getInvalidationListenerFromSingleInvalidationClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_SINGLE_INVALIDATION); - if (clazz.isAssignableFrom(helperClass)) { - return getInvalidationListenerFromSingleInvalidationClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_SINGLE_INVALIDATION); - if (clazz.isAssignableFrom(helperClass)) { - return getInvalidationListenerFromSingleInvalidationClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(SET_EXPRESSION_HELPER_SINGLE_INVALIDATION); - if (clazz.isAssignableFrom(helperClass)) { - return getInvalidationListenerFromSingleInvalidationClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - - - try { - final Class clazz = Class.forName(EXPRESSION_HELPER_GENERIC); - if (clazz.isAssignableFrom(helperClass)) { - return getInvalidationListenerFromGenericClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_GENERIC); - if (clazz.isAssignableFrom(helperClass)) { - return getInvalidationListenerFromGenericClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_GENERIC); - if (clazz.isAssignableFrom(helperClass)) { - return getInvalidationListenerFromGenericClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(SET_EXPRESSION_HELPER_GENERIC); - if (clazz.isAssignableFrom(helperClass)) { - return getInvalidationListenerFromGenericClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - return Collections.emptyList(); - } - - public static List> getChangeListeners(ObservableValue observable) { - final Object helper = getExpressionHelper(observable); - if (helper == null) { - return Collections.emptyList(); - } - final Class helperClass = helper.getClass(); - - try { - final Class clazz = Class.forName(EXPRESSION_HELPER_SINGLE_CHANGE); - if (clazz.isAssignableFrom(helperClass)) { - return getChangeListenerFromSingleChangeClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_SINGLE_CHANGE); - if (clazz.isAssignableFrom(helperClass)) { - return getChangeListenerFromSingleChangeClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_SINGLE_CHANGE); - if (clazz.isAssignableFrom(helperClass)) { - return getChangeListenerFromSingleChangeClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(SET_EXPRESSION_HELPER_SINGLE_CHANGE); - if (clazz.isAssignableFrom(helperClass)) { - return getChangeListenerFromSingleChangeClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - - - try { - final Class clazz = Class.forName(EXPRESSION_HELPER_GENERIC); - if (clazz.isAssignableFrom(helperClass)) { - return getChangeListenerFromGenericClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_GENERIC); - if (clazz.isAssignableFrom(helperClass)) { - return getChangeListenerFromGenericClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_GENERIC); - if (clazz.isAssignableFrom(helperClass)) { - return getChangeListenerFromGenericClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(SET_EXPRESSION_HELPER_GENERIC); - if (clazz.isAssignableFrom(helperClass)) { - return getChangeListenerFromGenericClass(clazz, helper); - } - } catch (ClassNotFoundException ex) { } - - return Collections.emptyList(); - } - - public static List> getListChangeListeners(ObservableList observable) { - final Object helper = getExpressionHelper(observable); - if (helper == null) { - return Collections.emptyList(); - } - final Class helperClass = helper.getClass(); - - try { - final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_SINGLE_LIST_CHANGE); - if (clazz.isAssignableFrom(helperClass)) { - try { - final Field field = clazz.getDeclaredField("listener"); - field.setAccessible(true); - final ListChangeListener listener = (ListChangeListener)field.get(helper); - return Arrays.>asList(listener); - } catch (Exception ex) { } - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_GENERIC); - if (clazz.isAssignableFrom(helperClass)) { - try { - final Field field = clazz.getDeclaredField("listChangeListeners"); - field.setAccessible(true); - final ListChangeListener[] listeners = (ListChangeListener[])field.get(helper); - if (listeners != null) { - final Field sizeField = clazz.getDeclaredField("listChangeSize"); - sizeField.setAccessible(true); - final int size = sizeField.getInt(helper); - return Arrays.asList(Arrays.copyOf(listeners, size)); - } - } catch (Exception ex) { } - } - } catch (ClassNotFoundException ex) { } - - return Collections.emptyList(); - } - - public static List> getMapChangeListeners(ObservableMap observable) { - final Object helper = getExpressionHelper(observable); - if (helper == null) { - return Collections.emptyList(); - } - final Class helperClass = helper.getClass(); - - try { - final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_SINGLE_MAP_CHANGE); - if (clazz.isAssignableFrom(helperClass)) { - try { - final Field field = clazz.getDeclaredField("listener"); - field.setAccessible(true); - final MapChangeListener listener = (MapChangeListener)field.get(helper); - return Arrays.>asList(listener); - } catch (Exception ex) { } - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_GENERIC); - if (clazz.isAssignableFrom(helperClass)) { - try { - final Field field = clazz.getDeclaredField("mapChangeListeners"); - field.setAccessible(true); - final MapChangeListener[] listeners = (MapChangeListener[])field.get(helper); - if (listeners != null) { - final Field sizeField = clazz.getDeclaredField("mapChangeSize"); - sizeField.setAccessible(true); - final int size = sizeField.getInt(helper); - return Arrays.asList(Arrays.copyOf(listeners, size)); - } - } catch (Exception ex) { } - } - } catch (ClassNotFoundException ex) { } - - return Collections.emptyList(); - } - - public static List> getSetChangeListeners(ObservableSet observable) { - final Object helper = getExpressionHelper(observable); - if (helper == null) { - return Collections.emptyList(); - } - final Class helperClass = helper.getClass(); - - try { - final Class clazz = Class.forName(SET_EXPRESSION_HELPER_SINGLE_SET_CHANGE); - if (clazz.isAssignableFrom(helperClass)) { - try { - final Field field = clazz.getDeclaredField("listener"); - field.setAccessible(true); - final SetChangeListener listener = (SetChangeListener)field.get(helper); - return Arrays.>asList(listener); - } catch (Exception ex) { } - } - } catch (ClassNotFoundException ex) { } - - try { - final Class clazz = Class.forName(SET_EXPRESSION_HELPER_GENERIC); - if (clazz.isAssignableFrom(helperClass)) { - try { - final Field field = clazz.getDeclaredField("setChangeListeners"); - field.setAccessible(true); - final SetChangeListener[] listeners = (SetChangeListener[])field.get(helper); - if (listeners != null) { - final Field sizeField = clazz.getDeclaredField("setChangeSize"); - sizeField.setAccessible(true); - final int size = sizeField.getInt(helper); - return Arrays.asList(Arrays.copyOf(listeners, size)); - } - } catch (Exception ex) { } - } - } catch (ClassNotFoundException ex) { } - - return Collections.emptyList(); - } - - private static Object getExpressionHelper(Object bean) { - Class clazz = bean.getClass(); - while (clazz != Object.class) { - try { - final Field field = clazz.getDeclaredField("helper"); - field.setAccessible(true); - return field.get(bean); - } catch (Exception ex) { } - clazz = clazz.getSuperclass(); - } - return null; - } - - private static List getInvalidationListenerFromSingleInvalidationClass(Class clazz, Object helper) { - try { - final Field field = clazz.getDeclaredField("listener"); - field.setAccessible(true); - final InvalidationListener listener = (InvalidationListener)field.get(helper); - return Arrays.asList(listener); - } catch (Exception ex) { } - return Collections.emptyList(); - } - - private static List getInvalidationListenerFromGenericClass(Class clazz, Object helper) { - try { - final Field field = clazz.getDeclaredField("invalidationListeners"); - field.setAccessible(true); - final InvalidationListener[] listeners = (InvalidationListener[])field.get(helper); - if (listeners != null) { - final Field sizeField = clazz.getDeclaredField("invalidationSize"); - sizeField.setAccessible(true); - final int size = sizeField.getInt(helper); - return Arrays.asList(Arrays.copyOf(listeners, size)); - } - } catch (Exception ex) { } - return Collections.emptyList(); - } - - private static List> getChangeListenerFromSingleChangeClass(Class clazz, Object helper) { - try { - final Field field = clazz.getDeclaredField("listener"); - field.setAccessible(true); - final ChangeListener listener = (ChangeListener)field.get(helper); - return Arrays.>asList(listener); - } catch (Exception ex) { } - return Collections.emptyList(); - } - - private static List> getChangeListenerFromGenericClass(Class clazz, Object helper) { - try { - final Field field = clazz.getDeclaredField("changeListeners"); - field.setAccessible(true); - final ChangeListener[] listeners = (ChangeListener[])field.get(helper); - if (listeners != null) { - final Field sizeField = clazz.getDeclaredField("changeSize"); - sizeField.setAccessible(true); - final int size = sizeField.getInt(helper); - return Arrays.asList(Arrays.copyOf(listeners, size)); - } - } catch (Exception ex) { } - return Collections.emptyList(); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/ExpressionHelperUtility.java 2015-08-31 10:22:54.085217849 -0400 @@ -0,0 +1,380 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.ListChangeListener; +import javafx.collections.MapChangeListener; +import javafx.collections.ObservableList; +import javafx.collections.ObservableMap; +import javafx.collections.ObservableSet; +import javafx.collections.SetChangeListener; + + +public class ExpressionHelperUtility { + + private static final String EXPRESSION_HELPER_SINGLE_INVALIDATION = "com.sun.javafx.binding.ExpressionHelper$SingleInvalidation"; + private static final String EXPRESSION_HELPER_SINGLE_CHANGE = "com.sun.javafx.binding.ExpressionHelper$SingleChange"; + private static final String EXPRESSION_HELPER_GENERIC = "com.sun.javafx.binding.ExpressionHelper$Generic"; + private static final String LIST_EXPRESSION_HELPER_SINGLE_INVALIDATION = "com.sun.javafx.binding.ListExpressionHelper$SingleInvalidation"; + private static final String LIST_EXPRESSION_HELPER_SINGLE_CHANGE = "com.sun.javafx.binding.ListExpressionHelper$SingleChange"; + private static final String LIST_EXPRESSION_HELPER_SINGLE_LIST_CHANGE = "com.sun.javafx.binding.ListExpressionHelper$SingleListChange"; + private static final String LIST_EXPRESSION_HELPER_GENERIC = "com.sun.javafx.binding.ListExpressionHelper$Generic"; + private static final String MAP_EXPRESSION_HELPER_SINGLE_INVALIDATION = "com.sun.javafx.binding.MapExpressionHelper$SingleInvalidation"; + private static final String MAP_EXPRESSION_HELPER_SINGLE_CHANGE = "com.sun.javafx.binding.MapExpressionHelper$SingleChange"; + private static final String MAP_EXPRESSION_HELPER_SINGLE_MAP_CHANGE = "com.sun.javafx.binding.MapExpressionHelper$SingleMapChange"; + private static final String MAP_EXPRESSION_HELPER_GENERIC = "com.sun.javafx.binding.MapExpressionHelper$Generic"; + private static final String SET_EXPRESSION_HELPER_SINGLE_INVALIDATION = "com.sun.javafx.binding.SetExpressionHelper$SingleInvalidation"; + private static final String SET_EXPRESSION_HELPER_SINGLE_CHANGE = "com.sun.javafx.binding.SetExpressionHelper$SingleChange"; + private static final String SET_EXPRESSION_HELPER_SINGLE_SET_CHANGE = "com.sun.javafx.binding.SetExpressionHelper$SingleSetChange"; + private static final String SET_EXPRESSION_HELPER_GENERIC = "com.sun.javafx.binding.SetExpressionHelper$Generic"; + + private ExpressionHelperUtility() {} + + + public static List getInvalidationListeners(Observable observable) { + final Object helper = getExpressionHelper(observable); + if (helper == null) { + return Collections.emptyList(); + } + final Class helperClass = helper.getClass(); + + try { + final Class clazz = Class.forName(EXPRESSION_HELPER_SINGLE_INVALIDATION); + if (clazz.isAssignableFrom(helperClass)) { + return getInvalidationListenerFromSingleInvalidationClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_SINGLE_INVALIDATION); + if (clazz.isAssignableFrom(helperClass)) { + return getInvalidationListenerFromSingleInvalidationClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_SINGLE_INVALIDATION); + if (clazz.isAssignableFrom(helperClass)) { + return getInvalidationListenerFromSingleInvalidationClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(SET_EXPRESSION_HELPER_SINGLE_INVALIDATION); + if (clazz.isAssignableFrom(helperClass)) { + return getInvalidationListenerFromSingleInvalidationClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + + + try { + final Class clazz = Class.forName(EXPRESSION_HELPER_GENERIC); + if (clazz.isAssignableFrom(helperClass)) { + return getInvalidationListenerFromGenericClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_GENERIC); + if (clazz.isAssignableFrom(helperClass)) { + return getInvalidationListenerFromGenericClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_GENERIC); + if (clazz.isAssignableFrom(helperClass)) { + return getInvalidationListenerFromGenericClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(SET_EXPRESSION_HELPER_GENERIC); + if (clazz.isAssignableFrom(helperClass)) { + return getInvalidationListenerFromGenericClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + return Collections.emptyList(); + } + + public static List> getChangeListeners(ObservableValue observable) { + final Object helper = getExpressionHelper(observable); + if (helper == null) { + return Collections.emptyList(); + } + final Class helperClass = helper.getClass(); + + try { + final Class clazz = Class.forName(EXPRESSION_HELPER_SINGLE_CHANGE); + if (clazz.isAssignableFrom(helperClass)) { + return getChangeListenerFromSingleChangeClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_SINGLE_CHANGE); + if (clazz.isAssignableFrom(helperClass)) { + return getChangeListenerFromSingleChangeClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_SINGLE_CHANGE); + if (clazz.isAssignableFrom(helperClass)) { + return getChangeListenerFromSingleChangeClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(SET_EXPRESSION_HELPER_SINGLE_CHANGE); + if (clazz.isAssignableFrom(helperClass)) { + return getChangeListenerFromSingleChangeClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + + + try { + final Class clazz = Class.forName(EXPRESSION_HELPER_GENERIC); + if (clazz.isAssignableFrom(helperClass)) { + return getChangeListenerFromGenericClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_GENERIC); + if (clazz.isAssignableFrom(helperClass)) { + return getChangeListenerFromGenericClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_GENERIC); + if (clazz.isAssignableFrom(helperClass)) { + return getChangeListenerFromGenericClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(SET_EXPRESSION_HELPER_GENERIC); + if (clazz.isAssignableFrom(helperClass)) { + return getChangeListenerFromGenericClass(clazz, helper); + } + } catch (ClassNotFoundException ex) { } + + return Collections.emptyList(); + } + + public static List> getListChangeListeners(ObservableList observable) { + final Object helper = getExpressionHelper(observable); + if (helper == null) { + return Collections.emptyList(); + } + final Class helperClass = helper.getClass(); + + try { + final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_SINGLE_LIST_CHANGE); + if (clazz.isAssignableFrom(helperClass)) { + try { + final Field field = clazz.getDeclaredField("listener"); + field.setAccessible(true); + final ListChangeListener listener = (ListChangeListener)field.get(helper); + return Arrays.>asList(listener); + } catch (Exception ex) { } + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(LIST_EXPRESSION_HELPER_GENERIC); + if (clazz.isAssignableFrom(helperClass)) { + try { + final Field field = clazz.getDeclaredField("listChangeListeners"); + field.setAccessible(true); + final ListChangeListener[] listeners = (ListChangeListener[])field.get(helper); + if (listeners != null) { + final Field sizeField = clazz.getDeclaredField("listChangeSize"); + sizeField.setAccessible(true); + final int size = sizeField.getInt(helper); + return Arrays.asList(Arrays.copyOf(listeners, size)); + } + } catch (Exception ex) { } + } + } catch (ClassNotFoundException ex) { } + + return Collections.emptyList(); + } + + public static List> getMapChangeListeners(ObservableMap observable) { + final Object helper = getExpressionHelper(observable); + if (helper == null) { + return Collections.emptyList(); + } + final Class helperClass = helper.getClass(); + + try { + final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_SINGLE_MAP_CHANGE); + if (clazz.isAssignableFrom(helperClass)) { + try { + final Field field = clazz.getDeclaredField("listener"); + field.setAccessible(true); + final MapChangeListener listener = (MapChangeListener)field.get(helper); + return Arrays.>asList(listener); + } catch (Exception ex) { } + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(MAP_EXPRESSION_HELPER_GENERIC); + if (clazz.isAssignableFrom(helperClass)) { + try { + final Field field = clazz.getDeclaredField("mapChangeListeners"); + field.setAccessible(true); + final MapChangeListener[] listeners = (MapChangeListener[])field.get(helper); + if (listeners != null) { + final Field sizeField = clazz.getDeclaredField("mapChangeSize"); + sizeField.setAccessible(true); + final int size = sizeField.getInt(helper); + return Arrays.asList(Arrays.copyOf(listeners, size)); + } + } catch (Exception ex) { } + } + } catch (ClassNotFoundException ex) { } + + return Collections.emptyList(); + } + + public static List> getSetChangeListeners(ObservableSet observable) { + final Object helper = getExpressionHelper(observable); + if (helper == null) { + return Collections.emptyList(); + } + final Class helperClass = helper.getClass(); + + try { + final Class clazz = Class.forName(SET_EXPRESSION_HELPER_SINGLE_SET_CHANGE); + if (clazz.isAssignableFrom(helperClass)) { + try { + final Field field = clazz.getDeclaredField("listener"); + field.setAccessible(true); + final SetChangeListener listener = (SetChangeListener)field.get(helper); + return Arrays.>asList(listener); + } catch (Exception ex) { } + } + } catch (ClassNotFoundException ex) { } + + try { + final Class clazz = Class.forName(SET_EXPRESSION_HELPER_GENERIC); + if (clazz.isAssignableFrom(helperClass)) { + try { + final Field field = clazz.getDeclaredField("setChangeListeners"); + field.setAccessible(true); + final SetChangeListener[] listeners = (SetChangeListener[])field.get(helper); + if (listeners != null) { + final Field sizeField = clazz.getDeclaredField("setChangeSize"); + sizeField.setAccessible(true); + final int size = sizeField.getInt(helper); + return Arrays.asList(Arrays.copyOf(listeners, size)); + } + } catch (Exception ex) { } + } + } catch (ClassNotFoundException ex) { } + + return Collections.emptyList(); + } + + private static Object getExpressionHelper(Object bean) { + Class clazz = bean.getClass(); + while (clazz != Object.class) { + try { + final Field field = clazz.getDeclaredField("helper"); + field.setAccessible(true); + return field.get(bean); + } catch (Exception ex) { } + clazz = clazz.getSuperclass(); + } + return null; + } + + private static List getInvalidationListenerFromSingleInvalidationClass(Class clazz, Object helper) { + try { + final Field field = clazz.getDeclaredField("listener"); + field.setAccessible(true); + final InvalidationListener listener = (InvalidationListener)field.get(helper); + return Arrays.asList(listener); + } catch (Exception ex) { } + return Collections.emptyList(); + } + + private static List getInvalidationListenerFromGenericClass(Class clazz, Object helper) { + try { + final Field field = clazz.getDeclaredField("invalidationListeners"); + field.setAccessible(true); + final InvalidationListener[] listeners = (InvalidationListener[])field.get(helper); + if (listeners != null) { + final Field sizeField = clazz.getDeclaredField("invalidationSize"); + sizeField.setAccessible(true); + final int size = sizeField.getInt(helper); + return Arrays.asList(Arrays.copyOf(listeners, size)); + } + } catch (Exception ex) { } + return Collections.emptyList(); + } + + private static List> getChangeListenerFromSingleChangeClass(Class clazz, Object helper) { + try { + final Field field = clazz.getDeclaredField("listener"); + field.setAccessible(true); + final ChangeListener listener = (ChangeListener)field.get(helper); + return Arrays.>asList(listener); + } catch (Exception ex) { } + return Collections.emptyList(); + } + + private static List> getChangeListenerFromGenericClass(Class clazz, Object helper) { + try { + final Field field = clazz.getDeclaredField("changeListeners"); + field.setAccessible(true); + final ChangeListener[] listeners = (ChangeListener[])field.get(helper); + if (listeners != null) { + final Field sizeField = clazz.getDeclaredField("changeSize"); + sizeField.setAccessible(true); + final int size = sizeField.getInt(helper); + return Arrays.asList(Arrays.copyOf(listeners, size)); + } + } catch (Exception ex) { } + return Collections.emptyList(); + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/ExpressionHelperUtilityTest.java 2015-08-31 10:22:54.945217839 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,437 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import java.util.Arrays; -import java.util.Collections; -import javafx.beans.InvalidationListener; -import javafx.beans.Observable; -import javafx.beans.property.SimpleListProperty; -import javafx.beans.property.SimpleMapProperty; -import javafx.beans.property.SimpleSetProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableListValue; -import javafx.beans.value.ObservableMapValue; -import javafx.beans.value.ObservableSetValue; -import javafx.beans.value.ObservableValue; -import javafx.collections.ListChangeListener; -import javafx.collections.MapChangeListener; -import javafx.collections.SetChangeListener; -import org.junit.Test; - -import static org.junit.Assert.*; -import org.junit.Before; - -public class ExpressionHelperUtilityTest { - - private ObservableValue observableValue; - private ObservableListValue observableList; - private ObservableMapValue observableMap; - private ObservableSetValue observableSet; - - private InvalidationListener invalidationListener1; - private InvalidationListener invalidationListener2; - private ChangeListener changeListener1; - private ChangeListener changeListener2; - private ListChangeListener listChangeListener1; - private ListChangeListener listChangeListener2; - private MapChangeListener mapChangeListener1; - private MapChangeListener mapChangeListener2; - private SetChangeListener setChangeListener1; - private SetChangeListener setChangeListener2; - - @Before - public void setUp() { - observableValue = new SimpleStringProperty(); - observableList = new SimpleListProperty(); - observableMap = new SimpleMapProperty(); - observableSet = new SimpleSetProperty(); - - invalidationListener1 = new EmptyInvalidationListener(); - invalidationListener2 = new EmptyInvalidationListener(); - changeListener1 = new EmptyChangeListener(); - changeListener2 = new EmptyChangeListener(); - listChangeListener1 = new EmptyListChangeListener(); - listChangeListener2 = new EmptyListChangeListener(); - mapChangeListener1 = new EmptyMapChangeListener(); - mapChangeListener2 = new EmptyMapChangeListener(); - setChangeListener1 = new EmptySetChangeListener(); - setChangeListener2 = new EmptySetChangeListener(); - } - - @Test - public void testGetInvalidationListenerFromValue() { - // empty helper - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableValue)); - - // SingleInvalidation - observableValue.addListener(invalidationListener1); - assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableValue)); - observableValue.removeListener(invalidationListener1); - - // SingleChange - observableValue.addListener(changeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableValue)); - observableValue.removeListener(changeListener1); - - // Generic - observableValue.addListener(changeListener1); - observableValue.addListener(changeListener2); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableValue)); - observableValue.addListener(invalidationListener1); - assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableValue)); - observableValue.addListener(invalidationListener2); - assertTrue(Arrays.asList(invalidationListener1, invalidationListener2).equals(ExpressionHelperUtility.getInvalidationListeners(observableValue)) - || Arrays.asList(invalidationListener2, invalidationListener1).equals(ExpressionHelperUtility.getInvalidationListeners(observableValue))); - } - - @Test - public void testGetChangeListenerFromValue() { - // empty helper - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableValue)); - - // SingleInvalidation - observableValue.addListener(invalidationListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableValue)); - observableValue.removeListener(invalidationListener1); - - // SingleChange - observableValue.addListener(changeListener1); - assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableValue)); - observableValue.removeListener(changeListener1); - - // Generic - observableValue.addListener(invalidationListener1); - observableValue.addListener(invalidationListener2); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableValue)); - observableValue.addListener(changeListener1); - assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableValue)); - observableValue.addListener(changeListener2); - assertTrue(Arrays.asList(changeListener1, changeListener2).equals(ExpressionHelperUtility.getChangeListeners(observableValue)) - || Arrays.asList(changeListener2, changeListener1).equals(ExpressionHelperUtility.getChangeListeners(observableValue))); - } - - @Test - public void testGetInvalidationListenerFromList() { - // empty helper - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableList)); - - // SingleInvalidation - observableList.addListener(invalidationListener1); - assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableList)); - observableList.removeListener(invalidationListener1); - - // SingleChange - observableList.addListener(changeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableList)); - observableList.removeListener(changeListener1); - - // SingeListChange - observableList.addListener(listChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableList)); - observableList.removeListener(listChangeListener1); - - // Generic - observableList.addListener(changeListener1); - observableList.addListener(listChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableList)); - observableList.addListener(invalidationListener1); - assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableList)); - observableList.addListener(invalidationListener2); - assertTrue(Arrays.asList(invalidationListener1, invalidationListener2).equals(ExpressionHelperUtility.getInvalidationListeners(observableList)) - || Arrays.asList(invalidationListener2, invalidationListener1).equals(ExpressionHelperUtility.getInvalidationListeners(observableList))); - } - - @Test - public void testGetChangeListenerFromList() { - // empty helper - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableList)); - - // SingleInvalidation - observableList.addListener(invalidationListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableList)); - observableList.removeListener(invalidationListener1); - - // SingleChange - observableList.addListener(changeListener1); - assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableList)); - observableList.removeListener(changeListener1); - - // SingeListChange - observableList.addListener(listChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableList)); - observableList.removeListener(listChangeListener1); - - // Generic - observableList.addListener(invalidationListener1); - observableList.addListener(listChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableList)); - observableList.addListener(changeListener1); - assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableList)); - observableList.addListener(changeListener2); - assertTrue(Arrays.asList(changeListener1, changeListener2).equals(ExpressionHelperUtility.getChangeListeners(observableList)) - || Arrays.asList(changeListener2, changeListener1).equals(ExpressionHelperUtility.getChangeListeners(observableList))); - } - - @Test - public void testGetListChangeListenerFromList() { - // empty helper - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getListChangeListeners(observableList)); - - // SingleInvalidation - observableList.addListener(invalidationListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getListChangeListeners(observableList)); - observableList.removeListener(invalidationListener1); - - // SingleChange - observableList.addListener(changeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getListChangeListeners(observableList)); - observableList.removeListener(changeListener1); - - // SingeListChange - observableList.addListener(listChangeListener1); - assertEquals(Collections.singletonList(listChangeListener1), ExpressionHelperUtility.getListChangeListeners(observableList)); - observableList.removeListener(listChangeListener1); - - // Generic - observableList.addListener(invalidationListener1); - observableList.addListener(changeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getListChangeListeners(observableList)); - observableList.addListener(listChangeListener1); - assertEquals(Collections.singletonList(listChangeListener1), ExpressionHelperUtility.getListChangeListeners(observableList)); - observableList.addListener(listChangeListener2); - assertTrue(Arrays.asList(listChangeListener1, listChangeListener2).equals(ExpressionHelperUtility.getListChangeListeners(observableList)) - || Arrays.asList(listChangeListener2, listChangeListener1).equals(ExpressionHelperUtility.getListChangeListeners(observableList))); - } - - @Test - public void testGetInvalidationListenerFromMap() { - // empty helper - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableMap)); - - // SingleInvalidation - observableMap.addListener(invalidationListener1); - assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableMap)); - observableMap.removeListener(invalidationListener1); - - // SingleChange - observableMap.addListener(changeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableMap)); - observableMap.removeListener(changeListener1); - - // SingeMapChange - observableMap.addListener(mapChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableMap)); - observableMap.removeListener(mapChangeListener1); - - // Generic - observableMap.addListener(changeListener1); - observableMap.addListener(mapChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableMap)); - observableMap.addListener(invalidationListener1); - assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableMap)); - observableMap.addListener(invalidationListener2); - assertTrue(Arrays.asList(invalidationListener1, invalidationListener2).equals(ExpressionHelperUtility.getInvalidationListeners(observableMap)) - || Arrays.asList(invalidationListener2, invalidationListener1).equals(ExpressionHelperUtility.getInvalidationListeners(observableMap))); - } - - @Test - public void testGetChangeListenerFromMap() { - // empty helper - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableMap)); - - // SingleInvalidation - observableMap.addListener(invalidationListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableMap)); - observableMap.removeListener(invalidationListener1); - - // SingleChange - observableMap.addListener(changeListener1); - assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableMap)); - observableMap.removeListener(changeListener1); - - // SingeMapChange - observableMap.addListener(mapChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableMap)); - observableMap.removeListener(mapChangeListener1); - - // Generic - observableMap.addListener(invalidationListener1); - observableMap.addListener(mapChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableMap)); - observableMap.addListener(changeListener1); - assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableMap)); - observableMap.addListener(changeListener2); - assertTrue(Arrays.asList(changeListener1, changeListener2).equals(ExpressionHelperUtility.getChangeListeners(observableMap)) - || Arrays.asList(changeListener2, changeListener1).equals(ExpressionHelperUtility.getChangeListeners(observableMap))); - } - - @Test - public void testGetMapChangeListenerFromMap() { - // empty helper - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getMapChangeListeners(observableMap)); - - // SingleInvalidation - observableMap.addListener(invalidationListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getMapChangeListeners(observableMap)); - observableMap.removeListener(invalidationListener1); - - // SingleChange - observableMap.addListener(changeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getMapChangeListeners(observableMap)); - observableMap.removeListener(changeListener1); - - // SingeMapChange - observableMap.addListener(mapChangeListener1); - assertEquals(Collections.singletonList(mapChangeListener1), ExpressionHelperUtility.getMapChangeListeners(observableMap)); - observableMap.removeListener(mapChangeListener1); - - // Generic - observableMap.addListener(invalidationListener1); - observableMap.addListener(changeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getMapChangeListeners(observableMap)); - observableMap.addListener(mapChangeListener1); - assertEquals(Collections.singletonList(mapChangeListener1), ExpressionHelperUtility.getMapChangeListeners(observableMap)); - observableMap.addListener(mapChangeListener2); - assertTrue(Arrays.asList(mapChangeListener1, mapChangeListener2).equals(ExpressionHelperUtility.getMapChangeListeners(observableMap)) - || Arrays.asList(mapChangeListener2, mapChangeListener1).equals(ExpressionHelperUtility.getMapChangeListeners(observableMap))); - } - - @Test - public void testGetInvalidationListenerFromSet() { - // empty helper - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableSet)); - - // SingleInvalidation - observableSet.addListener(invalidationListener1); - assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableSet)); - observableSet.removeListener(invalidationListener1); - - // SingleChange - observableSet.addListener(changeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableSet)); - observableSet.removeListener(changeListener1); - - // SingeSetChange - observableSet.addListener(setChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableSet)); - observableSet.removeListener(setChangeListener1); - - // Generic - observableSet.addListener(changeListener1); - observableSet.addListener(setChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableSet)); - observableSet.addListener(invalidationListener1); - assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableSet)); - observableSet.addListener(invalidationListener2); - assertTrue(Arrays.asList(invalidationListener1, invalidationListener2).equals(ExpressionHelperUtility.getInvalidationListeners(observableSet)) - || Arrays.asList(invalidationListener2, invalidationListener1).equals(ExpressionHelperUtility.getInvalidationListeners(observableSet))); - } - - @Test - public void testGetChangeListenerFromSet() { - // empty helper - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableSet)); - - // SingleInvalidation - observableSet.addListener(invalidationListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableSet)); - observableSet.removeListener(invalidationListener1); - - // SingleChange - observableSet.addListener(changeListener1); - assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableSet)); - observableSet.removeListener(changeListener1); - - // SingeSetChange - observableSet.addListener(setChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableSet)); - observableSet.removeListener(setChangeListener1); - - // Generic - observableSet.addListener(invalidationListener1); - observableSet.addListener(setChangeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableSet)); - observableSet.addListener(changeListener1); - assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableSet)); - observableSet.addListener(changeListener2); - assertTrue(Arrays.asList(changeListener1, changeListener2).equals(ExpressionHelperUtility.getChangeListeners(observableSet)) - || Arrays.asList(changeListener2, changeListener1).equals(ExpressionHelperUtility.getChangeListeners(observableSet))); - } - - @Test - public void testGetSetChangeListenerFromSet() { - // empty helper - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getSetChangeListeners(observableSet)); - - // SingleInvalidation - observableSet.addListener(invalidationListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getSetChangeListeners(observableSet)); - observableSet.removeListener(invalidationListener1); - - // SingleChange - observableSet.addListener(changeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getSetChangeListeners(observableSet)); - observableSet.removeListener(changeListener1); - - // SingeSetChange - observableSet.addListener(setChangeListener1); - assertEquals(Collections.singletonList(setChangeListener1), ExpressionHelperUtility.getSetChangeListeners(observableSet)); - observableSet.removeListener(setChangeListener1); - - // Generic - observableSet.addListener(invalidationListener1); - observableSet.addListener(changeListener1); - assertEquals(Collections.emptyList(), ExpressionHelperUtility.getSetChangeListeners(observableSet)); - observableSet.addListener(setChangeListener1); - assertEquals(Collections.singletonList(setChangeListener1), ExpressionHelperUtility.getSetChangeListeners(observableSet)); - observableSet.addListener(setChangeListener2); - assertTrue(Arrays.asList(setChangeListener1, setChangeListener2).equals(ExpressionHelperUtility.getSetChangeListeners(observableSet)) - || Arrays.asList(setChangeListener2, setChangeListener1).equals(ExpressionHelperUtility.getSetChangeListeners(observableSet))); - } - - private static class EmptyInvalidationListener implements InvalidationListener { - @Override public void invalidated(Observable observable) { } - } - - private static class EmptyChangeListener implements ChangeListener { - @Override public void changed(ObservableValue observableValue, Object oldValue, Object newValue) { } - } - - private static class EmptyListChangeListener implements ListChangeListener { - @Override public void onChanged(Change change) { } - } - - private static class EmptyMapChangeListener implements MapChangeListener { - @Override public void onChanged(Change change) { } - } - - private static class EmptySetChangeListener implements SetChangeListener { - @Override public void onChanged(Change change) { } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/ExpressionHelperUtilityTest.java 2015-08-31 10:22:54.805217841 -0400 @@ -0,0 +1,437 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import java.util.Arrays; +import java.util.Collections; +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; +import javafx.beans.property.SimpleListProperty; +import javafx.beans.property.SimpleMapProperty; +import javafx.beans.property.SimpleSetProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableListValue; +import javafx.beans.value.ObservableMapValue; +import javafx.beans.value.ObservableSetValue; +import javafx.beans.value.ObservableValue; +import javafx.collections.ListChangeListener; +import javafx.collections.MapChangeListener; +import javafx.collections.SetChangeListener; +import org.junit.Test; + +import static org.junit.Assert.*; +import org.junit.Before; + +public class ExpressionHelperUtilityTest { + + private ObservableValue observableValue; + private ObservableListValue observableList; + private ObservableMapValue observableMap; + private ObservableSetValue observableSet; + + private InvalidationListener invalidationListener1; + private InvalidationListener invalidationListener2; + private ChangeListener changeListener1; + private ChangeListener changeListener2; + private ListChangeListener listChangeListener1; + private ListChangeListener listChangeListener2; + private MapChangeListener mapChangeListener1; + private MapChangeListener mapChangeListener2; + private SetChangeListener setChangeListener1; + private SetChangeListener setChangeListener2; + + @Before + public void setUp() { + observableValue = new SimpleStringProperty(); + observableList = new SimpleListProperty(); + observableMap = new SimpleMapProperty(); + observableSet = new SimpleSetProperty(); + + invalidationListener1 = new EmptyInvalidationListener(); + invalidationListener2 = new EmptyInvalidationListener(); + changeListener1 = new EmptyChangeListener(); + changeListener2 = new EmptyChangeListener(); + listChangeListener1 = new EmptyListChangeListener(); + listChangeListener2 = new EmptyListChangeListener(); + mapChangeListener1 = new EmptyMapChangeListener(); + mapChangeListener2 = new EmptyMapChangeListener(); + setChangeListener1 = new EmptySetChangeListener(); + setChangeListener2 = new EmptySetChangeListener(); + } + + @Test + public void testGetInvalidationListenerFromValue() { + // empty helper + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableValue)); + + // SingleInvalidation + observableValue.addListener(invalidationListener1); + assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableValue)); + observableValue.removeListener(invalidationListener1); + + // SingleChange + observableValue.addListener(changeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableValue)); + observableValue.removeListener(changeListener1); + + // Generic + observableValue.addListener(changeListener1); + observableValue.addListener(changeListener2); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableValue)); + observableValue.addListener(invalidationListener1); + assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableValue)); + observableValue.addListener(invalidationListener2); + assertTrue(Arrays.asList(invalidationListener1, invalidationListener2).equals(ExpressionHelperUtility.getInvalidationListeners(observableValue)) + || Arrays.asList(invalidationListener2, invalidationListener1).equals(ExpressionHelperUtility.getInvalidationListeners(observableValue))); + } + + @Test + public void testGetChangeListenerFromValue() { + // empty helper + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableValue)); + + // SingleInvalidation + observableValue.addListener(invalidationListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableValue)); + observableValue.removeListener(invalidationListener1); + + // SingleChange + observableValue.addListener(changeListener1); + assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableValue)); + observableValue.removeListener(changeListener1); + + // Generic + observableValue.addListener(invalidationListener1); + observableValue.addListener(invalidationListener2); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableValue)); + observableValue.addListener(changeListener1); + assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableValue)); + observableValue.addListener(changeListener2); + assertTrue(Arrays.asList(changeListener1, changeListener2).equals(ExpressionHelperUtility.getChangeListeners(observableValue)) + || Arrays.asList(changeListener2, changeListener1).equals(ExpressionHelperUtility.getChangeListeners(observableValue))); + } + + @Test + public void testGetInvalidationListenerFromList() { + // empty helper + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableList)); + + // SingleInvalidation + observableList.addListener(invalidationListener1); + assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableList)); + observableList.removeListener(invalidationListener1); + + // SingleChange + observableList.addListener(changeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableList)); + observableList.removeListener(changeListener1); + + // SingeListChange + observableList.addListener(listChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableList)); + observableList.removeListener(listChangeListener1); + + // Generic + observableList.addListener(changeListener1); + observableList.addListener(listChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableList)); + observableList.addListener(invalidationListener1); + assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableList)); + observableList.addListener(invalidationListener2); + assertTrue(Arrays.asList(invalidationListener1, invalidationListener2).equals(ExpressionHelperUtility.getInvalidationListeners(observableList)) + || Arrays.asList(invalidationListener2, invalidationListener1).equals(ExpressionHelperUtility.getInvalidationListeners(observableList))); + } + + @Test + public void testGetChangeListenerFromList() { + // empty helper + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableList)); + + // SingleInvalidation + observableList.addListener(invalidationListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableList)); + observableList.removeListener(invalidationListener1); + + // SingleChange + observableList.addListener(changeListener1); + assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableList)); + observableList.removeListener(changeListener1); + + // SingeListChange + observableList.addListener(listChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableList)); + observableList.removeListener(listChangeListener1); + + // Generic + observableList.addListener(invalidationListener1); + observableList.addListener(listChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableList)); + observableList.addListener(changeListener1); + assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableList)); + observableList.addListener(changeListener2); + assertTrue(Arrays.asList(changeListener1, changeListener2).equals(ExpressionHelperUtility.getChangeListeners(observableList)) + || Arrays.asList(changeListener2, changeListener1).equals(ExpressionHelperUtility.getChangeListeners(observableList))); + } + + @Test + public void testGetListChangeListenerFromList() { + // empty helper + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getListChangeListeners(observableList)); + + // SingleInvalidation + observableList.addListener(invalidationListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getListChangeListeners(observableList)); + observableList.removeListener(invalidationListener1); + + // SingleChange + observableList.addListener(changeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getListChangeListeners(observableList)); + observableList.removeListener(changeListener1); + + // SingeListChange + observableList.addListener(listChangeListener1); + assertEquals(Collections.singletonList(listChangeListener1), ExpressionHelperUtility.getListChangeListeners(observableList)); + observableList.removeListener(listChangeListener1); + + // Generic + observableList.addListener(invalidationListener1); + observableList.addListener(changeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getListChangeListeners(observableList)); + observableList.addListener(listChangeListener1); + assertEquals(Collections.singletonList(listChangeListener1), ExpressionHelperUtility.getListChangeListeners(observableList)); + observableList.addListener(listChangeListener2); + assertTrue(Arrays.asList(listChangeListener1, listChangeListener2).equals(ExpressionHelperUtility.getListChangeListeners(observableList)) + || Arrays.asList(listChangeListener2, listChangeListener1).equals(ExpressionHelperUtility.getListChangeListeners(observableList))); + } + + @Test + public void testGetInvalidationListenerFromMap() { + // empty helper + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableMap)); + + // SingleInvalidation + observableMap.addListener(invalidationListener1); + assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableMap)); + observableMap.removeListener(invalidationListener1); + + // SingleChange + observableMap.addListener(changeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableMap)); + observableMap.removeListener(changeListener1); + + // SingeMapChange + observableMap.addListener(mapChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableMap)); + observableMap.removeListener(mapChangeListener1); + + // Generic + observableMap.addListener(changeListener1); + observableMap.addListener(mapChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableMap)); + observableMap.addListener(invalidationListener1); + assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableMap)); + observableMap.addListener(invalidationListener2); + assertTrue(Arrays.asList(invalidationListener1, invalidationListener2).equals(ExpressionHelperUtility.getInvalidationListeners(observableMap)) + || Arrays.asList(invalidationListener2, invalidationListener1).equals(ExpressionHelperUtility.getInvalidationListeners(observableMap))); + } + + @Test + public void testGetChangeListenerFromMap() { + // empty helper + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableMap)); + + // SingleInvalidation + observableMap.addListener(invalidationListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableMap)); + observableMap.removeListener(invalidationListener1); + + // SingleChange + observableMap.addListener(changeListener1); + assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableMap)); + observableMap.removeListener(changeListener1); + + // SingeMapChange + observableMap.addListener(mapChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableMap)); + observableMap.removeListener(mapChangeListener1); + + // Generic + observableMap.addListener(invalidationListener1); + observableMap.addListener(mapChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableMap)); + observableMap.addListener(changeListener1); + assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableMap)); + observableMap.addListener(changeListener2); + assertTrue(Arrays.asList(changeListener1, changeListener2).equals(ExpressionHelperUtility.getChangeListeners(observableMap)) + || Arrays.asList(changeListener2, changeListener1).equals(ExpressionHelperUtility.getChangeListeners(observableMap))); + } + + @Test + public void testGetMapChangeListenerFromMap() { + // empty helper + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getMapChangeListeners(observableMap)); + + // SingleInvalidation + observableMap.addListener(invalidationListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getMapChangeListeners(observableMap)); + observableMap.removeListener(invalidationListener1); + + // SingleChange + observableMap.addListener(changeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getMapChangeListeners(observableMap)); + observableMap.removeListener(changeListener1); + + // SingeMapChange + observableMap.addListener(mapChangeListener1); + assertEquals(Collections.singletonList(mapChangeListener1), ExpressionHelperUtility.getMapChangeListeners(observableMap)); + observableMap.removeListener(mapChangeListener1); + + // Generic + observableMap.addListener(invalidationListener1); + observableMap.addListener(changeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getMapChangeListeners(observableMap)); + observableMap.addListener(mapChangeListener1); + assertEquals(Collections.singletonList(mapChangeListener1), ExpressionHelperUtility.getMapChangeListeners(observableMap)); + observableMap.addListener(mapChangeListener2); + assertTrue(Arrays.asList(mapChangeListener1, mapChangeListener2).equals(ExpressionHelperUtility.getMapChangeListeners(observableMap)) + || Arrays.asList(mapChangeListener2, mapChangeListener1).equals(ExpressionHelperUtility.getMapChangeListeners(observableMap))); + } + + @Test + public void testGetInvalidationListenerFromSet() { + // empty helper + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableSet)); + + // SingleInvalidation + observableSet.addListener(invalidationListener1); + assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableSet)); + observableSet.removeListener(invalidationListener1); + + // SingleChange + observableSet.addListener(changeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableSet)); + observableSet.removeListener(changeListener1); + + // SingeSetChange + observableSet.addListener(setChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableSet)); + observableSet.removeListener(setChangeListener1); + + // Generic + observableSet.addListener(changeListener1); + observableSet.addListener(setChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getInvalidationListeners(observableSet)); + observableSet.addListener(invalidationListener1); + assertEquals(Collections.singletonList(invalidationListener1), ExpressionHelperUtility.getInvalidationListeners(observableSet)); + observableSet.addListener(invalidationListener2); + assertTrue(Arrays.asList(invalidationListener1, invalidationListener2).equals(ExpressionHelperUtility.getInvalidationListeners(observableSet)) + || Arrays.asList(invalidationListener2, invalidationListener1).equals(ExpressionHelperUtility.getInvalidationListeners(observableSet))); + } + + @Test + public void testGetChangeListenerFromSet() { + // empty helper + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableSet)); + + // SingleInvalidation + observableSet.addListener(invalidationListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableSet)); + observableSet.removeListener(invalidationListener1); + + // SingleChange + observableSet.addListener(changeListener1); + assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableSet)); + observableSet.removeListener(changeListener1); + + // SingeSetChange + observableSet.addListener(setChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableSet)); + observableSet.removeListener(setChangeListener1); + + // Generic + observableSet.addListener(invalidationListener1); + observableSet.addListener(setChangeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getChangeListeners(observableSet)); + observableSet.addListener(changeListener1); + assertEquals(Collections.singletonList(changeListener1), ExpressionHelperUtility.getChangeListeners(observableSet)); + observableSet.addListener(changeListener2); + assertTrue(Arrays.asList(changeListener1, changeListener2).equals(ExpressionHelperUtility.getChangeListeners(observableSet)) + || Arrays.asList(changeListener2, changeListener1).equals(ExpressionHelperUtility.getChangeListeners(observableSet))); + } + + @Test + public void testGetSetChangeListenerFromSet() { + // empty helper + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getSetChangeListeners(observableSet)); + + // SingleInvalidation + observableSet.addListener(invalidationListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getSetChangeListeners(observableSet)); + observableSet.removeListener(invalidationListener1); + + // SingleChange + observableSet.addListener(changeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getSetChangeListeners(observableSet)); + observableSet.removeListener(changeListener1); + + // SingeSetChange + observableSet.addListener(setChangeListener1); + assertEquals(Collections.singletonList(setChangeListener1), ExpressionHelperUtility.getSetChangeListeners(observableSet)); + observableSet.removeListener(setChangeListener1); + + // Generic + observableSet.addListener(invalidationListener1); + observableSet.addListener(changeListener1); + assertEquals(Collections.emptyList(), ExpressionHelperUtility.getSetChangeListeners(observableSet)); + observableSet.addListener(setChangeListener1); + assertEquals(Collections.singletonList(setChangeListener1), ExpressionHelperUtility.getSetChangeListeners(observableSet)); + observableSet.addListener(setChangeListener2); + assertTrue(Arrays.asList(setChangeListener1, setChangeListener2).equals(ExpressionHelperUtility.getSetChangeListeners(observableSet)) + || Arrays.asList(setChangeListener2, setChangeListener1).equals(ExpressionHelperUtility.getSetChangeListeners(observableSet))); + } + + private static class EmptyInvalidationListener implements InvalidationListener { + @Override public void invalidated(Observable observable) { } + } + + private static class EmptyChangeListener implements ChangeListener { + @Override public void changed(ObservableValue observableValue, Object oldValue, Object newValue) { } + } + + private static class EmptyListChangeListener implements ListChangeListener { + @Override public void onChanged(Change change) { } + } + + private static class EmptyMapChangeListener implements MapChangeListener { + @Override public void onChanged(Change change) { } + } + + private static class EmptySetChangeListener implements SetChangeListener { + @Override public void onChanged(Change change) { } + } + +} --- old/modules/base/src/test/java/com/sun/javafx/binding/ListExpressionHelperTest.java 2015-08-31 10:22:55.625217831 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,902 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import com.sun.javafx.collections.NonIterableChange; -import javafx.beans.InvalidationListener; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.Observable; -import javafx.beans.WeakInvalidationListenerMock; -import javafx.beans.property.ListProperty; -import javafx.beans.property.SimpleListProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableValue; -import javafx.beans.value.ObservableValueStub; -import javafx.beans.value.WeakChangeListenerMock; -import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener; -import javafx.collections.MockListObserver; -import javafx.collections.ObservableList; -import javafx.collections.WeakListChangeListenerMock; -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; - -public class ListExpressionHelperTest { - - private static final ObservableList UNDEFINED = FXCollections.observableArrayList(); - - - private Object listItem; - private ObservableList data1; - private ObservableList data2; - private ObservableList data3; -// private ListChangeListener.Change change_1_2; -// private ListChangeListener.Change change_2_1; - - private ListExpressionHelper helper; - private ListProperty observable; - - private InvalidationListenerMock[] invalidationListener; - private ChangeListenerMock>[] changeListener; - private MockListObserver[] listChangeListener; - - @Before - public void setUp() { - listItem = new Object(); - data1 = FXCollections.observableArrayList(); - data2 = FXCollections.observableArrayList(listItem); - data3 = FXCollections.observableArrayList(listItem); -// change_1_2 = new NonIterableChange.SimpleAddChange(0, 1, data2); -// change_2_1 = new NonIterableChange.SimpleRemovedChange(0, 1, listItem, data1); - helper = null; - observable = new SimpleListProperty(data1); - - invalidationListener = new InvalidationListenerMock[] { - new InvalidationListenerMock(), new InvalidationListenerMock(), new InvalidationListenerMock(), new InvalidationListenerMock() - }; - changeListener = new ChangeListenerMock[] { - new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED) - }; - listChangeListener = new MockListObserver[] { - new MockListObserver(), new MockListObserver(), new MockListObserver(), new MockListObserver() - }; - } - - @Test(expected = NullPointerException.class) - public void testAddInvalidation_Null_X() { - ListExpressionHelper.addListener(null, null, invalidationListener[0]); - } - - @Test(expected = NullPointerException.class) - public void testAddInvalidation_X_Null() { - ListExpressionHelper.addListener(null, observable, (InvalidationListener)null); - } - - @Test(expected = NullPointerException.class) - public void testRemoveInvalidation_Null() { - ListExpressionHelper.removeListener(null, (InvalidationListener) null); - } - - @Test(expected = NullPointerException.class) - public void testAddChange_Null_X() { - ListExpressionHelper.addListener(null, null, changeListener[0]); - } - - @Test(expected = NullPointerException.class) - public void testAddChange_X_Null() { - ListExpressionHelper.addListener(null, observable, (ChangeListener) null); - } - - @Test(expected = NullPointerException.class) - public void testRemoveChange_Null() { - ListExpressionHelper.removeListener(null, (ChangeListener) null); - } - - @Test(expected = NullPointerException.class) - public void testAddListChange_Null_X() { - ListExpressionHelper.addListener(null, null, listChangeListener[0]); - } - - @Test(expected = NullPointerException.class) - public void testAddListChange_X_Null() { - ListExpressionHelper.addListener(null, observable, (ListChangeListener) null); - } - - @Test(expected = NullPointerException.class) - public void testRemoveListChange_Null() { - ListExpressionHelper.removeListener(null, (ListChangeListener) null); - } - - @Test - public void testEmpty() { - final ListChangeListener.Change change = new NonIterableChange.SimpleRemovedChange(0, 1, new Object(), observable); - ListExpressionHelper.removeListener(null, invalidationListener[0]); - ListExpressionHelper.removeListener(null, changeListener[0]); - ListExpressionHelper.removeListener(null, listChangeListener[0]); - ListExpressionHelper.fireValueChangedEvent((ListExpressionHelper)null); - ListExpressionHelper.fireValueChangedEvent(null, change); - } - - @Test - public void testSingleInvalidation() { - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - - data2.remove(0); - ListExpressionHelper.fireValueChangedEvent(helper, new NonIterableChange.SimpleRemovedChange(0, 1, listItem, data2)); - invalidationListener[0].check(observable, 1); - data2.add(listItem); - - observable.set(data3); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(null, 0); - - helper = ListExpressionHelper.removeListener(helper, changeListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - listChangeListener[1].check0(); - - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(null, 0); - - helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[1].check(observable, data1, data2, 1); - - helper = ListExpressionHelper.removeListener(helper, changeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[1].clear(); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - listChangeListener[1].check0(); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[0]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - } - - @Test - public void testSingleChange() { - helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data1, data2, 1); - - data2.remove(0); - ListExpressionHelper.fireValueChangedEvent(helper, new NonIterableChange.SimpleRemovedChange(0, 1, listItem, data2)); - changeListener[0].check(observable, data2, data2, 1); - data2.add(listItem); - - observable.set(data3); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data2, data3, 1); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data2, data1, 1); - invalidationListener[1].check(null, 0); - - helper = ListExpressionHelper.removeListener(helper, changeListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data1, data2, 1); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data2, data1, 1); - listChangeListener[1].check0(); - - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data1, data2, 1); - invalidationListener[1].check(observable, 1); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data2, data1, 1); - invalidationListener[1].check(null, 0); - - helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data1, data2, 1); - changeListener[1].check(observable, data1, data2, 1); - - helper = ListExpressionHelper.removeListener(helper, changeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data2, data1, 1); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data1, data2, 1); - listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[1].clear(); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data2, data1, 1); - listChangeListener[1].check0(); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[0]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data1, data2, 1); - } - - @Test - public void testSingleListChange() { - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[0].clear(); - - data2.remove(0); - ListExpressionHelper.fireValueChangedEvent(helper, new NonIterableChange.SimpleRemovedChange(0, 0, listItem, data2)); - listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[0].clear(); - data2.add(listItem); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[0].clear(); - invalidationListener[1].check(null, 0); - - helper = ListExpressionHelper.removeListener(helper, changeListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[0].clear(); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[0].clear(); - listChangeListener[1].check0(); - - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[0].clear(); - invalidationListener[1].check(observable, 1); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[0].clear(); - invalidationListener[1].check(null, 0); - - helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[0].clear(); - changeListener[1].check(observable, data1, data2, 1); - - helper = ListExpressionHelper.removeListener(helper, changeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[0].clear(); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[0].clear(); - listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[1].clear(); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[0].clear(); - listChangeListener[1].check0(); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[0]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check0(); - } - - @Test - public void testAddInvalidation() { - final InvalidationListener weakListener = new WeakInvalidationListenerMock(); - - helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - - helper = ListExpressionHelper.addListener(helper, observable, weakListener); - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - - helper = ListExpressionHelper.addListener(helper, observable, weakListener); - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - - helper = ListExpressionHelper.addListener(helper, observable, weakListener); - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[2]); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - invalidationListener[2].check(observable, 1); - } - - @Test - public void testRemoveInvalidation() { - helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); - - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); - - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[2]); - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[0]); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].check(observable, 1); - invalidationListener[2].check(observable, 1); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].check(null, 0); - invalidationListener[2].check(observable, 1); - - helper = ListExpressionHelper.removeListener(helper, invalidationListener[2]); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].check(null, 0); - invalidationListener[2].check(null, 0); - } - - @Test - public void testAddInvalidationWhileLocked() { - final ChangeListener addingListener = new ChangeListener() { - int index = 0; - @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { - if (index < invalidationListener.length) { - helper = ListExpressionHelper.addListener(helper, ListExpressionHelperTest.this.observable, invalidationListener[index++]); - } - } - }; - helper = ListExpressionHelper.addListener(helper, observable, addingListener); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - - invalidationListener[0].reset(); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - - invalidationListener[1].reset(); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - - invalidationListener[2].reset(); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - invalidationListener[2].check(observable, 1); - - invalidationListener[3].reset(); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - invalidationListener[1].check(observable, 1); - invalidationListener[2].check(observable, 1); - invalidationListener[3].check(observable, 1); - } - - @Test - public void testRemoveInvalidationWhileLocked() { - final ChangeListener removingListener = new ChangeListener() { - int index = 0; - @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { - if (index < invalidationListener.length) { - helper = ListExpressionHelper.removeListener(helper, invalidationListener[index++]); - } - } - }; - helper = ListExpressionHelper.addListener(helper, observable, removingListener); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[2]); - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); - - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].reset(); - invalidationListener[1].check(observable, 1); - invalidationListener[2].check(observable, 1); - - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].reset(); - invalidationListener[2].check(observable, 1); - - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].check(null, 0); - invalidationListener[2].reset(); - - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(null, 0); - invalidationListener[1].check(null, 0); - invalidationListener[2].check(null, 0); - } - - @Test - public void testAddChange() { - final ChangeListener weakListener = new WeakChangeListenerMock(); - - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - - helper = ListExpressionHelper.addListener(helper, observable, weakListener); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data1, data2, 1); - - helper = ListExpressionHelper.addListener(helper, observable, weakListener); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data2, data1, 1); - changeListener[1].check(observable, data2, data1, 1); - - helper = ListExpressionHelper.addListener(helper, observable, weakListener); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[2]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data1, data2, 1); - changeListener[1].check(observable, data1, data2, 1); - changeListener[2].check(observable, data1, data2, 1); - } - - @Test - public void testRemoveChange() { - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - - helper = ListExpressionHelper.removeListener(helper, changeListener[1]); - - helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); - - helper = ListExpressionHelper.removeListener(helper, changeListener[1]); - - helper = ListExpressionHelper.addListener(helper, observable, changeListener[2]); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); - - helper = ListExpressionHelper.removeListener(helper, changeListener[0]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].check(observable, data1, data2, 1); - changeListener[2].check(observable, data1, data2, 1); - - helper = ListExpressionHelper.removeListener(helper, changeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[2].check(observable, data2, data1, 1); - - helper = ListExpressionHelper.removeListener(helper, changeListener[2]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[2].check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testAddChangeWhileLocked() { - final InvalidationListener addingListener = new InvalidationListener() { - int index = 0; - @Override public void invalidated(Observable observable) { - if (index < invalidationListener.length) { - helper = ListExpressionHelper.addListener(helper, ListExpressionHelperTest.this.observable, changeListener[index++]); - } - } - }; - helper = ListExpressionHelper.addListener(helper, observable, addingListener); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - - changeListener[0].reset(); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data2, data1, 1); - - changeListener[1].reset(); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data1, data2, 1); - changeListener[1].check(observable, data1, data2, 1); - - changeListener[2].reset(); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data2, data1, 1); - changeListener[1].check(observable, data2, data1, 1); - changeListener[2].check(observable, data2, data1, 1); - - changeListener[3].reset(); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(observable, data1, data2, 1); - changeListener[1].check(observable, data1, data2, 1); - changeListener[2].check(observable, data1, data2, 1); - changeListener[3].check(observable, data1, data2, 1); - } - - @Test - public void testRemoveChangeWhileLocked() { - final InvalidationListener removingListener = new InvalidationListener() { - int index = 0; - @Override public void invalidated(Observable observable) { - if (index < invalidationListener.length) { - helper = ListExpressionHelper.removeListener(helper, changeListener[index++]); - } - } - }; - helper = ListExpressionHelper.addListener(helper, observable, removingListener); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[2]); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); - - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].reset(); - changeListener[1].check(observable, data1, data2, 1); - changeListener[2].check(observable, data1, data2, 1); - - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].reset(); - changeListener[2].check(observable, data2, data1, 1); - - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[2].reset(); - - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); - changeListener[2].check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testAddListChange() { - final ChangeListener weakListener = new WeakListChangeListenerMock(); - - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); - - helper = ListExpressionHelper.addListener(helper, observable, weakListener); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[0].clear(); - - helper = ListExpressionHelper.addListener(helper, observable, weakListener); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[0].clear(); - listChangeListener[1].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[1].clear(); - - helper = ListExpressionHelper.addListener(helper, observable, weakListener); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[2]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[0].clear(); - listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[1].clear(); - listChangeListener[2].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[2].clear(); - - helper = ListExpressionHelper.addListener(helper, observable, weakListener); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[3]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[1].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[2].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[3].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - } - - @Test - public void testRemoveListChange() { - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); - - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); - - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[2]); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[0]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check0(); - listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[1].clear(); - listChangeListener[2].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[2].clear(); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check0(); - listChangeListener[1].check0(); - listChangeListener[2].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[2].clear(); - - helper = ListExpressionHelper.removeListener(helper, listChangeListener[2]); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check0(); - listChangeListener[1].check0(); - listChangeListener[2].check0(); - } - - @Test - public void testAddListChangeWhileLocked() { - final InvalidationListener addingListener = new InvalidationListener() { - int index = 0; - @Override public void invalidated(Observable observable) { - if (index < invalidationListener.length) { - helper = ListExpressionHelper.addListener(helper, ListExpressionHelperTest.this.observable, listChangeListener[index++]); - } - } - }; - helper = ListExpressionHelper.addListener(helper, observable, addingListener); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); - - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - - listChangeListener[0].clear(); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[0].clear(); - - listChangeListener[1].clear(); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[0].clear(); - listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[1].clear(); - - listChangeListener[2].clear(); - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[0].clear(); - listChangeListener[1].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[1].clear(); - listChangeListener[2].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - listChangeListener[2].clear(); - - listChangeListener[3].clear(); - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[2].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[3].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - } - - @Test - public void testRemoveListChangeWhileLocked() { - final InvalidationListener removingListener = new InvalidationListener() { - int index = 0; - @Override public void invalidated(Observable observable) { - if (index < invalidationListener.length) { - helper = ListExpressionHelper.removeListener(helper, listChangeListener[index++]); - } - } - }; - helper = ListExpressionHelper.addListener(helper, observable, removingListener); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[2]); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); - - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].clear(); - listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[2].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[2].clear(); - - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check0(); - listChangeListener[1].clear(); - listChangeListener[2].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); - - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check0(); - listChangeListener[1].check0(); - listChangeListener[2].clear(); - - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - listChangeListener[0].check0(); - listChangeListener[1].check0(); - listChangeListener[2].check0(); - } - - - @Test - public void testFireValueChangedEvent() { - helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); - helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); - - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - listChangeListener[0].check0(); - - observable.set(null); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(observable, data1, null, 1); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 0); - listChangeListener[0].clear(); - - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - listChangeListener[0].check0(); - - observable.set(data1); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(observable, null, data1, 1); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 0); - listChangeListener[0].clear(); - - observable.set(data2); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(observable, data1, data2, 1); - listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); - listChangeListener[0].clear(); - - observable.set(data3); - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(observable, data2, data3, 1); - listChangeListener[0].check1AddRemove(observable, Arrays.asList(listItem), 0, 1); - listChangeListener[0].clear(); - - ListExpressionHelper.fireValueChangedEvent(helper); - invalidationListener[0].check(observable, 1); - changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); - listChangeListener[0].check0(); - - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/ListExpressionHelperTest.java 2015-08-31 10:22:55.493217833 -0400 @@ -0,0 +1,903 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.ListExpressionHelper; +import com.sun.javafx.collections.NonIterableChange; +import javafx.beans.InvalidationListener; +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.Observable; +import test.javafx.beans.WeakInvalidationListenerMock; +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.beans.value.ChangeListener; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.ObservableValueStub; +import test.javafx.beans.value.WeakChangeListenerMock; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; +import test.javafx.collections.MockListObserver; +import javafx.collections.ObservableList; +import test.javafx.collections.WeakListChangeListenerMock; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; + +public class ListExpressionHelperTest { + + private static final ObservableList UNDEFINED = FXCollections.observableArrayList(); + + + private Object listItem; + private ObservableList data1; + private ObservableList data2; + private ObservableList data3; +// private ListChangeListener.Change change_1_2; +// private ListChangeListener.Change change_2_1; + + private ListExpressionHelper helper; + private ListProperty observable; + + private InvalidationListenerMock[] invalidationListener; + private ChangeListenerMock>[] changeListener; + private MockListObserver[] listChangeListener; + + @Before + public void setUp() { + listItem = new Object(); + data1 = FXCollections.observableArrayList(); + data2 = FXCollections.observableArrayList(listItem); + data3 = FXCollections.observableArrayList(listItem); +// change_1_2 = new NonIterableChange.SimpleAddChange(0, 1, data2); +// change_2_1 = new NonIterableChange.SimpleRemovedChange(0, 1, listItem, data1); + helper = null; + observable = new SimpleListProperty(data1); + + invalidationListener = new InvalidationListenerMock[] { + new InvalidationListenerMock(), new InvalidationListenerMock(), new InvalidationListenerMock(), new InvalidationListenerMock() + }; + changeListener = new ChangeListenerMock[] { + new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED), new ChangeListenerMock(UNDEFINED) + }; + listChangeListener = new MockListObserver[] { + new MockListObserver(), new MockListObserver(), new MockListObserver(), new MockListObserver() + }; + } + + @Test(expected = NullPointerException.class) + public void testAddInvalidation_Null_X() { + ListExpressionHelper.addListener(null, null, invalidationListener[0]); + } + + @Test(expected = NullPointerException.class) + public void testAddInvalidation_X_Null() { + ListExpressionHelper.addListener(null, observable, (InvalidationListener)null); + } + + @Test(expected = NullPointerException.class) + public void testRemoveInvalidation_Null() { + ListExpressionHelper.removeListener(null, (InvalidationListener) null); + } + + @Test(expected = NullPointerException.class) + public void testAddChange_Null_X() { + ListExpressionHelper.addListener(null, null, changeListener[0]); + } + + @Test(expected = NullPointerException.class) + public void testAddChange_X_Null() { + ListExpressionHelper.addListener(null, observable, (ChangeListener) null); + } + + @Test(expected = NullPointerException.class) + public void testRemoveChange_Null() { + ListExpressionHelper.removeListener(null, (ChangeListener) null); + } + + @Test(expected = NullPointerException.class) + public void testAddListChange_Null_X() { + ListExpressionHelper.addListener(null, null, listChangeListener[0]); + } + + @Test(expected = NullPointerException.class) + public void testAddListChange_X_Null() { + ListExpressionHelper.addListener(null, observable, (ListChangeListener) null); + } + + @Test(expected = NullPointerException.class) + public void testRemoveListChange_Null() { + ListExpressionHelper.removeListener(null, (ListChangeListener) null); + } + + @Test + public void testEmpty() { + final ListChangeListener.Change change = new NonIterableChange.SimpleRemovedChange(0, 1, new Object(), observable); + ListExpressionHelper.removeListener(null, invalidationListener[0]); + ListExpressionHelper.removeListener(null, changeListener[0]); + ListExpressionHelper.removeListener(null, listChangeListener[0]); + ListExpressionHelper.fireValueChangedEvent((ListExpressionHelper)null); + ListExpressionHelper.fireValueChangedEvent(null, change); + } + + @Test + public void testSingleInvalidation() { + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + + data2.remove(0); + ListExpressionHelper.fireValueChangedEvent(helper, new NonIterableChange.SimpleRemovedChange(0, 1, listItem, data2)); + invalidationListener[0].check(observable, 1); + data2.add(listItem); + + observable.set(data3); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(null, 0); + + helper = ListExpressionHelper.removeListener(helper, changeListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + listChangeListener[1].check0(); + + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(null, 0); + + helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[1].check(observable, data1, data2, 1); + + helper = ListExpressionHelper.removeListener(helper, changeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[1].clear(); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + listChangeListener[1].check0(); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[0]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + } + + @Test + public void testSingleChange() { + helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data1, data2, 1); + + data2.remove(0); + ListExpressionHelper.fireValueChangedEvent(helper, new NonIterableChange.SimpleRemovedChange(0, 1, listItem, data2)); + changeListener[0].check(observable, data2, data2, 1); + data2.add(listItem); + + observable.set(data3); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data2, data3, 1); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data2, data1, 1); + invalidationListener[1].check(null, 0); + + helper = ListExpressionHelper.removeListener(helper, changeListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data1, data2, 1); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data2, data1, 1); + listChangeListener[1].check0(); + + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data1, data2, 1); + invalidationListener[1].check(observable, 1); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data2, data1, 1); + invalidationListener[1].check(null, 0); + + helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data1, data2, 1); + changeListener[1].check(observable, data1, data2, 1); + + helper = ListExpressionHelper.removeListener(helper, changeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data2, data1, 1); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data1, data2, 1); + listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[1].clear(); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data2, data1, 1); + listChangeListener[1].check0(); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[0]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data1, data2, 1); + } + + @Test + public void testSingleListChange() { + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[0].clear(); + + data2.remove(0); + ListExpressionHelper.fireValueChangedEvent(helper, new NonIterableChange.SimpleRemovedChange(0, 0, listItem, data2)); + listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[0].clear(); + data2.add(listItem); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[0].clear(); + invalidationListener[1].check(null, 0); + + helper = ListExpressionHelper.removeListener(helper, changeListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[0].clear(); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[0].clear(); + listChangeListener[1].check0(); + + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[0].clear(); + invalidationListener[1].check(observable, 1); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[0].clear(); + invalidationListener[1].check(null, 0); + + helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[0].clear(); + changeListener[1].check(observable, data1, data2, 1); + + helper = ListExpressionHelper.removeListener(helper, changeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[0].clear(); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[0].clear(); + listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[1].clear(); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[0].clear(); + listChangeListener[1].check0(); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[0]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check0(); + } + + @Test + public void testAddInvalidation() { + final InvalidationListener weakListener = new WeakInvalidationListenerMock(); + + helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + + helper = ListExpressionHelper.addListener(helper, observable, weakListener); + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + + helper = ListExpressionHelper.addListener(helper, observable, weakListener); + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + + helper = ListExpressionHelper.addListener(helper, observable, weakListener); + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[2]); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + invalidationListener[2].check(observable, 1); + } + + @Test + public void testRemoveInvalidation() { + helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); + + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); + + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[2]); + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[0]); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].check(observable, 1); + invalidationListener[2].check(observable, 1); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[1]); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].check(null, 0); + invalidationListener[2].check(observable, 1); + + helper = ListExpressionHelper.removeListener(helper, invalidationListener[2]); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].check(null, 0); + invalidationListener[2].check(null, 0); + } + + @Test + public void testAddInvalidationWhileLocked() { + final ChangeListener addingListener = new ChangeListener() { + int index = 0; + @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { + if (index < invalidationListener.length) { + helper = ListExpressionHelper.addListener(helper, ListExpressionHelperTest.this.observable, invalidationListener[index++]); + } + } + }; + helper = ListExpressionHelper.addListener(helper, observable, addingListener); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + + invalidationListener[0].reset(); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + + invalidationListener[1].reset(); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + + invalidationListener[2].reset(); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + invalidationListener[2].check(observable, 1); + + invalidationListener[3].reset(); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + invalidationListener[1].check(observable, 1); + invalidationListener[2].check(observable, 1); + invalidationListener[3].check(observable, 1); + } + + @Test + public void testRemoveInvalidationWhileLocked() { + final ChangeListener removingListener = new ChangeListener() { + int index = 0; + @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { + if (index < invalidationListener.length) { + helper = ListExpressionHelper.removeListener(helper, invalidationListener[index++]); + } + } + }; + helper = ListExpressionHelper.addListener(helper, observable, removingListener); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[2]); + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[1]); + + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].reset(); + invalidationListener[1].check(observable, 1); + invalidationListener[2].check(observable, 1); + + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].reset(); + invalidationListener[2].check(observable, 1); + + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].check(null, 0); + invalidationListener[2].reset(); + + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(null, 0); + invalidationListener[1].check(null, 0); + invalidationListener[2].check(null, 0); + } + + @Test + public void testAddChange() { + final ChangeListener weakListener = new WeakChangeListenerMock(); + + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + + helper = ListExpressionHelper.addListener(helper, observable, weakListener); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data1, data2, 1); + + helper = ListExpressionHelper.addListener(helper, observable, weakListener); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data2, data1, 1); + changeListener[1].check(observable, data2, data1, 1); + + helper = ListExpressionHelper.addListener(helper, observable, weakListener); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[2]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data1, data2, 1); + changeListener[1].check(observable, data1, data2, 1); + changeListener[2].check(observable, data1, data2, 1); + } + + @Test + public void testRemoveChange() { + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + + helper = ListExpressionHelper.removeListener(helper, changeListener[1]); + + helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); + + helper = ListExpressionHelper.removeListener(helper, changeListener[1]); + + helper = ListExpressionHelper.addListener(helper, observable, changeListener[2]); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); + + helper = ListExpressionHelper.removeListener(helper, changeListener[0]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].check(observable, data1, data2, 1); + changeListener[2].check(observable, data1, data2, 1); + + helper = ListExpressionHelper.removeListener(helper, changeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[2].check(observable, data2, data1, 1); + + helper = ListExpressionHelper.removeListener(helper, changeListener[2]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[2].check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testAddChangeWhileLocked() { + final InvalidationListener addingListener = new InvalidationListener() { + int index = 0; + @Override public void invalidated(Observable observable) { + if (index < invalidationListener.length) { + helper = ListExpressionHelper.addListener(helper, ListExpressionHelperTest.this.observable, changeListener[index++]); + } + } + }; + helper = ListExpressionHelper.addListener(helper, observable, addingListener); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + + changeListener[0].reset(); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data2, data1, 1); + + changeListener[1].reset(); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data1, data2, 1); + changeListener[1].check(observable, data1, data2, 1); + + changeListener[2].reset(); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data2, data1, 1); + changeListener[1].check(observable, data2, data1, 1); + changeListener[2].check(observable, data2, data1, 1); + + changeListener[3].reset(); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(observable, data1, data2, 1); + changeListener[1].check(observable, data1, data2, 1); + changeListener[2].check(observable, data1, data2, 1); + changeListener[3].check(observable, data1, data2, 1); + } + + @Test + public void testRemoveChangeWhileLocked() { + final InvalidationListener removingListener = new InvalidationListener() { + int index = 0; + @Override public void invalidated(Observable observable) { + if (index < invalidationListener.length) { + helper = ListExpressionHelper.removeListener(helper, changeListener[index++]); + } + } + }; + helper = ListExpressionHelper.addListener(helper, observable, removingListener); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[2]); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[1]); + + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].reset(); + changeListener[1].check(observable, data1, data2, 1); + changeListener[2].check(observable, data1, data2, 1); + + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].reset(); + changeListener[2].check(observable, data2, data1, 1); + + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[2].reset(); + + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[1].check(null, UNDEFINED, UNDEFINED, 0); + changeListener[2].check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testAddListChange() { + final ChangeListener weakListener = new WeakListChangeListenerMock(); + + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); + + helper = ListExpressionHelper.addListener(helper, observable, weakListener); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[0].clear(); + + helper = ListExpressionHelper.addListener(helper, observable, weakListener); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[0].clear(); + listChangeListener[1].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[1].clear(); + + helper = ListExpressionHelper.addListener(helper, observable, weakListener); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[2]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[0].clear(); + listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[1].clear(); + listChangeListener[2].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[2].clear(); + + helper = ListExpressionHelper.addListener(helper, observable, weakListener); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[3]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[1].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[2].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[3].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + } + + @Test + public void testRemoveListChange() { + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); + + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); + + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[2]); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[0]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check0(); + listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[1].clear(); + listChangeListener[2].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[2].clear(); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[1]); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check0(); + listChangeListener[1].check0(); + listChangeListener[2].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[2].clear(); + + helper = ListExpressionHelper.removeListener(helper, listChangeListener[2]); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check0(); + listChangeListener[1].check0(); + listChangeListener[2].check0(); + } + + @Test + public void testAddListChangeWhileLocked() { + final InvalidationListener addingListener = new InvalidationListener() { + int index = 0; + @Override public void invalidated(Observable observable) { + if (index < invalidationListener.length) { + helper = ListExpressionHelper.addListener(helper, ListExpressionHelperTest.this.observable, listChangeListener[index++]); + } + } + }; + helper = ListExpressionHelper.addListener(helper, observable, addingListener); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); + + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + + listChangeListener[0].clear(); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[0].clear(); + + listChangeListener[1].clear(); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[0].clear(); + listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[1].clear(); + + listChangeListener[2].clear(); + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[0].clear(); + listChangeListener[1].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[1].clear(); + listChangeListener[2].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + listChangeListener[2].clear(); + + listChangeListener[3].clear(); + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[2].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[3].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + } + + @Test + public void testRemoveListChangeWhileLocked() { + final InvalidationListener removingListener = new InvalidationListener() { + int index = 0; + @Override public void invalidated(Observable observable) { + if (index < invalidationListener.length) { + helper = ListExpressionHelper.removeListener(helper, listChangeListener[index++]); + } + } + }; + helper = ListExpressionHelper.addListener(helper, observable, removingListener); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[2]); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[1]); + + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].clear(); + listChangeListener[1].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[2].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[2].clear(); + + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check0(); + listChangeListener[1].clear(); + listChangeListener[2].check1AddRemove(observable, FXCollections.singletonObservableList(listItem), 0, 0); + + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check0(); + listChangeListener[1].check0(); + listChangeListener[2].clear(); + + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + listChangeListener[0].check0(); + listChangeListener[1].check0(); + listChangeListener[2].check0(); + } + + + @Test + public void testFireValueChangedEvent() { + helper = ListExpressionHelper.addListener(helper, observable, invalidationListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, changeListener[0]); + helper = ListExpressionHelper.addListener(helper, observable, listChangeListener[0]); + + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + listChangeListener[0].check0(); + + observable.set(null); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(observable, data1, null, 1); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 0); + listChangeListener[0].clear(); + + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + listChangeListener[0].check0(); + + observable.set(data1); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(observable, null, data1, 1); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 0); + listChangeListener[0].clear(); + + observable.set(data2); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(observable, data1, data2, 1); + listChangeListener[0].check1AddRemove(observable, FXCollections.emptyObservableList(), 0, 1); + listChangeListener[0].clear(); + + observable.set(data3); + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(observable, data2, data3, 1); + listChangeListener[0].check1AddRemove(observable, Arrays.asList(listItem), 0, 1); + listChangeListener[0].clear(); + + ListExpressionHelper.fireValueChangedEvent(helper); + invalidationListener[0].check(observable, 1); + changeListener[0].check(null, UNDEFINED, UNDEFINED, 0); + listChangeListener[0].check0(); + + + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/SelectBindingTest.java 2015-08-31 10:22:56.253217824 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,655 +0,0 @@ -/* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.javafx.binding; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Random; -import javafx.beans.Person; -import javafx.beans.binding.Bindings; -import javafx.beans.binding.BooleanBinding; -import javafx.beans.binding.DoubleBinding; -import javafx.beans.binding.FloatBinding; -import javafx.beans.binding.IntegerBinding; -import javafx.beans.binding.LongBinding; -import javafx.beans.binding.ObjectBinding; -import javafx.beans.binding.StringBinding; -import javafx.binding.Variable; -import javafx.collections.ObservableList; -import sun.util.logging.PlatformLogger.Level; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class SelectBindingTest { - - private static final double EPSILON_DOUBLE = 1e-12; - private static final float EPSILON_FLOAT = 1e-6f; - - public static class POJOPerson { - - private String name; - - public String getName() { - return name; - } - - public POJOPerson() { - } - - public POJOPerson(String name) { - this.name = name; - } - - } - - public static class POJONext { - - private Object next; - private PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - public Object getNext() { - return next; - } - - public void setNext(Object next) { - Object old = this.next; - this.next = next; - pcs.firePropertyChange("next", old, next); - } - - public void addPropertyChangeListener(String property, PropertyChangeListener pcl) { - pcs.addPropertyChangeListener(property, pcl); - } - - public void removePropertyChangeListener(String property, PropertyChangeListener pcl) { - pcs.removePropertyChangeListener(property, pcl); - } - - } - - private Variable a; - private Variable b; - private Variable c; - private Variable d; - private StringBinding select; - private ObservableList dependencies; - - private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); - - @BeforeClass - public static void setUpClass() { - log.start(); - } - - @AfterClass - public static void tearDownClass() { - log.stop(); - } - - @Before - public void setUp() throws Exception { - a = new Variable("a"); - b = new Variable("b"); - c = new Variable("c"); - d = new Variable("d"); - a.setNext(b); - b.setNext(c); - select = Bindings.selectString(a.nextProperty(), "next", "name"); - dependencies = select.getDependencies(); - } - - @Test - public void testObject() { - final Person person1 = new Person(); - final Person person2 = new Person(); - c.setNext(person1); - final ObjectBinding objectBinding = Bindings.select(a.nextProperty(), "next", "next"); - assertEquals(person1, objectBinding.get()); - c.setNext(person2); - assertEquals(person2, objectBinding.get()); - b.setNext(null); - assertEquals(null, objectBinding.get()); - log.checkFine(NullPointerException.class); - } - - @Test - public void testPOJOObject() { - POJONext pojoA = new POJONext(); - pojoA.setNext(b); - final Person person1 = new Person(); - final Person person2 = new Person(); - c.setNext(person1); - final ObjectBinding objectBinding = Bindings.select(pojoA, "next", "next", "next"); - assertEquals(person1, objectBinding.get()); - c.setNext(person2); - assertEquals(person2, objectBinding.get()); - } - - @Test - public void testPOJOObject_2() { - POJONext pojoC = new POJONext(); - b.setNext(pojoC); - final Person person1 = new Person(); - final Person person2 = new Person(); - pojoC.setNext(person1); - final ObjectBinding objectBinding = Bindings.select(a.nextProperty(), "next", "next"); - assertEquals(person1, objectBinding.get()); - pojoC.setNext(person2); - assertEquals(person2, objectBinding.get()); - } - - @Test - public void testPOJOObject_3() { - final POJOPerson person1 = new POJOPerson("P1"); - final POJOPerson person2 = new POJOPerson("P2"); - c.setNext(person1); - final ObjectBinding objectBinding = Bindings.select(a.nextProperty(), "next", "next", "name"); - assertEquals("P1", objectBinding.get()); - c.setNext(person2); - assertEquals("P2", objectBinding.get()); - b.setNext(null); - assertEquals(null, objectBinding.get()); - log.checkFine(NullPointerException.class); - } - - @Test - public void testPOJOBoolean() { - - POJONext pojoA = new POJONext(); - pojoA.setNext(b); - - final Person person = new Person(); - b.setNext(person); - final BooleanBinding binding1 = Bindings.selectBoolean(pojoA, "next", "next", "retired"); - assertEquals(false, binding1.get()); - person.setRetired(true); - assertEquals(true, binding1.get()); - } - - @Test - public void testBoolean() { - - final Person person = new Person(); - b.setNext(person); - final BooleanBinding binding1 = Bindings.selectBoolean(a.nextProperty(), "next", "retired"); - assertEquals(false, binding1.get()); - person.setRetired(true); - assertEquals(true, binding1.get()); - b.setNext(null); - assertEquals(false, binding1.get()); - log.checkFine(NullPointerException.class); - - person.setData(false); - b.setNext(person); - final BooleanBinding binding2 = Bindings.selectBoolean(a.nextProperty(), "next", "data"); - assertEquals(false, binding2.get()); - person.setData(true); - assertEquals(true, binding2.get()); - person.setData(null); - assertEquals(false, binding2.get()); - log.checkFine(NullPointerException.class); - b.setNext(null); - assertEquals(false, binding2.get()); - log.checkFine(NullPointerException.class); - } - - @Test - public void testPOJODouble() { - POJONext pojoA = new POJONext(); - pojoA.setNext(b); - - final Person person = new Person(); - person.setSomething(-Math.E); - b.setNext(person); - final DoubleBinding binding1 = Bindings.selectDouble(pojoA, "next", "next", "something"); - assertEquals(-Math.E, binding1.get(), EPSILON_DOUBLE); - person.setSomething(Math.PI); - assertEquals(Math.PI, binding1.get(), EPSILON_DOUBLE); - } - - @Test - public void testDouble() { - - final Person person = new Person(); - person.setSomething(-Math.E); - b.setNext(person); - final DoubleBinding binding1 = Bindings.selectDouble(a.nextProperty(), "next", "something"); - assertEquals(-Math.E, binding1.get(), EPSILON_DOUBLE); - person.setSomething(Math.PI); - assertEquals(Math.PI, binding1.get(), EPSILON_DOUBLE); - b.setNext(null); - assertEquals(0.0, binding1.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - - person.setData(-Math.E); - b.setNext(person); - final DoubleBinding binding2 = Bindings.selectDouble(a.nextProperty(), "next", "data"); - assertEquals(-Math.E, binding2.get(), EPSILON_DOUBLE); - person.setData(Math.PI); - assertEquals(Math.PI, binding2.get(), EPSILON_DOUBLE); - person.setData(null); - assertEquals(0.0, binding2.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - b.setNext(null); - assertEquals(0.0, binding2.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - } - - @Test - public void testPOJOFloat() { - POJONext pojoA = new POJONext(); - pojoA.setNext(b); - - final Person person = new Person(); - person.setMiles((float) -Math.E); - b.setNext(person); - final FloatBinding binding1 = Bindings.selectFloat(pojoA, "next", "next", "miles"); - assertEquals((float) -Math.E, binding1.get(), EPSILON_FLOAT); - person.setMiles((float) Math.PI); - assertEquals((float) Math.PI, binding1.get(), EPSILON_FLOAT); - } - - @Test - public void testFloat() { - - final Person person = new Person(); - person.setMiles((float) -Math.E); - b.setNext(person); - final FloatBinding binding1 = Bindings.selectFloat(a.nextProperty(), "next", "miles"); - assertEquals((float) -Math.E, binding1.get(), EPSILON_FLOAT); - person.setMiles((float) Math.PI); - assertEquals((float) Math.PI, binding1.get(), EPSILON_FLOAT); - b.setNext(null); - assertEquals(0.0f, binding1.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - - person.setData((float) -Math.E); - b.setNext(person); - final FloatBinding binding2 = Bindings.selectFloat(a.nextProperty(), "next", "data"); - assertEquals((float) -Math.E, binding2.get(), EPSILON_FLOAT); - person.setData((float) Math.PI); - assertEquals((float) Math.PI, binding2.get(), EPSILON_FLOAT); - person.setData(null); - assertEquals(0.0f, binding2.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - b.setNext(null); - assertEquals(0.0f, binding2.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - } - - @Test - public void testPOJOInteger() { - - POJONext pojoA = new POJONext(); - pojoA.setNext(b); - - final Person person = new Person(); - person.setAge(42); - b.setNext(person); - final IntegerBinding binding1 = Bindings.selectInteger(pojoA, "next", "next", "age"); - assertEquals(42, binding1.get()); - person.setAge(-18); - assertEquals(-18, binding1.get()); - } - - @Test - public void testInteger() { - - final Person person = new Person(); - person.setAge(42); - b.setNext(person); - final IntegerBinding binding1 = Bindings.selectInteger(a.nextProperty(), "next", "age"); - assertEquals(42, binding1.get()); - person.setAge(-18); - assertEquals(-18, binding1.get()); - b.setNext(null); - assertEquals(0, binding1.get()); - log.checkFine(NullPointerException.class); - - person.setData(42); - b.setNext(person); - final IntegerBinding binding2 = Bindings.selectInteger(a.nextProperty(), "next", "data"); - assertEquals(42, binding2.get()); - person.setData(-18); - assertEquals(-18, binding2.get()); - person.setData(null); - assertEquals(0, binding2.get()); - log.checkFine(NullPointerException.class); - b.setNext(null); - assertEquals(0, binding2.get()); - log.checkFine(NullPointerException.class); - } - - @Test - public void testPOJOLong() { - POJONext pojoA = new POJONext(); - pojoA.setNext(b); - final Person person = new Person(); - person.setIncome(1234567890987654321L); - b.setNext(person); - final LongBinding binding1 = Bindings.selectLong(pojoA, "next", "next", "income"); - assertEquals(1234567890987654321L, binding1.get()); - person.setIncome(-987654321234567890L); - assertEquals(-987654321234567890L, binding1.get()); - } - - @Test - public void testLong() { - final Person person = new Person(); - person.setIncome(1234567890987654321L); - b.setNext(person); - final LongBinding binding1 = Bindings.selectLong(a.nextProperty(), "next", "income"); - assertEquals(1234567890987654321L, binding1.get()); - person.setIncome(-987654321234567890L); - assertEquals(-987654321234567890L, binding1.get()); - b.setNext(null); - assertEquals(0L, binding1.get()); - log.checkFine(NullPointerException.class); - - person.setData(1234567890987654321L); - b.setNext(person); - final LongBinding binding2 = Bindings.selectLong(a.nextProperty(), "next", "data"); - assertEquals(1234567890987654321L, binding2.get()); - person.setData(-987654321234567890L); - assertEquals(-987654321234567890L, binding2.get()); - person.setData(null); - assertEquals(0L, binding2.get()); - log.checkFine(NullPointerException.class); - b.setNext(null); - assertEquals(0L, binding2.get()); - log.checkFine(NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void createWithRootNull() { - select = Bindings.selectString(null, "next", "name"); - } - - @Test - public void createWithNoSteps() { - select = Bindings.selectString(a.nameProperty()); - assertEquals("a", select.get()); - a.setName("b"); - assertEquals("b", select.get()); - a.setName(null); - assertNull(select.get()); - log.check(java.util.logging.Level.WARNING, NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void createWithOneStepIsNull() { - select = Bindings.selectString(a.nextProperty(), null, "name"); - } - - @Test - public void testNullIsReturnedFromAChainWithAPropertyThatIsNotOnTheAvailableObject() { - select = Bindings.selectString(a.nextProperty(), "dummy", "name"); - assertNull(select.get()); - log.check(java.util.logging.Level.WARNING, NoSuchMethodException.class); - } - - @SuppressWarnings("unchecked") - @Test - public void testAllMembersHaveListeners() { - // As yet, there should still be no listeners registered - assertEquals(1, a.numChangedListenersForNext); - assertEquals(0, a.numChangedListenersForName); - assertEquals(0, b.numChangedListenersForNext); - assertEquals(0, b.numChangedListenersForName); - assertEquals(0, c.numChangedListenersForNext); - assertEquals(0, c.numChangedListenersForName); - assertEquals(Arrays.asList(a.nextProperty()), dependencies); - // Read the value of the select. It should be == "c" - assertEquals("c", select.get()); - // Now there should be changed listeners for a.value and - // b.value and c.name - assertEquals(1, a.numChangedListenersForNext); - assertEquals(0, a.numChangedListenersForName); - assertEquals(1, b.numChangedListenersForNext); - assertEquals(0, b.numChangedListenersForName); - assertEquals(0, c.numChangedListenersForNext); - assertEquals(1, c.numChangedListenersForName); - assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); - } - - @SuppressWarnings("unchecked") - @Test - public void testWhenAValidChangeIsBrokenBySettingTheRootToNullThenTheValueIsNull() { - - assertEquals("c", select.get()); - a.setNext(null); - assertEquals(Arrays.asList(a.nextProperty()), dependencies); - assertNull(select.get()); - assertEquals(Arrays.asList(a.nextProperty()), dependencies); - log.checkFine(NullPointerException.class); - } - - @SuppressWarnings("unchecked") - @Test - public void testWhenAnIncompleteChainIsMadeCompleteThatTheValueIsComputedCorrectly() { - - a.setNext(null); - select.get(); // force it to be validated, for fun - log.reset(); - a.setNext(b); - assertEquals(Arrays.asList(a.nextProperty()), dependencies); - assertEquals("c", select.get()); - assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); - assertTrue(log.isEmpty()); - } - - @SuppressWarnings("unchecked") - @Test - public void testWhenAValidChangeIsBrokenBySettingTheMiddleToNullThenTheValueIsNull() { - - assertEquals("c", select.get()); - b.setNext(null); - assertEquals(Arrays.asList(a.nextProperty()), dependencies); - assertNull(select.get()); - assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty()), dependencies); - log.checkFine(NullPointerException.class); - } - - @SuppressWarnings("unchecked") - @Test - public void testWhenAnIncompleteChainIsMadeCompleteInTheMiddleThatTheValueIsComputedCorrectly() { - - b.setNext(null); - select.get(); - log.reset(); - b.setNext(c); - assertEquals(Arrays.asList(a.nextProperty()), dependencies); - assertEquals("c", select.get()); - assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); - assertTrue(log.isEmpty()); - } - - @SuppressWarnings("unchecked") - @Test - public void testWhenAValidChangeIsBrokenBySettingTheLastLinkToNullThenTheValueIsNull() { - log.reset(); - assertEquals("c", select.get()); - c.setName("d"); - assertEquals(Arrays.asList(a.nextProperty()), dependencies); - assertEquals("d", select.get()); - assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); - assertTrue(log.isEmpty()); - } - - @SuppressWarnings("unchecked") - @Test - public void testWhenAnIncompleteChainIsMadeCompleteAtTheEndThatTheValueIsComputedCorrectly() { - log.reset(); - c.setName("d"); - select.get(); - c.setName("c"); - assertEquals(Arrays.asList(a.nextProperty()), dependencies); - assertEquals("c", select.get()); - assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); - assertTrue(log.isEmpty()); - } - - @SuppressWarnings("unchecked") - @Test - public void testSettingTheRootValueToNullInAChainShouldUnhookAllListeners() { - select.get(); - a.setNext(null); - - // All of the listeners should have been uninstalled - assertEquals(0, a.numChangedListenersForName); - assertEquals(1, a.numChangedListenersForNext); - - assertEquals(0, b.numChangedListenersForName); - assertEquals(0, b.numChangedListenersForNext); - - assertEquals(0, c.numChangedListenersForName); - assertEquals(0, c.numChangedListenersForNext); - - assertEquals(0, d.numChangedListenersForName); - assertEquals(0, d.numChangedListenersForNext); - - assertEquals(Arrays.asList(a.nextProperty()), dependencies); - } - - /** - * This test performs 10,000 random operations on the chain of a.b.c - * (setting different values for each step, sometimes doing multiple - * assignments between get() calls, random invalidate() calls). After each - * random iteration, we check to see if the listeners installed on the a, b, - * c objects are still correct. The goal is to catch any freak situations - * where we might have installed two listeners on the same property, or - * failed to remove a listener for a property under some circumstance. - * - * Do note that the only listeners that are installed in this method are - * done by the select binding. - */ - @SuppressWarnings("unchecked") - @Test - public void stressTestRandomOperationsResultInCorrectListenersInstalled() { - - final Level logLevel = Logging.getLogger().level(); - Logging.getLogger().setLevel(Level.SEVERE); - List steps = new ArrayList(); - - Random rand = new Random(System.currentTimeMillis()); - for (int i = 0; i < 10000; i++) { - switch (rand.nextInt(20)) { - case 0: - a.setNext(null); - steps.add("Assign a.value to null"); - break; - case 1: - a.setNext(b); - steps.add("Assign a.value to b"); - break; - case 2: - b.setNext(null); - steps.add("Assign b.value to null"); - break; - case 3: - b.setNext(c); - steps.add("Assign b.value to c"); - break; - case 4: - c.setNext(null); - steps.add("Assign c.value to null"); - break; - case 5: - c.setNext(d); - steps.add("Assign c.value to d"); - break; - case 6: - c.setName(null); - steps.add("Assign c.name to null"); - break; - case 7: - c.setName("c"); - steps.add("Assign c.name to 'c'"); - break; - default: - select.get(); - steps.add("Call select.get()"); - } - - // Now validate that the listeners are as we expected - int expected = 1; - int depsCount = expected; - assertEquals(0, a.numChangedListenersForName); - if (expected != a.numChangedListenersForNext) { - printSteps(i, steps); - } - assertEquals(expected, a.numChangedListenersForNext); - - expected = select.isValid() && a.getNext() == b ? 1 : 0; - depsCount += expected; - assertEquals(0, b.numChangedListenersForName); - if (expected != b.numChangedListenersForNext) { - printSteps(i, steps); - } - assertEquals(expected, b.numChangedListenersForNext); - - expected = select.isValid() && a.getNext() == b && b.getNext() == c ? 1 : 0; - depsCount += expected; - assertEquals(0, c.numChangedListenersForNext); - if (expected != c.numChangedListenersForName) { - printSteps(i, steps); - } - assertEquals(expected, c.numChangedListenersForName); - - assertEquals(0, d.numChangedListenersForName); - assertEquals(0, d.numChangedListenersForNext); - - switch (depsCount) { - case 0: - case 1: - assertEquals(Arrays.asList(a.nextProperty()), dependencies); - break; - case 2: - assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty()), dependencies); - break; - case 3: - assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); - break; - default: - fail("Should not reach here"); - } - } - Logging.getLogger().setLevel(logLevel); - } - - private void printSteps(int iteration, List steps) { - System.err.println("Failed on iteration " + iteration + " for the following observableArrayList of changes"); - for (String s : steps) { - System.err.println("\t" + s); - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/SelectBindingTest.java 2015-08-31 10:22:56.121217826 -0400 @@ -0,0 +1,656 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.com.sun.javafx.binding; + +import com.sun.javafx.binding.Logging; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import test.javafx.beans.Person; +import javafx.beans.binding.Bindings; +import javafx.beans.binding.BooleanBinding; +import javafx.beans.binding.DoubleBinding; +import javafx.beans.binding.FloatBinding; +import javafx.beans.binding.IntegerBinding; +import javafx.beans.binding.LongBinding; +import javafx.beans.binding.ObjectBinding; +import javafx.beans.binding.StringBinding; +import test.javafx.binding.Variable; +import javafx.collections.ObservableList; +import sun.util.logging.PlatformLogger.Level; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class SelectBindingTest { + + private static final double EPSILON_DOUBLE = 1e-12; + private static final float EPSILON_FLOAT = 1e-6f; + + public static class POJOPerson { + + private String name; + + public String getName() { + return name; + } + + public POJOPerson() { + } + + public POJOPerson(String name) { + this.name = name; + } + + } + + public static class POJONext { + + private Object next; + private PropertyChangeSupport pcs = new PropertyChangeSupport(this); + + public Object getNext() { + return next; + } + + public void setNext(Object next) { + Object old = this.next; + this.next = next; + pcs.firePropertyChange("next", old, next); + } + + public void addPropertyChangeListener(String property, PropertyChangeListener pcl) { + pcs.addPropertyChangeListener(property, pcl); + } + + public void removePropertyChangeListener(String property, PropertyChangeListener pcl) { + pcs.removePropertyChangeListener(property, pcl); + } + + } + + private Variable a; + private Variable b; + private Variable c; + private Variable d; + private StringBinding select; + private ObservableList dependencies; + + private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); + + @BeforeClass + public static void setUpClass() { + log.start(); + } + + @AfterClass + public static void tearDownClass() { + log.stop(); + } + + @Before + public void setUp() throws Exception { + a = new Variable("a"); + b = new Variable("b"); + c = new Variable("c"); + d = new Variable("d"); + a.setNext(b); + b.setNext(c); + select = Bindings.selectString(a.nextProperty(), "next", "name"); + dependencies = select.getDependencies(); + } + + @Test + public void testObject() { + final Person person1 = new Person(); + final Person person2 = new Person(); + c.setNext(person1); + final ObjectBinding objectBinding = Bindings.select(a.nextProperty(), "next", "next"); + assertEquals(person1, objectBinding.get()); + c.setNext(person2); + assertEquals(person2, objectBinding.get()); + b.setNext(null); + assertEquals(null, objectBinding.get()); + log.checkFine(NullPointerException.class); + } + + @Test + public void testPOJOObject() { + POJONext pojoA = new POJONext(); + pojoA.setNext(b); + final Person person1 = new Person(); + final Person person2 = new Person(); + c.setNext(person1); + final ObjectBinding objectBinding = Bindings.select(pojoA, "next", "next", "next"); + assertEquals(person1, objectBinding.get()); + c.setNext(person2); + assertEquals(person2, objectBinding.get()); + } + + @Test + public void testPOJOObject_2() { + POJONext pojoC = new POJONext(); + b.setNext(pojoC); + final Person person1 = new Person(); + final Person person2 = new Person(); + pojoC.setNext(person1); + final ObjectBinding objectBinding = Bindings.select(a.nextProperty(), "next", "next"); + assertEquals(person1, objectBinding.get()); + pojoC.setNext(person2); + assertEquals(person2, objectBinding.get()); + } + + @Test + public void testPOJOObject_3() { + final POJOPerson person1 = new POJOPerson("P1"); + final POJOPerson person2 = new POJOPerson("P2"); + c.setNext(person1); + final ObjectBinding objectBinding = Bindings.select(a.nextProperty(), "next", "next", "name"); + assertEquals("P1", objectBinding.get()); + c.setNext(person2); + assertEquals("P2", objectBinding.get()); + b.setNext(null); + assertEquals(null, objectBinding.get()); + log.checkFine(NullPointerException.class); + } + + @Test + public void testPOJOBoolean() { + + POJONext pojoA = new POJONext(); + pojoA.setNext(b); + + final Person person = new Person(); + b.setNext(person); + final BooleanBinding binding1 = Bindings.selectBoolean(pojoA, "next", "next", "retired"); + assertEquals(false, binding1.get()); + person.setRetired(true); + assertEquals(true, binding1.get()); + } + + @Test + public void testBoolean() { + + final Person person = new Person(); + b.setNext(person); + final BooleanBinding binding1 = Bindings.selectBoolean(a.nextProperty(), "next", "retired"); + assertEquals(false, binding1.get()); + person.setRetired(true); + assertEquals(true, binding1.get()); + b.setNext(null); + assertEquals(false, binding1.get()); + log.checkFine(NullPointerException.class); + + person.setData(false); + b.setNext(person); + final BooleanBinding binding2 = Bindings.selectBoolean(a.nextProperty(), "next", "data"); + assertEquals(false, binding2.get()); + person.setData(true); + assertEquals(true, binding2.get()); + person.setData(null); + assertEquals(false, binding2.get()); + log.checkFine(NullPointerException.class); + b.setNext(null); + assertEquals(false, binding2.get()); + log.checkFine(NullPointerException.class); + } + + @Test + public void testPOJODouble() { + POJONext pojoA = new POJONext(); + pojoA.setNext(b); + + final Person person = new Person(); + person.setSomething(-Math.E); + b.setNext(person); + final DoubleBinding binding1 = Bindings.selectDouble(pojoA, "next", "next", "something"); + assertEquals(-Math.E, binding1.get(), EPSILON_DOUBLE); + person.setSomething(Math.PI); + assertEquals(Math.PI, binding1.get(), EPSILON_DOUBLE); + } + + @Test + public void testDouble() { + + final Person person = new Person(); + person.setSomething(-Math.E); + b.setNext(person); + final DoubleBinding binding1 = Bindings.selectDouble(a.nextProperty(), "next", "something"); + assertEquals(-Math.E, binding1.get(), EPSILON_DOUBLE); + person.setSomething(Math.PI); + assertEquals(Math.PI, binding1.get(), EPSILON_DOUBLE); + b.setNext(null); + assertEquals(0.0, binding1.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + + person.setData(-Math.E); + b.setNext(person); + final DoubleBinding binding2 = Bindings.selectDouble(a.nextProperty(), "next", "data"); + assertEquals(-Math.E, binding2.get(), EPSILON_DOUBLE); + person.setData(Math.PI); + assertEquals(Math.PI, binding2.get(), EPSILON_DOUBLE); + person.setData(null); + assertEquals(0.0, binding2.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + b.setNext(null); + assertEquals(0.0, binding2.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + } + + @Test + public void testPOJOFloat() { + POJONext pojoA = new POJONext(); + pojoA.setNext(b); + + final Person person = new Person(); + person.setMiles((float) -Math.E); + b.setNext(person); + final FloatBinding binding1 = Bindings.selectFloat(pojoA, "next", "next", "miles"); + assertEquals((float) -Math.E, binding1.get(), EPSILON_FLOAT); + person.setMiles((float) Math.PI); + assertEquals((float) Math.PI, binding1.get(), EPSILON_FLOAT); + } + + @Test + public void testFloat() { + + final Person person = new Person(); + person.setMiles((float) -Math.E); + b.setNext(person); + final FloatBinding binding1 = Bindings.selectFloat(a.nextProperty(), "next", "miles"); + assertEquals((float) -Math.E, binding1.get(), EPSILON_FLOAT); + person.setMiles((float) Math.PI); + assertEquals((float) Math.PI, binding1.get(), EPSILON_FLOAT); + b.setNext(null); + assertEquals(0.0f, binding1.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + + person.setData((float) -Math.E); + b.setNext(person); + final FloatBinding binding2 = Bindings.selectFloat(a.nextProperty(), "next", "data"); + assertEquals((float) -Math.E, binding2.get(), EPSILON_FLOAT); + person.setData((float) Math.PI); + assertEquals((float) Math.PI, binding2.get(), EPSILON_FLOAT); + person.setData(null); + assertEquals(0.0f, binding2.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + b.setNext(null); + assertEquals(0.0f, binding2.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + } + + @Test + public void testPOJOInteger() { + + POJONext pojoA = new POJONext(); + pojoA.setNext(b); + + final Person person = new Person(); + person.setAge(42); + b.setNext(person); + final IntegerBinding binding1 = Bindings.selectInteger(pojoA, "next", "next", "age"); + assertEquals(42, binding1.get()); + person.setAge(-18); + assertEquals(-18, binding1.get()); + } + + @Test + public void testInteger() { + + final Person person = new Person(); + person.setAge(42); + b.setNext(person); + final IntegerBinding binding1 = Bindings.selectInteger(a.nextProperty(), "next", "age"); + assertEquals(42, binding1.get()); + person.setAge(-18); + assertEquals(-18, binding1.get()); + b.setNext(null); + assertEquals(0, binding1.get()); + log.checkFine(NullPointerException.class); + + person.setData(42); + b.setNext(person); + final IntegerBinding binding2 = Bindings.selectInteger(a.nextProperty(), "next", "data"); + assertEquals(42, binding2.get()); + person.setData(-18); + assertEquals(-18, binding2.get()); + person.setData(null); + assertEquals(0, binding2.get()); + log.checkFine(NullPointerException.class); + b.setNext(null); + assertEquals(0, binding2.get()); + log.checkFine(NullPointerException.class); + } + + @Test + public void testPOJOLong() { + POJONext pojoA = new POJONext(); + pojoA.setNext(b); + final Person person = new Person(); + person.setIncome(1234567890987654321L); + b.setNext(person); + final LongBinding binding1 = Bindings.selectLong(pojoA, "next", "next", "income"); + assertEquals(1234567890987654321L, binding1.get()); + person.setIncome(-987654321234567890L); + assertEquals(-987654321234567890L, binding1.get()); + } + + @Test + public void testLong() { + final Person person = new Person(); + person.setIncome(1234567890987654321L); + b.setNext(person); + final LongBinding binding1 = Bindings.selectLong(a.nextProperty(), "next", "income"); + assertEquals(1234567890987654321L, binding1.get()); + person.setIncome(-987654321234567890L); + assertEquals(-987654321234567890L, binding1.get()); + b.setNext(null); + assertEquals(0L, binding1.get()); + log.checkFine(NullPointerException.class); + + person.setData(1234567890987654321L); + b.setNext(person); + final LongBinding binding2 = Bindings.selectLong(a.nextProperty(), "next", "data"); + assertEquals(1234567890987654321L, binding2.get()); + person.setData(-987654321234567890L); + assertEquals(-987654321234567890L, binding2.get()); + person.setData(null); + assertEquals(0L, binding2.get()); + log.checkFine(NullPointerException.class); + b.setNext(null); + assertEquals(0L, binding2.get()); + log.checkFine(NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void createWithRootNull() { + select = Bindings.selectString(null, "next", "name"); + } + + @Test + public void createWithNoSteps() { + select = Bindings.selectString(a.nameProperty()); + assertEquals("a", select.get()); + a.setName("b"); + assertEquals("b", select.get()); + a.setName(null); + assertNull(select.get()); + log.check(java.util.logging.Level.WARNING, NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void createWithOneStepIsNull() { + select = Bindings.selectString(a.nextProperty(), null, "name"); + } + + @Test + public void testNullIsReturnedFromAChainWithAPropertyThatIsNotOnTheAvailableObject() { + select = Bindings.selectString(a.nextProperty(), "dummy", "name"); + assertNull(select.get()); + log.check(java.util.logging.Level.WARNING, NoSuchMethodException.class); + } + + @SuppressWarnings("unchecked") + @Test + public void testAllMembersHaveListeners() { + // As yet, there should still be no listeners registered + assertEquals(1, a.numChangedListenersForNext); + assertEquals(0, a.numChangedListenersForName); + assertEquals(0, b.numChangedListenersForNext); + assertEquals(0, b.numChangedListenersForName); + assertEquals(0, c.numChangedListenersForNext); + assertEquals(0, c.numChangedListenersForName); + assertEquals(Arrays.asList(a.nextProperty()), dependencies); + // Read the value of the select. It should be == "c" + assertEquals("c", select.get()); + // Now there should be changed listeners for a.value and + // b.value and c.name + assertEquals(1, a.numChangedListenersForNext); + assertEquals(0, a.numChangedListenersForName); + assertEquals(1, b.numChangedListenersForNext); + assertEquals(0, b.numChangedListenersForName); + assertEquals(0, c.numChangedListenersForNext); + assertEquals(1, c.numChangedListenersForName); + assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); + } + + @SuppressWarnings("unchecked") + @Test + public void testWhenAValidChangeIsBrokenBySettingTheRootToNullThenTheValueIsNull() { + + assertEquals("c", select.get()); + a.setNext(null); + assertEquals(Arrays.asList(a.nextProperty()), dependencies); + assertNull(select.get()); + assertEquals(Arrays.asList(a.nextProperty()), dependencies); + log.checkFine(NullPointerException.class); + } + + @SuppressWarnings("unchecked") + @Test + public void testWhenAnIncompleteChainIsMadeCompleteThatTheValueIsComputedCorrectly() { + + a.setNext(null); + select.get(); // force it to be validated, for fun + log.reset(); + a.setNext(b); + assertEquals(Arrays.asList(a.nextProperty()), dependencies); + assertEquals("c", select.get()); + assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); + assertTrue(log.isEmpty()); + } + + @SuppressWarnings("unchecked") + @Test + public void testWhenAValidChangeIsBrokenBySettingTheMiddleToNullThenTheValueIsNull() { + + assertEquals("c", select.get()); + b.setNext(null); + assertEquals(Arrays.asList(a.nextProperty()), dependencies); + assertNull(select.get()); + assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty()), dependencies); + log.checkFine(NullPointerException.class); + } + + @SuppressWarnings("unchecked") + @Test + public void testWhenAnIncompleteChainIsMadeCompleteInTheMiddleThatTheValueIsComputedCorrectly() { + + b.setNext(null); + select.get(); + log.reset(); + b.setNext(c); + assertEquals(Arrays.asList(a.nextProperty()), dependencies); + assertEquals("c", select.get()); + assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); + assertTrue(log.isEmpty()); + } + + @SuppressWarnings("unchecked") + @Test + public void testWhenAValidChangeIsBrokenBySettingTheLastLinkToNullThenTheValueIsNull() { + log.reset(); + assertEquals("c", select.get()); + c.setName("d"); + assertEquals(Arrays.asList(a.nextProperty()), dependencies); + assertEquals("d", select.get()); + assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); + assertTrue(log.isEmpty()); + } + + @SuppressWarnings("unchecked") + @Test + public void testWhenAnIncompleteChainIsMadeCompleteAtTheEndThatTheValueIsComputedCorrectly() { + log.reset(); + c.setName("d"); + select.get(); + c.setName("c"); + assertEquals(Arrays.asList(a.nextProperty()), dependencies); + assertEquals("c", select.get()); + assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); + assertTrue(log.isEmpty()); + } + + @SuppressWarnings("unchecked") + @Test + public void testSettingTheRootValueToNullInAChainShouldUnhookAllListeners() { + select.get(); + a.setNext(null); + + // All of the listeners should have been uninstalled + assertEquals(0, a.numChangedListenersForName); + assertEquals(1, a.numChangedListenersForNext); + + assertEquals(0, b.numChangedListenersForName); + assertEquals(0, b.numChangedListenersForNext); + + assertEquals(0, c.numChangedListenersForName); + assertEquals(0, c.numChangedListenersForNext); + + assertEquals(0, d.numChangedListenersForName); + assertEquals(0, d.numChangedListenersForNext); + + assertEquals(Arrays.asList(a.nextProperty()), dependencies); + } + + /** + * This test performs 10,000 random operations on the chain of a.b.c + * (setting different values for each step, sometimes doing multiple + * assignments between get() calls, random invalidate() calls). After each + * random iteration, we check to see if the listeners installed on the a, b, + * c objects are still correct. The goal is to catch any freak situations + * where we might have installed two listeners on the same property, or + * failed to remove a listener for a property under some circumstance. + * + * Do note that the only listeners that are installed in this method are + * done by the select binding. + */ + @SuppressWarnings("unchecked") + @Test + public void stressTestRandomOperationsResultInCorrectListenersInstalled() { + + final Level logLevel = Logging.getLogger().level(); + Logging.getLogger().setLevel(Level.SEVERE); + List steps = new ArrayList(); + + Random rand = new Random(System.currentTimeMillis()); + for (int i = 0; i < 10000; i++) { + switch (rand.nextInt(20)) { + case 0: + a.setNext(null); + steps.add("Assign a.value to null"); + break; + case 1: + a.setNext(b); + steps.add("Assign a.value to b"); + break; + case 2: + b.setNext(null); + steps.add("Assign b.value to null"); + break; + case 3: + b.setNext(c); + steps.add("Assign b.value to c"); + break; + case 4: + c.setNext(null); + steps.add("Assign c.value to null"); + break; + case 5: + c.setNext(d); + steps.add("Assign c.value to d"); + break; + case 6: + c.setName(null); + steps.add("Assign c.name to null"); + break; + case 7: + c.setName("c"); + steps.add("Assign c.name to 'c'"); + break; + default: + select.get(); + steps.add("Call select.get()"); + } + + // Now validate that the listeners are as we expected + int expected = 1; + int depsCount = expected; + assertEquals(0, a.numChangedListenersForName); + if (expected != a.numChangedListenersForNext) { + printSteps(i, steps); + } + assertEquals(expected, a.numChangedListenersForNext); + + expected = select.isValid() && a.getNext() == b ? 1 : 0; + depsCount += expected; + assertEquals(0, b.numChangedListenersForName); + if (expected != b.numChangedListenersForNext) { + printSteps(i, steps); + } + assertEquals(expected, b.numChangedListenersForNext); + + expected = select.isValid() && a.getNext() == b && b.getNext() == c ? 1 : 0; + depsCount += expected; + assertEquals(0, c.numChangedListenersForNext); + if (expected != c.numChangedListenersForName) { + printSteps(i, steps); + } + assertEquals(expected, c.numChangedListenersForName); + + assertEquals(0, d.numChangedListenersForName); + assertEquals(0, d.numChangedListenersForNext); + + switch (depsCount) { + case 0: + case 1: + assertEquals(Arrays.asList(a.nextProperty()), dependencies); + break; + case 2: + assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty()), dependencies); + break; + case 3: + assertEquals(Arrays.asList(a.nextProperty(), b.nextProperty(), c.nameProperty()), dependencies); + break; + default: + fail("Should not reach here"); + } + } + Logging.getLogger().setLevel(logLevel); + } + + private void printSteps(int iteration, List steps) { + System.err.println("Failed on iteration " + iteration + " for the following observableArrayList of changes"); + for (String s : steps) { + System.err.println("\t" + s); + } + } +} --- old/modules/base/src/test/java/com/sun/javafx/binding/StringFormatterTest.java 2015-08-31 10:22:56.877217817 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,404 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.binding; - -import static org.junit.Assert.assertEquals; - -import java.util.Date; -import java.util.IllegalFormatException; -import java.util.Locale; - -import javafx.beans.binding.Bindings; -import javafx.beans.binding.StringBinding; -import javafx.beans.binding.StringExpression; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.FloatProperty; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.LongProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleLongProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; -import javafx.binding.DependencyUtils; - -import org.junit.Before; -import org.junit.Test; - -@SuppressWarnings("WebTest") -public class StringFormatterTest { - - private double double0; - private float float0; - private long long0; - private int int0; - private boolean boolean0; - private String string0; - private Date date0; - - private double double1; - private float float1; - private long long1; - private int int1; - private boolean boolean1; - private String string1; - private Date date1; - - private DoubleProperty doubleV; - private FloatProperty floatV; - private LongProperty longV; - private IntegerProperty intV; - private BooleanProperty booleanV; - private StringProperty stringV; - private ObjectProperty dateV; - - @Before - public void setUp() { - double0 = 90.1243987; - float0 = -897.4509f; - long0 = -88793289779238972L; - int0 = -9872498; - boolean0 = false; - string0 = "Hello"; - date0 = new Date(0); - - double1 = 23341.9823; - float1 = 989823.8723f; - long1 = 98234892892389233L; - int1 = -897237894; - boolean1 = true; - string1 = "Goodbye"; - date1 = new Date(); - - doubleV = new SimpleDoubleProperty(double0); - floatV = new SimpleFloatProperty(float0); - longV = new SimpleLongProperty(long0); - intV = new SimpleIntegerProperty(int0); - booleanV = new SimpleBooleanProperty(boolean0); - stringV = new SimpleStringProperty(string0); - dateV = new SimpleObjectProperty(date0); - } - - @Test - public void testConvert() { - StringExpression s = Bindings.convert(doubleV); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV); - assertEquals(Double.toString(double0), s.get()); - doubleV.set(double1); - assertEquals(Double.toString(double1), s.get()); - - s = Bindings.convert(floatV); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), floatV); - assertEquals(Float.toString(float0), s.get()); - floatV.set(float1); - assertEquals(Float.toString(float1), s.get()); - - s = Bindings.convert(longV); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), longV); - assertEquals(Long.toString(long0), s.get()); - longV.set(long1); - assertEquals(Long.toString(long1), s.get()); - - s = Bindings.convert(intV); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), intV); - assertEquals(Integer.toString(int0), s.get()); - intV.set(int1); - assertEquals(Integer.toString(int1), s.get()); - - s = Bindings.convert(booleanV); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), booleanV); - assertEquals(Boolean.toString(boolean0), s.get()); - booleanV.set(boolean1); - assertEquals(Boolean.toString(boolean1), s.get()); - - s = Bindings.convert(dateV); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); - assertEquals(date0.toString(), s.get()); - dateV.set(date1); - assertEquals(date1.toString(), s.get()); - dateV.set(null); - assertEquals("null", s.get()); - - s = Bindings.convert(stringV); - assertEquals(stringV, s); - } - - @Test(expected=NullPointerException.class) - public void testConvert_Null() { - Bindings.convert(null); - } - - @Test - public void testConcat() { - // empty - StringExpression s = Bindings.concat(); - assertEquals("", s.get()); - s = Bindings.concat(new Object[0]); - assertEquals("", s.get()); - - // one object - s = Bindings.concat(date1); - assertEquals(date1.toString(), s.get()); - - // one variable - s = Bindings.concat(dateV); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); - assertEquals(date0.toString(), s.get()); - dateV.set(date1); - assertEquals(date1.toString(), s.get()); - dateV.set(null); - assertEquals("null", s.get()); - dateV.set(date0); - - // two objects - s = Bindings.concat(date0, date1); - assertEquals(date0.toString() + date1.toString(), s.get()); - - // test all - s = Bindings.concat(doubleV, double1, floatV, float1, longV, long1, intV, int1, booleanV, boolean1, stringV, string1, dateV, date1); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV, floatV, longV, intV, booleanV, stringV, dateV); - assertEquals("" + double0 + double1 + float0 + float1 + long0 + long1 + int0 + int1+ boolean0 + boolean1 + string0 + string1 + date0 + date1, s.get()); - doubleV.set(double1); - floatV.set(float1); - longV.set(long1); - intV.set(int1); - booleanV.set(boolean1); - stringV.set(string1); - dateV.set(date1); - assertEquals("" + double1 + double1 + float1 + float1 + long1 + long1 + int1 + int1 + boolean1 + boolean1 + string1 + string1 + date1 + date1, s.get()); - stringV.set(null); - dateV.set(null); - assertEquals("" + double1 + double1 + float1 + float1 + long1 + long1 + int1 + int1 + boolean1 + boolean1 + "null" + string1 + "null" + date1, s.get()); - } - - @Test - public void testConvertWithDefaultLocale() { - // empty - StringExpression s = Bindings.format("Empty String"); - assertEquals("Empty String", s.get()); - - final Locale defaultLocale = Locale.getDefault(); - try { - // German Locale - Locale.setDefault(Locale.GERMAN); - // one object - s = Bindings.format("Date: %tc", date1); - assertEquals(String.format(Locale.GERMAN, "Date: %tc", date1), s.get()); - // one variable - s = Bindings.format("Date: %tc", dateV); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); - assertEquals(String.format(Locale.GERMAN, "Date: %tc", date0), s.get()); - dateV.set(date1); - assertEquals(String.format(Locale.GERMAN, "Date: %tc", date1), s.get()); - dateV.set(null); - assertEquals("Date: null", s.get()); - dateV.set(date0); - - // test all - s = Bindings.format("%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - doubleV, double1, floatV, float1, longV, long1, intV, int1, booleanV, boolean1, stringV, string1, dateV, date1); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV, floatV, longV, intV, booleanV, stringV, dateV); - assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - double0, double1, float0, float1, long0, long1, int0, int1, boolean0, boolean1, string0, string1, date0, date1), s.get()); - doubleV.set(double1); - floatV.set(float1); - longV.set(long1); - intV.set(int1); - booleanV.set(boolean1); - stringV.set(string1); - dateV.set(date1); - assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, string1, string1, date1, date1), s.get()); - stringV.set(null); - dateV.set(null); - assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %s, %tc", - double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, "null", string1, "null", date1), s.get()); - - // US Locale - Locale.setDefault(Locale.US); - doubleV.set(double0); - floatV.set(float0); - longV.set(long0); - intV.set(int0); - booleanV.set(boolean0); - stringV.set(string0); - dateV.set(date0); - // one object - s = Bindings.format("Date: %tc", date1); - assertEquals(String.format(Locale.US, "Date: %tc", date1), s.get()); - // one variable - s = Bindings.format("Date: %tc", dateV); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); - assertEquals(String.format(Locale.US, "Date: %tc", date0), s.get()); - dateV.set(date1); - assertEquals(String.format(Locale.US, "Date: %tc", date1), s.get()); - dateV.set(null); - assertEquals("Date: null", s.get()); - dateV.set(date0); - - // test all - s = Bindings.format("%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - doubleV, double1, floatV, float1, longV, long1, intV, int1, booleanV, boolean1, stringV, string1, dateV, date1); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV, floatV, longV, intV, booleanV, stringV, dateV); - assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - double0, double1, float0, float1, long0, long1, int0, int1, boolean0, boolean1, string0, string1, date0, date1), s.get()); - doubleV.set(double1); - floatV.set(float1); - longV.set(long1); - intV.set(int1); - booleanV.set(boolean1); - stringV.set(string1); - dateV.set(date1); - assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, string1, string1, date1, date1), s.get()); - stringV.set(null); - dateV.set(null); - assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %s, %tc", - double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, "null", string1, "null", date1), s.get()); - } finally { - Locale.setDefault(defaultLocale); - } - } - - @Test(expected=NullPointerException.class) - public void testConvertWithDefaultLocale_Null() { - Bindings.format(null); - } - - @Test(expected=IllegalFormatException.class) - public void testConvertWithDefaultLocale_IllegalObject() { - Bindings.format("%tc", double0); - } - - @Test(expected=IllegalFormatException.class) - public void testConvertWithDefaultLocale_IllegalValueModel() { - Bindings.format("%tc", doubleV); - } - - @Test - public void testConvertWithCustomLocale() { - // German Locale - // empty - StringExpression s = Bindings.format(Locale.GERMAN, "Empty String"); - assertEquals("Empty String", s.get()); - // one object - s = Bindings.format(Locale.GERMAN, "Date: %tc", date1); - assertEquals(String.format(Locale.GERMAN, "Date: %tc", date1), s.get()); - // one variable - s = Bindings.format(Locale.GERMAN, "Date: %tc", dateV); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); - assertEquals(String.format(Locale.GERMAN, "Date: %tc", date0), s.get()); - dateV.set(date1); - assertEquals(String.format(Locale.GERMAN, "Date: %tc", date1), s.get()); - dateV.set(null); - assertEquals("Date: null", s.get()); - dateV.set(date0); - - // test all - s = Bindings.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - doubleV, double1, floatV, float1, longV, long1, intV, int1, booleanV, boolean1, stringV, string1, dateV, date1); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV, floatV, longV, intV, booleanV, stringV, dateV); - assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - double0, double1, float0, float1, long0, long1, int0, int1, boolean0, boolean1, string0, string1, date0, date1), s.get()); - doubleV.set(double1); - floatV.set(float1); - longV.set(long1); - intV.set(int1); - booleanV.set(boolean1); - stringV.set(string1); - dateV.set(date1); - assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, string1, string1, date1, date1), s.get()); - stringV.set(null); - dateV.set(null); - assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %s, %tc", - double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, "null", string1, "null", date1), s.get()); - - // US Locale - doubleV.set(double0); - floatV.set(float0); - longV.set(long0); - intV.set(int0); - booleanV.set(boolean0); - stringV.set(string0); - dateV.set(date0); - // empty - s = Bindings.format(Locale.US, "Empty String"); - assertEquals("Empty String", s.get()); - // one object - s = Bindings.format(Locale.US, "Date: %tc", date1); - assertEquals(String.format(Locale.US, "Date: %tc", date1), s.get()); - // one variable - s = Bindings.format(Locale.US, "Date: %tc", dateV); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); - assertEquals(String.format(Locale.US, "Date: %tc", date0), s.get()); - dateV.set(date1); - assertEquals(String.format(Locale.US, "Date: %tc", date1), s.get()); - dateV.set(null); - assertEquals("Date: null", s.get()); - dateV.set(date0); - - // test all - s = Bindings.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - doubleV, double1, floatV, float1, longV, long1, intV, int1, booleanV, boolean1, stringV, string1, dateV, date1); - DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV, floatV, longV, intV, booleanV, stringV, dateV); - assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - double0, double1, float0, float1, long0, long1, int0, int1, boolean0, boolean1, string0, string1, date0, date1), s.get()); - doubleV.set(double1); - floatV.set(float1); - longV.set(long1); - intV.set(int1); - booleanV.set(boolean1); - stringV.set(string1); - dateV.set(date1); - assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", - double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, string1, string1, date1, date1), s.get()); - stringV.set(null); - dateV.set(null); - assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %s, %tc", - double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, "null", string1, "null", date1), s.get()); - } - - @Test(expected=NullPointerException.class) - public void testConvertWithCustomLocale_Null() { - Bindings.format(Locale.US, null); - } - - @Test(expected=IllegalFormatException.class) - public void testConvertWithCustomLocale_IllegalObject() { - Bindings.format(Locale.US, "%tc", double0); - } - - @Test(expected=IllegalFormatException.class) - public void testConvertWithCustomLocale_IllegalValueModel() { - Bindings.format(Locale.US, "%tc", doubleV); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/binding/StringFormatterTest.java 2015-08-31 10:22:56.741217819 -0400 @@ -0,0 +1,404 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.binding; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; +import java.util.IllegalFormatException; +import java.util.Locale; + +import javafx.beans.binding.Bindings; +import javafx.beans.binding.StringBinding; +import javafx.beans.binding.StringExpression; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.FloatProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.LongProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import test.javafx.binding.DependencyUtils; + +import org.junit.Before; +import org.junit.Test; + +@SuppressWarnings("WebTest") +public class StringFormatterTest { + + private double double0; + private float float0; + private long long0; + private int int0; + private boolean boolean0; + private String string0; + private Date date0; + + private double double1; + private float float1; + private long long1; + private int int1; + private boolean boolean1; + private String string1; + private Date date1; + + private DoubleProperty doubleV; + private FloatProperty floatV; + private LongProperty longV; + private IntegerProperty intV; + private BooleanProperty booleanV; + private StringProperty stringV; + private ObjectProperty dateV; + + @Before + public void setUp() { + double0 = 90.1243987; + float0 = -897.4509f; + long0 = -88793289779238972L; + int0 = -9872498; + boolean0 = false; + string0 = "Hello"; + date0 = new Date(0); + + double1 = 23341.9823; + float1 = 989823.8723f; + long1 = 98234892892389233L; + int1 = -897237894; + boolean1 = true; + string1 = "Goodbye"; + date1 = new Date(); + + doubleV = new SimpleDoubleProperty(double0); + floatV = new SimpleFloatProperty(float0); + longV = new SimpleLongProperty(long0); + intV = new SimpleIntegerProperty(int0); + booleanV = new SimpleBooleanProperty(boolean0); + stringV = new SimpleStringProperty(string0); + dateV = new SimpleObjectProperty(date0); + } + + @Test + public void testConvert() { + StringExpression s = Bindings.convert(doubleV); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV); + assertEquals(Double.toString(double0), s.get()); + doubleV.set(double1); + assertEquals(Double.toString(double1), s.get()); + + s = Bindings.convert(floatV); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), floatV); + assertEquals(Float.toString(float0), s.get()); + floatV.set(float1); + assertEquals(Float.toString(float1), s.get()); + + s = Bindings.convert(longV); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), longV); + assertEquals(Long.toString(long0), s.get()); + longV.set(long1); + assertEquals(Long.toString(long1), s.get()); + + s = Bindings.convert(intV); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), intV); + assertEquals(Integer.toString(int0), s.get()); + intV.set(int1); + assertEquals(Integer.toString(int1), s.get()); + + s = Bindings.convert(booleanV); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), booleanV); + assertEquals(Boolean.toString(boolean0), s.get()); + booleanV.set(boolean1); + assertEquals(Boolean.toString(boolean1), s.get()); + + s = Bindings.convert(dateV); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); + assertEquals(date0.toString(), s.get()); + dateV.set(date1); + assertEquals(date1.toString(), s.get()); + dateV.set(null); + assertEquals("null", s.get()); + + s = Bindings.convert(stringV); + assertEquals(stringV, s); + } + + @Test(expected=NullPointerException.class) + public void testConvert_Null() { + Bindings.convert(null); + } + + @Test + public void testConcat() { + // empty + StringExpression s = Bindings.concat(); + assertEquals("", s.get()); + s = Bindings.concat(new Object[0]); + assertEquals("", s.get()); + + // one object + s = Bindings.concat(date1); + assertEquals(date1.toString(), s.get()); + + // one variable + s = Bindings.concat(dateV); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); + assertEquals(date0.toString(), s.get()); + dateV.set(date1); + assertEquals(date1.toString(), s.get()); + dateV.set(null); + assertEquals("null", s.get()); + dateV.set(date0); + + // two objects + s = Bindings.concat(date0, date1); + assertEquals(date0.toString() + date1.toString(), s.get()); + + // test all + s = Bindings.concat(doubleV, double1, floatV, float1, longV, long1, intV, int1, booleanV, boolean1, stringV, string1, dateV, date1); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV, floatV, longV, intV, booleanV, stringV, dateV); + assertEquals("" + double0 + double1 + float0 + float1 + long0 + long1 + int0 + int1+ boolean0 + boolean1 + string0 + string1 + date0 + date1, s.get()); + doubleV.set(double1); + floatV.set(float1); + longV.set(long1); + intV.set(int1); + booleanV.set(boolean1); + stringV.set(string1); + dateV.set(date1); + assertEquals("" + double1 + double1 + float1 + float1 + long1 + long1 + int1 + int1 + boolean1 + boolean1 + string1 + string1 + date1 + date1, s.get()); + stringV.set(null); + dateV.set(null); + assertEquals("" + double1 + double1 + float1 + float1 + long1 + long1 + int1 + int1 + boolean1 + boolean1 + "null" + string1 + "null" + date1, s.get()); + } + + @Test + public void testConvertWithDefaultLocale() { + // empty + StringExpression s = Bindings.format("Empty String"); + assertEquals("Empty String", s.get()); + + final Locale defaultLocale = Locale.getDefault(); + try { + // German Locale + Locale.setDefault(Locale.GERMAN); + // one object + s = Bindings.format("Date: %tc", date1); + assertEquals(String.format(Locale.GERMAN, "Date: %tc", date1), s.get()); + // one variable + s = Bindings.format("Date: %tc", dateV); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); + assertEquals(String.format(Locale.GERMAN, "Date: %tc", date0), s.get()); + dateV.set(date1); + assertEquals(String.format(Locale.GERMAN, "Date: %tc", date1), s.get()); + dateV.set(null); + assertEquals("Date: null", s.get()); + dateV.set(date0); + + // test all + s = Bindings.format("%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + doubleV, double1, floatV, float1, longV, long1, intV, int1, booleanV, boolean1, stringV, string1, dateV, date1); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV, floatV, longV, intV, booleanV, stringV, dateV); + assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + double0, double1, float0, float1, long0, long1, int0, int1, boolean0, boolean1, string0, string1, date0, date1), s.get()); + doubleV.set(double1); + floatV.set(float1); + longV.set(long1); + intV.set(int1); + booleanV.set(boolean1); + stringV.set(string1); + dateV.set(date1); + assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, string1, string1, date1, date1), s.get()); + stringV.set(null); + dateV.set(null); + assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %s, %tc", + double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, "null", string1, "null", date1), s.get()); + + // US Locale + Locale.setDefault(Locale.US); + doubleV.set(double0); + floatV.set(float0); + longV.set(long0); + intV.set(int0); + booleanV.set(boolean0); + stringV.set(string0); + dateV.set(date0); + // one object + s = Bindings.format("Date: %tc", date1); + assertEquals(String.format(Locale.US, "Date: %tc", date1), s.get()); + // one variable + s = Bindings.format("Date: %tc", dateV); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); + assertEquals(String.format(Locale.US, "Date: %tc", date0), s.get()); + dateV.set(date1); + assertEquals(String.format(Locale.US, "Date: %tc", date1), s.get()); + dateV.set(null); + assertEquals("Date: null", s.get()); + dateV.set(date0); + + // test all + s = Bindings.format("%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + doubleV, double1, floatV, float1, longV, long1, intV, int1, booleanV, boolean1, stringV, string1, dateV, date1); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV, floatV, longV, intV, booleanV, stringV, dateV); + assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + double0, double1, float0, float1, long0, long1, int0, int1, boolean0, boolean1, string0, string1, date0, date1), s.get()); + doubleV.set(double1); + floatV.set(float1); + longV.set(long1); + intV.set(int1); + booleanV.set(boolean1); + stringV.set(string1); + dateV.set(date1); + assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, string1, string1, date1, date1), s.get()); + stringV.set(null); + dateV.set(null); + assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %s, %tc", + double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, "null", string1, "null", date1), s.get()); + } finally { + Locale.setDefault(defaultLocale); + } + } + + @Test(expected=NullPointerException.class) + public void testConvertWithDefaultLocale_Null() { + Bindings.format(null); + } + + @Test(expected=IllegalFormatException.class) + public void testConvertWithDefaultLocale_IllegalObject() { + Bindings.format("%tc", double0); + } + + @Test(expected=IllegalFormatException.class) + public void testConvertWithDefaultLocale_IllegalValueModel() { + Bindings.format("%tc", doubleV); + } + + @Test + public void testConvertWithCustomLocale() { + // German Locale + // empty + StringExpression s = Bindings.format(Locale.GERMAN, "Empty String"); + assertEquals("Empty String", s.get()); + // one object + s = Bindings.format(Locale.GERMAN, "Date: %tc", date1); + assertEquals(String.format(Locale.GERMAN, "Date: %tc", date1), s.get()); + // one variable + s = Bindings.format(Locale.GERMAN, "Date: %tc", dateV); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); + assertEquals(String.format(Locale.GERMAN, "Date: %tc", date0), s.get()); + dateV.set(date1); + assertEquals(String.format(Locale.GERMAN, "Date: %tc", date1), s.get()); + dateV.set(null); + assertEquals("Date: null", s.get()); + dateV.set(date0); + + // test all + s = Bindings.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + doubleV, double1, floatV, float1, longV, long1, intV, int1, booleanV, boolean1, stringV, string1, dateV, date1); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV, floatV, longV, intV, booleanV, stringV, dateV); + assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + double0, double1, float0, float1, long0, long1, int0, int1, boolean0, boolean1, string0, string1, date0, date1), s.get()); + doubleV.set(double1); + floatV.set(float1); + longV.set(long1); + intV.set(int1); + booleanV.set(boolean1); + stringV.set(string1); + dateV.set(date1); + assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, string1, string1, date1, date1), s.get()); + stringV.set(null); + dateV.set(null); + assertEquals(String.format(Locale.GERMAN, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %s, %tc", + double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, "null", string1, "null", date1), s.get()); + + // US Locale + doubleV.set(double0); + floatV.set(float0); + longV.set(long0); + intV.set(int0); + booleanV.set(boolean0); + stringV.set(string0); + dateV.set(date0); + // empty + s = Bindings.format(Locale.US, "Empty String"); + assertEquals("Empty String", s.get()); + // one object + s = Bindings.format(Locale.US, "Date: %tc", date1); + assertEquals(String.format(Locale.US, "Date: %tc", date1), s.get()); + // one variable + s = Bindings.format(Locale.US, "Date: %tc", dateV); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), dateV); + assertEquals(String.format(Locale.US, "Date: %tc", date0), s.get()); + dateV.set(date1); + assertEquals(String.format(Locale.US, "Date: %tc", date1), s.get()); + dateV.set(null); + assertEquals("Date: null", s.get()); + dateV.set(date0); + + // test all + s = Bindings.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + doubleV, double1, floatV, float1, longV, long1, intV, int1, booleanV, boolean1, stringV, string1, dateV, date1); + DependencyUtils.checkDependencies(((StringBinding)s).getDependencies(), doubleV, floatV, longV, intV, booleanV, stringV, dateV); + assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + double0, double1, float0, float1, long0, long1, int0, int1, boolean0, boolean1, string0, string1, date0, date1), s.get()); + doubleV.set(double1); + floatV.set(float1); + longV.set(long1); + intV.set(int1); + booleanV.set(boolean1); + stringV.set(string1); + dateV.set(date1); + assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %tc, %tc", + double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, string1, string1, date1, date1), s.get()); + stringV.set(null); + dateV.set(null); + assertEquals(String.format(Locale.US, "%8.3e, %8.3e, %6.3f, %6.3f, %d, %d, %d, %d, %s, %s, %s, %s, %s, %tc", + double1, double1, float1, float1, long1, long1, int1, int1, boolean1, boolean1, "null", string1, "null", date1), s.get()); + } + + @Test(expected=NullPointerException.class) + public void testConvertWithCustomLocale_Null() { + Bindings.format(Locale.US, null); + } + + @Test(expected=IllegalFormatException.class) + public void testConvertWithCustomLocale_IllegalObject() { + Bindings.format(Locale.US, "%tc", double0); + } + + @Test(expected=IllegalFormatException.class) + public void testConvertWithCustomLocale_IllegalValueModel() { + Bindings.format(Locale.US, "%tc", doubleV); + } +} --- old/modules/base/src/test/java/com/sun/javafx/collections/ListListenerHelperTest.java 2015-08-31 10:22:57.573217809 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,741 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.collections; - -import com.sun.javafx.binding.ExpressionHelper; - -import javafx.beans.InvalidationListener; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.Observable; -import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener; -import javafx.collections.MockListObserver; -import javafx.collections.ObservableList; - -import org.junit.Before; -import org.junit.Test; - -import java.util.BitSet; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class ListListenerHelperTest { - - private InvalidationListenerMock[] invalidationListenerMock; - - private MockListObserver[] changeListenerMock; - - private ListListenerHelper helper; - - private ObservableList list; - private ListChangeListener.Change change; - - @Before - public void setUp() { - invalidationListenerMock = new InvalidationListenerMock[] { - new InvalidationListenerMock(), - new InvalidationListenerMock(), - new InvalidationListenerMock(), - new InvalidationListenerMock() - }; - changeListenerMock = new MockListObserver[] { - new MockListObserver(), - new MockListObserver(), - new MockListObserver(), - new MockListObserver() - }; - helper = null; - list = FXCollections.emptyObservableList(); - change = new NonIterableChange.SimpleRemovedChange(0, 1, new Object(), list); - } - - private void resetAllListeners() { - for (final InvalidationListenerMock listener : invalidationListenerMock) { - listener.reset(); - } - for (final MockListObserver listener : changeListenerMock) { - listener.clear(); - } - } - - @Test(expected = NullPointerException.class) - public void testAddInvalidationListener_Null() { - ListListenerHelper.addListener(helper, (InvalidationListener)null); - } - - @Test(expected = NullPointerException.class) - public void testRemoveInvalidationListener_Null() { - ListListenerHelper.removeListener(helper, (InvalidationListener) null); - } - - @Test(expected = NullPointerException.class) - public void testRemoveListChangeListener_Null() { - ListListenerHelper.removeListener(helper, (ListChangeListener) null); - } - - @Test(expected = NullPointerException.class) - public void testAddListChangeListener_Null() { - ListListenerHelper.addListener(helper, (ListChangeListener) null); - } - - @Test - public void testEmpty() { - assertFalse(ListListenerHelper.hasListeners(helper)); - - // these should be no-ops - ListListenerHelper.fireValueChangedEvent(helper, change); - ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); - ListListenerHelper.removeListener(helper, changeListenerMock[0]); - } - - @Test - public void testInvalidation_Simple() { - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - - helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[1]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - invalidationListenerMock[1].check(null, 0); - - helper = ListListenerHelper.removeListener(helper, changeListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - changeListenerMock[0].check0(); - - helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - } - - @Test - public void testInvalidation_AddInvalidation() { - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[1]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - invalidationListenerMock[1].check(list, 1); - } - - @Test - public void testInvalidation_AddChange() { - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - changeListenerMock[0].check1(); - } - - @Test - public void testInvalidation_ChangeInPulse() { - final InvalidationListener listener = observable -> { - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - }; - helper = ListListenerHelper.addListener(helper, listener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, listener); - invalidationListenerMock[0].reset(); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - } - - @Test - public void testChange_Simple() { - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - changeListenerMock[0].clear(); - - helper = ListListenerHelper.removeListener(helper, changeListenerMock[1]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - changeListenerMock[1].check0(); - changeListenerMock[0].clear(); - - helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - invalidationListenerMock[0].check(null, 0); - changeListenerMock[0].clear(); - - helper = ListListenerHelper.removeListener(helper, changeListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check0(); - changeListenerMock[0].clear(); - } - - @Test - public void testChange_AddInvalidation() { - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - invalidationListenerMock[0].check(list, 1); - } - - @Test - public void testChange_AddChange() { - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - changeListenerMock[1].check1(); - } - - @Test - public void testChange_ChangeInPulse() { - final ListChangeListener listener = c -> { - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - }; - helper = ListListenerHelper.addListener(helper, listener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, listener); - changeListenerMock[0].clear(); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - } - - @Test - public void testGeneric_AddInvalidation() { - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); - - // first invalidation listener creates the array - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - - // second and third invalidation listener enlarge the array - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[2]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - invalidationListenerMock[1].check(list, 1); - invalidationListenerMock[2].check(list, 1); - - // fourth invalidation listener fits into the array - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[3]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - invalidationListenerMock[1].check(list, 1); - invalidationListenerMock[2].check(list, 1); - invalidationListenerMock[3].check(list, 1); - } - - @Test - public void testGeneric_AddInvalidationInPulse() { - final ListChangeListener addListener = new ListChangeListener() { - int counter; - @Override - public void onChanged(Change c) { - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[counter++]); - } - }; - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - - helper = ListListenerHelper.addListener(helper, addListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(null, 0); - - helper = ListListenerHelper.addListener(helper, addListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - invalidationListenerMock[1].check(list, 1); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(null, 0); - - helper = ListListenerHelper.addListener(helper, addListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - invalidationListenerMock[1].check(list, 1); - invalidationListenerMock[2].check(list, 1); - invalidationListenerMock[3].check(null, 0); - - helper = ListListenerHelper.addListener(helper, addListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - invalidationListenerMock[1].check(list, 1); - invalidationListenerMock[2].check(list, 1); - invalidationListenerMock[3].check(list, 1); - } - - @Test - public void testGeneric_RemoveInvalidation() { - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[2]); - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[3]); - - // remove first element - helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[1].check(list, 1); - invalidationListenerMock[2].check(list, 1); - invalidationListenerMock[3].check(list, 1); - - // remove middle element - helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[2]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[1].check(list, 1); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(list, 1); - - // remove last element - helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[3]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[1].check(list, 1); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(null, 0); - - // remove last invalidation with single change - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[1]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[1].check(null, 0); - changeListenerMock[0].check1(); - changeListenerMock[0].clear(); - - // remove invalidation if array is empty - helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); - helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - changeListenerMock[0].check1(); - changeListenerMock[1].check1(); - changeListenerMock[0].clear(); - changeListenerMock[1].clear(); - - // remove last invalidation with two change - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - changeListenerMock[0].check1(); - changeListenerMock[1].check1(); - } - - - @Test - public void testGeneric_RemoveInvalidationInPulse() { - final ListChangeListener removeListener = new ListChangeListener() { - int counter; - @Override - public void onChanged(Change c) { - helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[counter++]); - } - }; - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[3]); - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[2]); - - helper = ListListenerHelper.addListener(helper, removeListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(list, 1); - invalidationListenerMock[1].check(list, 1); - invalidationListenerMock[2].check(list, 1); - - helper = ListListenerHelper.addListener(helper, removeListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(list, 1); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(list, 1); - - helper = ListListenerHelper.addListener(helper, removeListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(list, 1); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(null, 0); - - helper = ListListenerHelper.addListener(helper, removeListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(null, 0); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(null, 0); - } - - @Test - public void testGeneric_AddChange() { - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - - // first change listener creates the array - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - changeListenerMock[0].clear(); - - // second and third change listener enlarge the array - helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); - helper = ListListenerHelper.addListener(helper, changeListenerMock[2]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - changeListenerMock[1].check1(); - changeListenerMock[2].check1(); - resetAllListeners(); - - // fourth change listener fits into the array - helper = ListListenerHelper.addListener(helper, changeListenerMock[3]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - changeListenerMock[1].check1(); - changeListenerMock[2].check1(); - changeListenerMock[3].check1(); - } - - @Test - public void testGeneric_AddChangeInPulse() { - final InvalidationListener addListener = new InvalidationListener() { - int counter; - @Override - public void invalidated(Observable observable) { - helper = ListListenerHelper.addListener(helper, changeListenerMock[counter++]); - - } - }; - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - - helper = ListListenerHelper.addListener(helper, addListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - changeListenerMock[1].check0(); - changeListenerMock[2].check0(); - changeListenerMock[3].check0(); - - helper = ListListenerHelper.addListener(helper, addListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - changeListenerMock[1].check1(); - changeListenerMock[2].check0(); - changeListenerMock[3].check0(); - - helper = ListListenerHelper.addListener(helper, addListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - changeListenerMock[1].check1(); - changeListenerMock[2].check1(); - changeListenerMock[3].check0(); - - helper = ListListenerHelper.addListener(helper, addListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check1(); - changeListenerMock[1].check1(); - changeListenerMock[2].check1(); - changeListenerMock[3].check1(); - } - - @Test - public void testGeneric_RemoveChange() { - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); - helper = ListListenerHelper.addListener(helper, changeListenerMock[2]); - helper = ListListenerHelper.addListener(helper, changeListenerMock[3]); - - // remove first element - helper = ListListenerHelper.removeListener(helper, changeListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check0(); - changeListenerMock[1].check1(); - changeListenerMock[2].check1(); - changeListenerMock[3].check1(); - resetAllListeners(); - - // remove middle element - helper = ListListenerHelper.removeListener(helper, changeListenerMock[2]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check0(); - changeListenerMock[1].check1(); - changeListenerMock[2].check0(); - changeListenerMock[3].check1(); - resetAllListeners(); - - // remove last element - helper = ListListenerHelper.removeListener(helper, changeListenerMock[3]); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check0(); - changeListenerMock[1].check1(); - changeListenerMock[2].check0(); - changeListenerMock[3].check0(); - resetAllListeners(); - - // remove last change with single invalidation - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = ListListenerHelper.removeListener(helper, changeListenerMock[1]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - changeListenerMock[1].check0(); - changeListenerMock[1].clear(); - - // remove change if array is empty - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = ListListenerHelper.removeListener(helper, changeListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - invalidationListenerMock[1].check(list, 1); - changeListenerMock[0].check0(); - changeListenerMock[0].clear(); - - // remove last change with two invalidation - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - helper = ListListenerHelper.removeListener(helper, changeListenerMock[0]); - ListListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(list, 1); - invalidationListenerMock[1].check(list, 1); - changeListenerMock[0].check0(); - changeListenerMock[0].clear(); - } - - - @Test - public void testGeneric_RemoveChangeInPulse() { - final InvalidationListener removeListener = new InvalidationListener() { - int counter; - @Override - public void invalidated(Observable observable) { - helper = ListListenerHelper.removeListener(helper, changeListenerMock[counter++]); - } - }; - helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); - helper = ListListenerHelper.addListener(helper, changeListenerMock[3]); - helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); - helper = ListListenerHelper.addListener(helper, changeListenerMock[2]); - - helper = ListListenerHelper.addListener(helper, removeListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check0(); - changeListenerMock[3].check1(); - changeListenerMock[1].check1(); - changeListenerMock[2].check1(); - - helper = ListListenerHelper.addListener(helper, removeListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check0(); - changeListenerMock[3].check1(); - changeListenerMock[1].check0(); - changeListenerMock[2].check1(); - - helper = ListListenerHelper.addListener(helper, removeListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check0(); - changeListenerMock[3].check1(); - changeListenerMock[1].check0(); - changeListenerMock[2].check0(); - - helper = ListListenerHelper.addListener(helper, removeListener); - ListListenerHelper.fireValueChangedEvent(helper, change); - helper = ListListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - ListListenerHelper.fireValueChangedEvent(helper, change); - changeListenerMock[0].check0(); - changeListenerMock[3].check0(); - changeListenerMock[1].check0(); - changeListenerMock[2].check0(); - } - - - @Test - public void testExceptionNotPropagatedFromSingleInvalidation() { - helper = ListListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - } - - @Test - public void testExceptionNotPropagatedFromMultipleInvalidation() { - BitSet called = new BitSet(); - - helper = ListListenerHelper.addListener(helper, (Observable o) -> {called.set(0); throw new RuntimeException();}); - helper = ListListenerHelper.addListener(helper, (Observable o) -> {called.set(1); throw new RuntimeException();}); - - helper.fireValueChangedEvent(change); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - } - - @Test - public void testExceptionNotPropagatedFromSingleChange() { - helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> { - throw new RuntimeException(); - }); - helper.fireValueChangedEvent(change); - } - - @Test - public void testExceptionNotPropagatedFromMultipleChange() { - BitSet called = new BitSet(); - - helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); - helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - } - - @Test - public void testExceptionNotPropagatedFromMultipleChangeAndInvalidation() { - BitSet called = new BitSet(); - - helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); - helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); - helper = ListListenerHelper.addListener(helper, (Observable o) -> {called.set(2); throw new RuntimeException();}); - helper = ListListenerHelper.addListener(helper, (Observable o) -> {called.set(3); throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - assertTrue(called.get(2)); - assertTrue(called.get(3)); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInSingleInvalidation() { - AtomicBoolean called = new AtomicBoolean(false); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); - - helper = ListListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get()); - } - - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleInvalidation() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = ListListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); - helper = ListListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertEquals(2, called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInSingleChange() { - AtomicBoolean called = new AtomicBoolean(false); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); - helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleChange() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {throw new RuntimeException();}); - helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertEquals(2, called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleChangeAndInvalidation() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> { throw new RuntimeException();}); - helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> { throw new RuntimeException();}); - helper = ListListenerHelper.addListener(helper, (Observable o) -> { throw new RuntimeException();}); - helper = ListListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertEquals(4, called.get()); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/collections/ListListenerHelperTest.java 2015-08-31 10:22:57.437217811 -0400 @@ -0,0 +1,741 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.collections; + +import com.sun.javafx.collections.ListListenerHelper; +import com.sun.javafx.collections.NonIterableChange; +import javafx.beans.InvalidationListener; +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.Observable; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; +import test.javafx.collections.MockListObserver; +import javafx.collections.ObservableList; + +import org.junit.Before; +import org.junit.Test; + +import java.util.BitSet; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class ListListenerHelperTest { + + private InvalidationListenerMock[] invalidationListenerMock; + + private MockListObserver[] changeListenerMock; + + private ListListenerHelper helper; + + private ObservableList list; + private ListChangeListener.Change change; + + @Before + public void setUp() { + invalidationListenerMock = new InvalidationListenerMock[] { + new InvalidationListenerMock(), + new InvalidationListenerMock(), + new InvalidationListenerMock(), + new InvalidationListenerMock() + }; + changeListenerMock = new MockListObserver[] { + new MockListObserver(), + new MockListObserver(), + new MockListObserver(), + new MockListObserver() + }; + helper = null; + list = FXCollections.emptyObservableList(); + change = new NonIterableChange.SimpleRemovedChange(0, 1, new Object(), list); + } + + private void resetAllListeners() { + for (final InvalidationListenerMock listener : invalidationListenerMock) { + listener.reset(); + } + for (final MockListObserver listener : changeListenerMock) { + listener.clear(); + } + } + + @Test(expected = NullPointerException.class) + public void testAddInvalidationListener_Null() { + ListListenerHelper.addListener(helper, (InvalidationListener)null); + } + + @Test(expected = NullPointerException.class) + public void testRemoveInvalidationListener_Null() { + ListListenerHelper.removeListener(helper, (InvalidationListener) null); + } + + @Test(expected = NullPointerException.class) + public void testRemoveListChangeListener_Null() { + ListListenerHelper.removeListener(helper, (ListChangeListener) null); + } + + @Test(expected = NullPointerException.class) + public void testAddListChangeListener_Null() { + ListListenerHelper.addListener(helper, (ListChangeListener) null); + } + + @Test + public void testEmpty() { + assertFalse(ListListenerHelper.hasListeners(helper)); + + // these should be no-ops + ListListenerHelper.fireValueChangedEvent(helper, change); + ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); + ListListenerHelper.removeListener(helper, changeListenerMock[0]); + } + + @Test + public void testInvalidation_Simple() { + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + + helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[1]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + invalidationListenerMock[1].check(null, 0); + + helper = ListListenerHelper.removeListener(helper, changeListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + changeListenerMock[0].check0(); + + helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + } + + @Test + public void testInvalidation_AddInvalidation() { + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[1]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + invalidationListenerMock[1].check(list, 1); + } + + @Test + public void testInvalidation_AddChange() { + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + changeListenerMock[0].check1(); + } + + @Test + public void testInvalidation_ChangeInPulse() { + final InvalidationListener listener = observable -> { + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + }; + helper = ListListenerHelper.addListener(helper, listener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, listener); + invalidationListenerMock[0].reset(); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + } + + @Test + public void testChange_Simple() { + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + changeListenerMock[0].clear(); + + helper = ListListenerHelper.removeListener(helper, changeListenerMock[1]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + changeListenerMock[1].check0(); + changeListenerMock[0].clear(); + + helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + invalidationListenerMock[0].check(null, 0); + changeListenerMock[0].clear(); + + helper = ListListenerHelper.removeListener(helper, changeListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check0(); + changeListenerMock[0].clear(); + } + + @Test + public void testChange_AddInvalidation() { + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + invalidationListenerMock[0].check(list, 1); + } + + @Test + public void testChange_AddChange() { + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + changeListenerMock[1].check1(); + } + + @Test + public void testChange_ChangeInPulse() { + final ListChangeListener listener = c -> { + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + }; + helper = ListListenerHelper.addListener(helper, listener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, listener); + changeListenerMock[0].clear(); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + } + + @Test + public void testGeneric_AddInvalidation() { + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); + + // first invalidation listener creates the array + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + + // second and third invalidation listener enlarge the array + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[2]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + invalidationListenerMock[1].check(list, 1); + invalidationListenerMock[2].check(list, 1); + + // fourth invalidation listener fits into the array + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[3]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + invalidationListenerMock[1].check(list, 1); + invalidationListenerMock[2].check(list, 1); + invalidationListenerMock[3].check(list, 1); + } + + @Test + public void testGeneric_AddInvalidationInPulse() { + final ListChangeListener addListener = new ListChangeListener() { + int counter; + @Override + public void onChanged(Change c) { + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[counter++]); + } + }; + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + + helper = ListListenerHelper.addListener(helper, addListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(null, 0); + + helper = ListListenerHelper.addListener(helper, addListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + invalidationListenerMock[1].check(list, 1); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(null, 0); + + helper = ListListenerHelper.addListener(helper, addListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + invalidationListenerMock[1].check(list, 1); + invalidationListenerMock[2].check(list, 1); + invalidationListenerMock[3].check(null, 0); + + helper = ListListenerHelper.addListener(helper, addListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + invalidationListenerMock[1].check(list, 1); + invalidationListenerMock[2].check(list, 1); + invalidationListenerMock[3].check(list, 1); + } + + @Test + public void testGeneric_RemoveInvalidation() { + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[2]); + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[3]); + + // remove first element + helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[1].check(list, 1); + invalidationListenerMock[2].check(list, 1); + invalidationListenerMock[3].check(list, 1); + + // remove middle element + helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[2]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[1].check(list, 1); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(list, 1); + + // remove last element + helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[3]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[1].check(list, 1); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(null, 0); + + // remove last invalidation with single change + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[1]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[1].check(null, 0); + changeListenerMock[0].check1(); + changeListenerMock[0].clear(); + + // remove invalidation if array is empty + helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); + helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + changeListenerMock[0].check1(); + changeListenerMock[1].check1(); + changeListenerMock[0].clear(); + changeListenerMock[1].clear(); + + // remove last invalidation with two change + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + changeListenerMock[0].check1(); + changeListenerMock[1].check1(); + } + + + @Test + public void testGeneric_RemoveInvalidationInPulse() { + final ListChangeListener removeListener = new ListChangeListener() { + int counter; + @Override + public void onChanged(Change c) { + helper = ListListenerHelper.removeListener(helper, invalidationListenerMock[counter++]); + } + }; + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[3]); + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[2]); + + helper = ListListenerHelper.addListener(helper, removeListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(list, 1); + invalidationListenerMock[1].check(list, 1); + invalidationListenerMock[2].check(list, 1); + + helper = ListListenerHelper.addListener(helper, removeListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(list, 1); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(list, 1); + + helper = ListListenerHelper.addListener(helper, removeListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(list, 1); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(null, 0); + + helper = ListListenerHelper.addListener(helper, removeListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(null, 0); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(null, 0); + } + + @Test + public void testGeneric_AddChange() { + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + + // first change listener creates the array + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + changeListenerMock[0].clear(); + + // second and third change listener enlarge the array + helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); + helper = ListListenerHelper.addListener(helper, changeListenerMock[2]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + changeListenerMock[1].check1(); + changeListenerMock[2].check1(); + resetAllListeners(); + + // fourth change listener fits into the array + helper = ListListenerHelper.addListener(helper, changeListenerMock[3]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + changeListenerMock[1].check1(); + changeListenerMock[2].check1(); + changeListenerMock[3].check1(); + } + + @Test + public void testGeneric_AddChangeInPulse() { + final InvalidationListener addListener = new InvalidationListener() { + int counter; + @Override + public void invalidated(Observable observable) { + helper = ListListenerHelper.addListener(helper, changeListenerMock[counter++]); + + } + }; + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + + helper = ListListenerHelper.addListener(helper, addListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + changeListenerMock[1].check0(); + changeListenerMock[2].check0(); + changeListenerMock[3].check0(); + + helper = ListListenerHelper.addListener(helper, addListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + changeListenerMock[1].check1(); + changeListenerMock[2].check0(); + changeListenerMock[3].check0(); + + helper = ListListenerHelper.addListener(helper, addListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + changeListenerMock[1].check1(); + changeListenerMock[2].check1(); + changeListenerMock[3].check0(); + + helper = ListListenerHelper.addListener(helper, addListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check1(); + changeListenerMock[1].check1(); + changeListenerMock[2].check1(); + changeListenerMock[3].check1(); + } + + @Test + public void testGeneric_RemoveChange() { + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); + helper = ListListenerHelper.addListener(helper, changeListenerMock[2]); + helper = ListListenerHelper.addListener(helper, changeListenerMock[3]); + + // remove first element + helper = ListListenerHelper.removeListener(helper, changeListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check0(); + changeListenerMock[1].check1(); + changeListenerMock[2].check1(); + changeListenerMock[3].check1(); + resetAllListeners(); + + // remove middle element + helper = ListListenerHelper.removeListener(helper, changeListenerMock[2]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check0(); + changeListenerMock[1].check1(); + changeListenerMock[2].check0(); + changeListenerMock[3].check1(); + resetAllListeners(); + + // remove last element + helper = ListListenerHelper.removeListener(helper, changeListenerMock[3]); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check0(); + changeListenerMock[1].check1(); + changeListenerMock[2].check0(); + changeListenerMock[3].check0(); + resetAllListeners(); + + // remove last change with single invalidation + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = ListListenerHelper.removeListener(helper, changeListenerMock[1]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + changeListenerMock[1].check0(); + changeListenerMock[1].clear(); + + // remove change if array is empty + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = ListListenerHelper.removeListener(helper, changeListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + invalidationListenerMock[1].check(list, 1); + changeListenerMock[0].check0(); + changeListenerMock[0].clear(); + + // remove last change with two invalidation + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + helper = ListListenerHelper.removeListener(helper, changeListenerMock[0]); + ListListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(list, 1); + invalidationListenerMock[1].check(list, 1); + changeListenerMock[0].check0(); + changeListenerMock[0].clear(); + } + + + @Test + public void testGeneric_RemoveChangeInPulse() { + final InvalidationListener removeListener = new InvalidationListener() { + int counter; + @Override + public void invalidated(Observable observable) { + helper = ListListenerHelper.removeListener(helper, changeListenerMock[counter++]); + } + }; + helper = ListListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = ListListenerHelper.addListener(helper, changeListenerMock[0]); + helper = ListListenerHelper.addListener(helper, changeListenerMock[3]); + helper = ListListenerHelper.addListener(helper, changeListenerMock[1]); + helper = ListListenerHelper.addListener(helper, changeListenerMock[2]); + + helper = ListListenerHelper.addListener(helper, removeListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check0(); + changeListenerMock[3].check1(); + changeListenerMock[1].check1(); + changeListenerMock[2].check1(); + + helper = ListListenerHelper.addListener(helper, removeListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check0(); + changeListenerMock[3].check1(); + changeListenerMock[1].check0(); + changeListenerMock[2].check1(); + + helper = ListListenerHelper.addListener(helper, removeListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check0(); + changeListenerMock[3].check1(); + changeListenerMock[1].check0(); + changeListenerMock[2].check0(); + + helper = ListListenerHelper.addListener(helper, removeListener); + ListListenerHelper.fireValueChangedEvent(helper, change); + helper = ListListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + ListListenerHelper.fireValueChangedEvent(helper, change); + changeListenerMock[0].check0(); + changeListenerMock[3].check0(); + changeListenerMock[1].check0(); + changeListenerMock[2].check0(); + } + + + @Test + public void testExceptionNotPropagatedFromSingleInvalidation() { + helper = ListListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); + ListListenerHelper.fireValueChangedEvent(helper, change); + } + + @Test + public void testExceptionNotPropagatedFromMultipleInvalidation() { + BitSet called = new BitSet(); + + helper = ListListenerHelper.addListener(helper, (Observable o) -> {called.set(0); throw new RuntimeException();}); + helper = ListListenerHelper.addListener(helper, (Observable o) -> {called.set(1); throw new RuntimeException();}); + + ListListenerHelper.fireValueChangedEvent(helper, change); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + } + + @Test + public void testExceptionNotPropagatedFromSingleChange() { + helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> { + throw new RuntimeException(); + }); + ListListenerHelper.fireValueChangedEvent(helper, change); + } + + @Test + public void testExceptionNotPropagatedFromMultipleChange() { + BitSet called = new BitSet(); + + helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); + helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); + ListListenerHelper.fireValueChangedEvent(helper, change); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + } + + @Test + public void testExceptionNotPropagatedFromMultipleChangeAndInvalidation() { + BitSet called = new BitSet(); + + helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); + helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); + helper = ListListenerHelper.addListener(helper, (Observable o) -> {called.set(2); throw new RuntimeException();}); + helper = ListListenerHelper.addListener(helper, (Observable o) -> {called.set(3); throw new RuntimeException();}); + ListListenerHelper.fireValueChangedEvent(helper, change); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + assertTrue(called.get(2)); + assertTrue(called.get(3)); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInSingleInvalidation() { + AtomicBoolean called = new AtomicBoolean(false); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); + + helper = ListListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); + ListListenerHelper.fireValueChangedEvent(helper, change); + + assertTrue(called.get()); + } + + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleInvalidation() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = ListListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); + helper = ListListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); + ListListenerHelper.fireValueChangedEvent(helper, change); + + assertEquals(2, called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInSingleChange() { + AtomicBoolean called = new AtomicBoolean(false); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); + helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {throw new RuntimeException();}); + ListListenerHelper.fireValueChangedEvent(helper, change); + + assertTrue(called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleChange() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {throw new RuntimeException();}); + helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> {throw new RuntimeException();}); + ListListenerHelper.fireValueChangedEvent(helper, change); + + assertEquals(2, called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleChangeAndInvalidation() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> { throw new RuntimeException();}); + helper = ListListenerHelper.addListener(helper, (ListChangeListener.Change c) -> { throw new RuntimeException();}); + helper = ListListenerHelper.addListener(helper, (Observable o) -> { throw new RuntimeException();}); + helper = ListListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); + ListListenerHelper.fireValueChangedEvent(helper, change); + + assertEquals(4, called.get()); + } + +} --- old/modules/base/src/test/java/com/sun/javafx/collections/MapListenerHelperTest.java 2015-08-31 10:22:58.209217802 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,740 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.collections; - -import com.sun.javafx.binding.MapExpressionHelper; - -import javafx.beans.InvalidationListener; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.Observable; -import javafx.collections.*; - -import org.junit.Before; -import org.junit.Test; - -import java.util.BitSet; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class MapListenerHelperTest { - - private InvalidationListenerMock[] invalidationListenerMock; - - private MockMapObserver[] changeListenerMock; - - private MapListenerHelper helper; - - private ObservableMap map; - private MapChangeListener.Change change; - - @Before - public void setUp() { - invalidationListenerMock = new InvalidationListenerMock[] { - new InvalidationListenerMock(), - new InvalidationListenerMock(), - new InvalidationListenerMock(), - new InvalidationListenerMock() - }; - changeListenerMock = new MockMapObserver[] { - new MockMapObserver(), - new MockMapObserver(), - new MockMapObserver(), - new MockMapObserver() - }; - helper = null; - map = FXCollections.observableHashMap(); - change = new MapExpressionHelper.SimpleChange(map).setRemoved(new Object(), new Object()); - } - - private void resetAllListeners() { - for (final InvalidationListenerMock listener : invalidationListenerMock) { - listener.reset(); - } - for (final MockMapObserver listener : changeListenerMock) { - listener.clear(); - } - } - - @Test(expected = NullPointerException.class) - public void testAddInvalidationListener_Null() { - MapListenerHelper.addListener(helper, (InvalidationListener)null); - } - - @Test(expected = NullPointerException.class) - public void testRemoveInvalidationListener_Null() { - MapListenerHelper.removeListener(helper, (InvalidationListener) null); - } - - @Test(expected = NullPointerException.class) - public void testRemoveMapChangeListener_Null() { - MapListenerHelper.removeListener(helper, (MapChangeListener) null); - } - - @Test(expected = NullPointerException.class) - public void testAddMapChangeListener_Null() { - MapListenerHelper.addListener(helper, (MapChangeListener) null); - } - - @Test - public void testEmpty() { - assertFalse(MapListenerHelper.hasListeners(helper)); - - // these should be no-ops - MapListenerHelper.fireValueChangedEvent(helper, change); - MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); - MapListenerHelper.removeListener(helper, changeListenerMock[0]); - } - - @Test - public void testInvalidation_Simple() { - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - - helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[1]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - invalidationListenerMock[1].check(null, 0); - - helper = MapListenerHelper.removeListener(helper, changeListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - - helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - } - - @Test - public void testInvalidation_AddInvalidation() { - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[1]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - invalidationListenerMock[1].check(map, 1); - } - - @Test - public void testInvalidation_AddChange() { - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - } - - @Test - public void testInvalidation_ChangeInPulse() { - final InvalidationListener listener = observable -> { - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - }; - helper = MapListenerHelper.addListener(helper, listener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, listener); - invalidationListenerMock[0].reset(); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - } - - @Test - public void testChange_Simple() { - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - - helper = MapListenerHelper.removeListener(helper, changeListenerMock[1]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - changeListenerMock[0].clear(); - - helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - invalidationListenerMock[0].check(null, 0); - changeListenerMock[0].clear(); - - helper = MapListenerHelper.removeListener(helper, changeListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - } - - @Test - public void testChange_AddInvalidation() { - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - invalidationListenerMock[0].check(map, 1); - } - - @Test - public void testChange_AddChange() { - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - } - - @Test - public void testChange_ChangeInPulse() { - final MapChangeListener listener = change1 -> { - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - }; - helper = MapListenerHelper.addListener(helper, listener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, listener); - changeListenerMock[0].clear(); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - } - - @Test - public void testGeneric_AddInvalidation() { - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); - - // first invalidation listener creates the array - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - - // second and third invalidation listener enlarge the array - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[2]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - invalidationListenerMock[1].check(map, 1); - invalidationListenerMock[2].check(map, 1); - - // fourth invalidation listener fits into the array - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[3]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - invalidationListenerMock[1].check(map, 1); - invalidationListenerMock[2].check(map, 1); - invalidationListenerMock[3].check(map, 1); - } - - @Test - public void testGeneric_AddInvalidationInPulse() { - final MapChangeListener addListener = new MapChangeListener() { - int counter; - @Override - public void onChanged(Change change) { - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[counter++]); - } - }; - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - - helper = MapListenerHelper.addListener(helper, addListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(null, 0); - - helper = MapListenerHelper.addListener(helper, addListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - invalidationListenerMock[1].check(map, 1); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(null, 0); - - helper = MapListenerHelper.addListener(helper, addListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - invalidationListenerMock[1].check(map, 1); - invalidationListenerMock[2].check(map, 1); - invalidationListenerMock[3].check(null, 0); - - helper = MapListenerHelper.addListener(helper, addListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - invalidationListenerMock[1].check(map, 1); - invalidationListenerMock[2].check(map, 1); - invalidationListenerMock[3].check(map, 1); - } - - @Test - public void testGeneric_RemoveInvalidation() { - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[2]); - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[3]); - - // remove first element - helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[1].check(map, 1); - invalidationListenerMock[2].check(map, 1); - invalidationListenerMock[3].check(map, 1); - - // remove middle element - helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[2]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[1].check(map, 1); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(map, 1); - - // remove last element - helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[3]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[1].check(map, 1); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(null, 0); - - // remove last invalidation with single change - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[1]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[1].check(null, 0); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - - // remove invalidation if array is empty - helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); - helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - changeListenerMock[0].clear(); - changeListenerMock[1].clear(); - - // remove last invalidation with two change - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - } - - - @Test - public void testGeneric_RemoveInvalidationInPulse() { - final MapChangeListener removeListener = new MapChangeListener() { - int counter; - @Override - public void onChanged(Change change) { - helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[counter++]); - } - }; - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[3]); - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[2]); - - helper = MapListenerHelper.addListener(helper, removeListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(map, 1); - invalidationListenerMock[1].check(map, 1); - invalidationListenerMock[2].check(map, 1); - - helper = MapListenerHelper.addListener(helper, removeListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(map, 1); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(map, 1); - - helper = MapListenerHelper.addListener(helper, removeListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(map, 1); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(null, 0); - - helper = MapListenerHelper.addListener(helper, removeListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(null, 0); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(null, 0); - } - - @Test - public void testGeneric_AddChange() { - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - - // first change listener creates the array - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - - // second and third change listener enlarge the array - helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); - helper = MapListenerHelper.addListener(helper, changeListenerMock[2]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - resetAllListeners(); - - // fourth change listener fits into the array - helper = MapListenerHelper.addListener(helper, changeListenerMock[3]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - } - - @Test - public void testGeneric_AddChangeInPulse() { - final InvalidationListener addListener = new InvalidationListener() { - int counter; - @Override - public void invalidated(Observable observable) { - helper = MapListenerHelper.addListener(helper, changeListenerMock[counter++]); - - } - }; - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - - helper = MapListenerHelper.addListener(helper, addListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - assertEquals(0, changeListenerMock[3].getCallsNumber()); - - helper = MapListenerHelper.addListener(helper, addListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - assertEquals(0, changeListenerMock[3].getCallsNumber()); - - helper = MapListenerHelper.addListener(helper, addListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - assertEquals(0, changeListenerMock[3].getCallsNumber()); - - helper = MapListenerHelper.addListener(helper, addListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - } - - @Test - public void testGeneric_RemoveChange() { - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); - helper = MapListenerHelper.addListener(helper, changeListenerMock[2]); - helper = MapListenerHelper.addListener(helper, changeListenerMock[3]); - - // remove first element - helper = MapListenerHelper.removeListener(helper, changeListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - resetAllListeners(); - - // remove middle element - helper = MapListenerHelper.removeListener(helper, changeListenerMock[2]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - resetAllListeners(); - - // remove last element - helper = MapListenerHelper.removeListener(helper, changeListenerMock[3]); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - assertEquals(0, changeListenerMock[3].getCallsNumber()); - resetAllListeners(); - - // remove last change with single invalidation - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = MapListenerHelper.removeListener(helper, changeListenerMock[1]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - changeListenerMock[1].clear(); - - // remove change if array is empty - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = MapListenerHelper.removeListener(helper, changeListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - invalidationListenerMock[1].check(map, 1); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - - // remove last change with two invalidation - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - helper = MapListenerHelper.removeListener(helper, changeListenerMock[0]); - MapListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(map, 1); - invalidationListenerMock[1].check(map, 1); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - } - - - @Test - public void testGeneric_RemoveChangeInPulse() { - final InvalidationListener removeListener = new InvalidationListener() { - int counter; - @Override - public void invalidated(Observable observable) { - helper = MapListenerHelper.removeListener(helper, changeListenerMock[counter++]); - } - }; - helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); - helper = MapListenerHelper.addListener(helper, changeListenerMock[3]); - helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); - helper = MapListenerHelper.addListener(helper, changeListenerMock[2]); - - helper = MapListenerHelper.addListener(helper, removeListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - - helper = MapListenerHelper.addListener(helper, removeListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - - helper = MapListenerHelper.addListener(helper, removeListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - - helper = MapListenerHelper.addListener(helper, removeListener); - MapListenerHelper.fireValueChangedEvent(helper, change); - helper = MapListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - MapListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(0, changeListenerMock[3].getCallsNumber()); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - } - - - - @Test - public void testExceptionNotPropagatedFromSingleInvalidation() { - helper = MapListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - } - - @Test - public void testExceptionNotPropagatedFromMultipleInvalidation() { - BitSet called = new BitSet(); - - helper = MapListenerHelper.addListener(helper, (Observable o) -> {called.set(0); throw new RuntimeException();}); - helper = MapListenerHelper.addListener(helper, (Observable o) -> {called.set(1); throw new RuntimeException();}); - - helper.fireValueChangedEvent(change); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - } - - @Test - public void testExceptionNotPropagatedFromSingleChange() { - helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> { - throw new RuntimeException(); - }); - helper.fireValueChangedEvent(change); - } - - @Test - public void testExceptionNotPropagatedFromMultipleChange() { - BitSet called = new BitSet(); - - helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); - helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - } - - @Test - public void testExceptionNotPropagatedFromMultipleChangeAndInvalidation() { - BitSet called = new BitSet(); - - helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); - helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); - helper = MapListenerHelper.addListener(helper, (Observable o) -> {called.set(2); throw new RuntimeException();}); - helper = MapListenerHelper.addListener(helper, (Observable o) -> {called.set(3); throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - assertTrue(called.get(2)); - assertTrue(called.get(3)); - } - - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInSingleInvalidation() { - AtomicBoolean called = new AtomicBoolean(false); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); - - helper = MapListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get()); - } - - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleInvalidation() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = MapListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); - helper = MapListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertEquals(2, called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInSingleChange() { - AtomicBoolean called = new AtomicBoolean(false); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); - helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleChange() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {throw new RuntimeException();}); - helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertEquals(2, called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleChangeAndInvalidation() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> { throw new RuntimeException();}); - helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> { throw new RuntimeException();}); - helper = MapListenerHelper.addListener(helper, (Observable o) -> { throw new RuntimeException();}); - helper = MapListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertEquals(4, called.get()); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/collections/MapListenerHelperTest.java 2015-08-31 10:22:58.073217804 -0400 @@ -0,0 +1,742 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.collections; + +import test.javafx.collections.MockMapObserver; +import com.sun.javafx.binding.MapExpressionHelper; +import com.sun.javafx.collections.MapListenerHelper; + +import javafx.beans.InvalidationListener; +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.Observable; +import javafx.collections.*; + +import org.junit.Before; +import org.junit.Test; + +import java.util.BitSet; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class MapListenerHelperTest { + + private InvalidationListenerMock[] invalidationListenerMock; + + private MockMapObserver[] changeListenerMock; + + private MapListenerHelper helper; + + private ObservableMap map; + private MapChangeListener.Change change; + + @Before + public void setUp() { + invalidationListenerMock = new InvalidationListenerMock[] { + new InvalidationListenerMock(), + new InvalidationListenerMock(), + new InvalidationListenerMock(), + new InvalidationListenerMock() + }; + changeListenerMock = new MockMapObserver[] { + new MockMapObserver(), + new MockMapObserver(), + new MockMapObserver(), + new MockMapObserver() + }; + helper = null; + map = FXCollections.observableHashMap(); + change = new MapExpressionHelper.SimpleChange(map).setRemoved(new Object(), new Object()); + } + + private void resetAllListeners() { + for (final InvalidationListenerMock listener : invalidationListenerMock) { + listener.reset(); + } + for (final MockMapObserver listener : changeListenerMock) { + listener.clear(); + } + } + + @Test(expected = NullPointerException.class) + public void testAddInvalidationListener_Null() { + MapListenerHelper.addListener(helper, (InvalidationListener)null); + } + + @Test(expected = NullPointerException.class) + public void testRemoveInvalidationListener_Null() { + MapListenerHelper.removeListener(helper, (InvalidationListener) null); + } + + @Test(expected = NullPointerException.class) + public void testRemoveMapChangeListener_Null() { + MapListenerHelper.removeListener(helper, (MapChangeListener) null); + } + + @Test(expected = NullPointerException.class) + public void testAddMapChangeListener_Null() { + MapListenerHelper.addListener(helper, (MapChangeListener) null); + } + + @Test + public void testEmpty() { + assertFalse(MapListenerHelper.hasListeners(helper)); + + // these should be no-ops + MapListenerHelper.fireValueChangedEvent(helper, change); + MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); + MapListenerHelper.removeListener(helper, changeListenerMock[0]); + } + + @Test + public void testInvalidation_Simple() { + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + + helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[1]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + invalidationListenerMock[1].check(null, 0); + + helper = MapListenerHelper.removeListener(helper, changeListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + + helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + } + + @Test + public void testInvalidation_AddInvalidation() { + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[1]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + invalidationListenerMock[1].check(map, 1); + } + + @Test + public void testInvalidation_AddChange() { + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + } + + @Test + public void testInvalidation_ChangeInPulse() { + final InvalidationListener listener = observable -> { + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + }; + helper = MapListenerHelper.addListener(helper, listener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, listener); + invalidationListenerMock[0].reset(); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + } + + @Test + public void testChange_Simple() { + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + + helper = MapListenerHelper.removeListener(helper, changeListenerMock[1]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + changeListenerMock[0].clear(); + + helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + invalidationListenerMock[0].check(null, 0); + changeListenerMock[0].clear(); + + helper = MapListenerHelper.removeListener(helper, changeListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + } + + @Test + public void testChange_AddInvalidation() { + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + invalidationListenerMock[0].check(map, 1); + } + + @Test + public void testChange_AddChange() { + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + } + + @Test + public void testChange_ChangeInPulse() { + final MapChangeListener listener = change1 -> { + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + }; + helper = MapListenerHelper.addListener(helper, listener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, listener); + changeListenerMock[0].clear(); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + } + + @Test + public void testGeneric_AddInvalidation() { + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); + + // first invalidation listener creates the array + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + + // second and third invalidation listener enlarge the array + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[2]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + invalidationListenerMock[1].check(map, 1); + invalidationListenerMock[2].check(map, 1); + + // fourth invalidation listener fits into the array + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[3]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + invalidationListenerMock[1].check(map, 1); + invalidationListenerMock[2].check(map, 1); + invalidationListenerMock[3].check(map, 1); + } + + @Test + public void testGeneric_AddInvalidationInPulse() { + final MapChangeListener addListener = new MapChangeListener() { + int counter; + @Override + public void onChanged(Change change) { + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[counter++]); + } + }; + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + + helper = MapListenerHelper.addListener(helper, addListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(null, 0); + + helper = MapListenerHelper.addListener(helper, addListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + invalidationListenerMock[1].check(map, 1); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(null, 0); + + helper = MapListenerHelper.addListener(helper, addListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + invalidationListenerMock[1].check(map, 1); + invalidationListenerMock[2].check(map, 1); + invalidationListenerMock[3].check(null, 0); + + helper = MapListenerHelper.addListener(helper, addListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + invalidationListenerMock[1].check(map, 1); + invalidationListenerMock[2].check(map, 1); + invalidationListenerMock[3].check(map, 1); + } + + @Test + public void testGeneric_RemoveInvalidation() { + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[2]); + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[3]); + + // remove first element + helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[1].check(map, 1); + invalidationListenerMock[2].check(map, 1); + invalidationListenerMock[3].check(map, 1); + + // remove middle element + helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[2]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[1].check(map, 1); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(map, 1); + + // remove last element + helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[3]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[1].check(map, 1); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(null, 0); + + // remove last invalidation with single change + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[1]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[1].check(null, 0); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + + // remove invalidation if array is empty + helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); + helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + changeListenerMock[0].clear(); + changeListenerMock[1].clear(); + + // remove last invalidation with two change + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + } + + + @Test + public void testGeneric_RemoveInvalidationInPulse() { + final MapChangeListener removeListener = new MapChangeListener() { + int counter; + @Override + public void onChanged(Change change) { + helper = MapListenerHelper.removeListener(helper, invalidationListenerMock[counter++]); + } + }; + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[3]); + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[2]); + + helper = MapListenerHelper.addListener(helper, removeListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(map, 1); + invalidationListenerMock[1].check(map, 1); + invalidationListenerMock[2].check(map, 1); + + helper = MapListenerHelper.addListener(helper, removeListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(map, 1); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(map, 1); + + helper = MapListenerHelper.addListener(helper, removeListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(map, 1); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(null, 0); + + helper = MapListenerHelper.addListener(helper, removeListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(null, 0); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(null, 0); + } + + @Test + public void testGeneric_AddChange() { + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + + // first change listener creates the array + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + + // second and third change listener enlarge the array + helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); + helper = MapListenerHelper.addListener(helper, changeListenerMock[2]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + resetAllListeners(); + + // fourth change listener fits into the array + helper = MapListenerHelper.addListener(helper, changeListenerMock[3]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + } + + @Test + public void testGeneric_AddChangeInPulse() { + final InvalidationListener addListener = new InvalidationListener() { + int counter; + @Override + public void invalidated(Observable observable) { + helper = MapListenerHelper.addListener(helper, changeListenerMock[counter++]); + + } + }; + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + + helper = MapListenerHelper.addListener(helper, addListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + assertEquals(0, changeListenerMock[3].getCallsNumber()); + + helper = MapListenerHelper.addListener(helper, addListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + assertEquals(0, changeListenerMock[3].getCallsNumber()); + + helper = MapListenerHelper.addListener(helper, addListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + assertEquals(0, changeListenerMock[3].getCallsNumber()); + + helper = MapListenerHelper.addListener(helper, addListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + } + + @Test + public void testGeneric_RemoveChange() { + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); + helper = MapListenerHelper.addListener(helper, changeListenerMock[2]); + helper = MapListenerHelper.addListener(helper, changeListenerMock[3]); + + // remove first element + helper = MapListenerHelper.removeListener(helper, changeListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + resetAllListeners(); + + // remove middle element + helper = MapListenerHelper.removeListener(helper, changeListenerMock[2]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + resetAllListeners(); + + // remove last element + helper = MapListenerHelper.removeListener(helper, changeListenerMock[3]); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + assertEquals(0, changeListenerMock[3].getCallsNumber()); + resetAllListeners(); + + // remove last change with single invalidation + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = MapListenerHelper.removeListener(helper, changeListenerMock[1]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + changeListenerMock[1].clear(); + + // remove change if array is empty + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = MapListenerHelper.removeListener(helper, changeListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + invalidationListenerMock[1].check(map, 1); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + + // remove last change with two invalidation + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + helper = MapListenerHelper.removeListener(helper, changeListenerMock[0]); + MapListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(map, 1); + invalidationListenerMock[1].check(map, 1); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + } + + + @Test + public void testGeneric_RemoveChangeInPulse() { + final InvalidationListener removeListener = new InvalidationListener() { + int counter; + @Override + public void invalidated(Observable observable) { + helper = MapListenerHelper.removeListener(helper, changeListenerMock[counter++]); + } + }; + helper = MapListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = MapListenerHelper.addListener(helper, changeListenerMock[0]); + helper = MapListenerHelper.addListener(helper, changeListenerMock[3]); + helper = MapListenerHelper.addListener(helper, changeListenerMock[1]); + helper = MapListenerHelper.addListener(helper, changeListenerMock[2]); + + helper = MapListenerHelper.addListener(helper, removeListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + + helper = MapListenerHelper.addListener(helper, removeListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + + helper = MapListenerHelper.addListener(helper, removeListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + + helper = MapListenerHelper.addListener(helper, removeListener); + MapListenerHelper.fireValueChangedEvent(helper, change); + helper = MapListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + MapListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(0, changeListenerMock[3].getCallsNumber()); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + } + + + + @Test + public void testExceptionNotPropagatedFromSingleInvalidation() { + helper = MapListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); + MapListenerHelper.fireValueChangedEvent(helper, change); + } + + @Test + public void testExceptionNotPropagatedFromMultipleInvalidation() { + BitSet called = new BitSet(); + + helper = MapListenerHelper.addListener(helper, (Observable o) -> {called.set(0); throw new RuntimeException();}); + helper = MapListenerHelper.addListener(helper, (Observable o) -> {called.set(1); throw new RuntimeException();}); + + MapListenerHelper.fireValueChangedEvent(helper, change); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + } + + @Test + public void testExceptionNotPropagatedFromSingleChange() { + helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> { + throw new RuntimeException(); + }); + MapListenerHelper.fireValueChangedEvent(helper, change); + } + + @Test + public void testExceptionNotPropagatedFromMultipleChange() { + BitSet called = new BitSet(); + + helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); + helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); + MapListenerHelper.fireValueChangedEvent(helper, change); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + } + + @Test + public void testExceptionNotPropagatedFromMultipleChangeAndInvalidation() { + BitSet called = new BitSet(); + + helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); + helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); + helper = MapListenerHelper.addListener(helper, (Observable o) -> {called.set(2); throw new RuntimeException();}); + helper = MapListenerHelper.addListener(helper, (Observable o) -> {called.set(3); throw new RuntimeException();}); + MapListenerHelper.fireValueChangedEvent(helper, change); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + assertTrue(called.get(2)); + assertTrue(called.get(3)); + } + + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInSingleInvalidation() { + AtomicBoolean called = new AtomicBoolean(false); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); + + helper = MapListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); + MapListenerHelper.fireValueChangedEvent(helper, change); + + assertTrue(called.get()); + } + + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleInvalidation() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = MapListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); + helper = MapListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); + MapListenerHelper.fireValueChangedEvent(helper, change); + + assertEquals(2, called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInSingleChange() { + AtomicBoolean called = new AtomicBoolean(false); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); + helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {throw new RuntimeException();}); + MapListenerHelper.fireValueChangedEvent(helper, change); + + assertTrue(called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleChange() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {throw new RuntimeException();}); + helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> {throw new RuntimeException();}); + MapListenerHelper.fireValueChangedEvent(helper, change); + + assertEquals(2, called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleChangeAndInvalidation() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> { throw new RuntimeException();}); + helper = MapListenerHelper.addListener(helper, (MapChangeListener.Change c) -> { throw new RuntimeException();}); + helper = MapListenerHelper.addListener(helper, (Observable o) -> { throw new RuntimeException();}); + helper = MapListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); + MapListenerHelper.fireValueChangedEvent(helper, change); + + assertEquals(4, called.get()); + } + +} --- old/modules/base/src/test/java/com/sun/javafx/collections/MappingChangeTest.java 2015-08-31 10:22:58.801217796 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.javafx.collections; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener.Change; -import javafx.collections.ObservableList; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -public class MappingChangeTest { - - ObservableList originalList; - ObservableList list; - - @Before - public void setUp() { - originalList = FXCollections.observableArrayList(1, 2, 3, 4, 5); - list = FXCollections.observableArrayList("1", "2", "3", "4", "5"); - } - - @Test - public void testAddRemove() { - Change change = new NonIterableChange.SimpleRemovedChange(0, 1, new Integer(5), originalList); - MappingChange mapChange = new MappingChange(change, - e -> e.toString(), list); - - assertTrue(mapChange.next()); - assertEquals(0, mapChange.getFrom()); - assertEquals(1, mapChange.getTo()); - assertEquals(Arrays.asList("5"), mapChange.getRemoved()); - assertNotNull(mapChange.toString()); - - assertFalse(mapChange.next()); - } - - @Test - public void testUpdate() { - Change change = new NonIterableChange.SimpleUpdateChange(0, 1, originalList); - MappingChange mapChange = new MappingChange(change, - e -> e.toString(), list); - - assertTrue(mapChange.next()); - assertEquals(0, mapChange.getFrom()); - assertEquals(1, mapChange.getTo()); - assertTrue(mapChange.wasUpdated()); - assertNotNull(mapChange.toString()); - - assertFalse(mapChange.next()); - } - - @Test - public void testPermutation() { - Change change = new NonIterableChange.SimplePermutationChange(0, 2, new int[] {1, 0}, originalList); - MappingChange mapChange = new MappingChange(change, - e -> e.toString(), list); - - assertTrue(mapChange.next()); - assertEquals(0, mapChange.getFrom()); - assertEquals(2, mapChange.getTo()); - assertTrue(mapChange.wasPermutated()); - assertNotNull(mapChange.toString()); - - assertFalse(mapChange.next()); - } - - @Test - public void testComplex() { - Change change = new Change(originalList) { - int[][] added= new int[][]{ new int[] {0, 1}, new int[] {2, 3}, new int[] {4, 5}}; - - int pointer = -1; - - @Override - public boolean next() { - if (pointer == added.length - 1) { - return false; - } - ++pointer; - return true; - } - - @Override - public void reset() { - pointer = -1; - } - - @Override - public int getFrom() { - return added[pointer][0]; - } - - @Override - public int getTo() { - return added[pointer][1]; - } - - @Override - public List getRemoved() { - return Collections.EMPTY_LIST; - } - - @Override - protected int[] getPermutation() { - return new int[0]; - } - }; - MappingChange mapChange = new MappingChange(change, - e -> e.toString(), list); - - assertTrue(mapChange.next()); - assertEquals(0, mapChange.getFrom()); - assertEquals(1, mapChange.getTo()); - assertTrue(mapChange.wasAdded()); - assertNotNull(mapChange.toString()); - - assertTrue(mapChange.next()); - assertEquals(2, mapChange.getFrom()); - assertEquals(3, mapChange.getTo()); - assertTrue(mapChange.wasAdded()); - assertNotNull(mapChange.toString()); - - assertTrue(mapChange.next()); - assertEquals(4, mapChange.getFrom()); - assertEquals(5, mapChange.getTo()); - assertTrue(mapChange.wasAdded()); - assertNotNull(mapChange.toString()); - - assertFalse(mapChange.next()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/collections/MappingChangeTest.java 2015-08-31 10:22:58.665217797 -0400 @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.com.sun.javafx.collections; + +import com.sun.javafx.collections.MappingChange; +import com.sun.javafx.collections.NonIterableChange; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener.Change; +import javafx.collections.ObservableList; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +public class MappingChangeTest { + + ObservableList originalList; + ObservableList list; + + @Before + public void setUp() { + originalList = FXCollections.observableArrayList(1, 2, 3, 4, 5); + list = FXCollections.observableArrayList("1", "2", "3", "4", "5"); + } + + @Test + public void testAddRemove() { + Change change = new NonIterableChange.SimpleRemovedChange(0, 1, new Integer(5), originalList); + MappingChange mapChange = new MappingChange(change, + e -> e.toString(), list); + + assertTrue(mapChange.next()); + assertEquals(0, mapChange.getFrom()); + assertEquals(1, mapChange.getTo()); + assertEquals(Arrays.asList("5"), mapChange.getRemoved()); + assertNotNull(mapChange.toString()); + + assertFalse(mapChange.next()); + } + + @Test + public void testUpdate() { + Change change = new NonIterableChange.SimpleUpdateChange(0, 1, originalList); + MappingChange mapChange = new MappingChange(change, + e -> e.toString(), list); + + assertTrue(mapChange.next()); + assertEquals(0, mapChange.getFrom()); + assertEquals(1, mapChange.getTo()); + assertTrue(mapChange.wasUpdated()); + assertNotNull(mapChange.toString()); + + assertFalse(mapChange.next()); + } + + @Test + public void testPermutation() { + Change change = new NonIterableChange.SimplePermutationChange(0, 2, new int[] {1, 0}, originalList); + MappingChange mapChange = new MappingChange(change, + e -> e.toString(), list); + + assertTrue(mapChange.next()); + assertEquals(0, mapChange.getFrom()); + assertEquals(2, mapChange.getTo()); + assertTrue(mapChange.wasPermutated()); + assertNotNull(mapChange.toString()); + + assertFalse(mapChange.next()); + } + + @Test + public void testComplex() { + Change change = new Change(originalList) { + int[][] added= new int[][]{ new int[] {0, 1}, new int[] {2, 3}, new int[] {4, 5}}; + + int pointer = -1; + + @Override + public boolean next() { + if (pointer == added.length - 1) { + return false; + } + ++pointer; + return true; + } + + @Override + public void reset() { + pointer = -1; + } + + @Override + public int getFrom() { + return added[pointer][0]; + } + + @Override + public int getTo() { + return added[pointer][1]; + } + + @Override + public List getRemoved() { + return Collections.EMPTY_LIST; + } + + @Override + protected int[] getPermutation() { + return new int[0]; + } + }; + MappingChange mapChange = new MappingChange(change, + e -> e.toString(), list); + + assertTrue(mapChange.next()); + assertEquals(0, mapChange.getFrom()); + assertEquals(1, mapChange.getTo()); + assertTrue(mapChange.wasAdded()); + assertNotNull(mapChange.toString()); + + assertTrue(mapChange.next()); + assertEquals(2, mapChange.getFrom()); + assertEquals(3, mapChange.getTo()); + assertTrue(mapChange.wasAdded()); + assertNotNull(mapChange.toString()); + + assertTrue(mapChange.next()); + assertEquals(4, mapChange.getFrom()); + assertEquals(5, mapChange.getTo()); + assertTrue(mapChange.wasAdded()); + assertNotNull(mapChange.toString()); + + assertFalse(mapChange.next()); + } +} --- old/modules/base/src/test/java/com/sun/javafx/collections/NonIterableChangeTest.java 2015-08-31 10:22:59.401217789 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.javafx.collections; - -import java.util.Arrays; -import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener.Change; -import javafx.collections.ObservableList; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -public class NonIterableChangeTest { - - ObservableList list; - - @Before - public void setUp() { - list = FXCollections.observableArrayList("a", "b", "c", "d", "e"); - } - - @Test - public void testSimpleAdd() { - Change change = new NonIterableChange.SimpleAddChange(0, 1, list); - - assertTrue(change.next()); - - assertTrue(change.wasAdded()); - assertFalse(change.wasRemoved()); - assertFalse(change.wasReplaced()); - assertFalse(change.wasUpdated()); - assertFalse(change.wasPermutated()); - assertEquals(0, change.getFrom()); - assertEquals(1, change.getTo()); - assertEquals(1, change.getAddedSize()); - assertEquals(Arrays.asList("a"), change.getAddedSubList()); - assertEquals(0, change.getRemovedSize()); - assertEquals(Arrays.asList(), change.getRemoved()); - assertNotNull(change.toString()); - - assertFalse(change.next()); - } - - @Test - public void testSimpleRemove() { - Change change = new NonIterableChange.SimpleRemovedChange(0, 0, "a0", list); - - assertTrue(change.next()); - - assertFalse(change.wasAdded()); - assertTrue(change.wasRemoved()); - assertFalse(change.wasReplaced()); - assertFalse(change.wasUpdated()); - assertFalse(change.wasPermutated()); - assertEquals(0, change.getFrom()); - assertEquals(0, change.getTo()); - assertEquals(0, change.getAddedSize()); - assertEquals(Arrays.asList(), change.getAddedSubList()); - assertEquals(1, change.getRemovedSize()); - assertEquals(Arrays.asList("a0"), change.getRemoved()); - assertNotNull(change.toString()); - - assertFalse(change.next()); - } - - @Test - public void testSimpleUpdate() { - Change change = new NonIterableChange.SimpleUpdateChange(0, 1, list); - - assertTrue(change.next()); - - assertFalse(change.wasAdded()); - assertFalse(change.wasRemoved()); - assertFalse(change.wasReplaced()); - assertTrue(change.wasUpdated()); - assertFalse(change.wasPermutated()); - assertEquals(0, change.getFrom()); - assertEquals(1, change.getTo()); - assertEquals(0, change.getAddedSize()); - assertEquals(Arrays.asList(), change.getAddedSubList()); - assertEquals(0, change.getRemovedSize()); - assertEquals(Arrays.asList(), change.getRemoved()); - assertNotNull(change.toString()); - - assertFalse(change.next()); - } - - @Test - public void testSimplePermutation() { - Change change = new NonIterableChange.SimplePermutationChange(0, 2, new int[] {1, 0}, list); - - assertTrue(change.next()); - - assertFalse(change.wasAdded()); - assertFalse(change.wasRemoved()); - assertFalse(change.wasReplaced()); - assertFalse(change.wasUpdated()); - assertTrue(change.wasPermutated()); - assertEquals(0, change.getFrom()); - assertEquals(1, change.getPermutation(0)); - assertEquals(0, change.getPermutation(1)); - assertEquals(2, change.getTo()); - assertEquals(0, change.getAddedSize()); - assertEquals(Arrays.asList(), change.getAddedSubList()); - assertEquals(0, change.getRemovedSize()); - assertEquals(Arrays.asList(), change.getRemoved()); - assertNotNull(change.toString()); - - assertFalse(change.next()); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/collections/NonIterableChangeTest.java 2015-08-31 10:22:59.265217790 -0400 @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.com.sun.javafx.collections; + +import com.sun.javafx.collections.NonIterableChange; +import java.util.Arrays; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener.Change; +import javafx.collections.ObservableList; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +public class NonIterableChangeTest { + + ObservableList list; + + @Before + public void setUp() { + list = FXCollections.observableArrayList("a", "b", "c", "d", "e"); + } + + @Test + public void testSimpleAdd() { + Change change = new NonIterableChange.SimpleAddChange(0, 1, list); + + assertTrue(change.next()); + + assertTrue(change.wasAdded()); + assertFalse(change.wasRemoved()); + assertFalse(change.wasReplaced()); + assertFalse(change.wasUpdated()); + assertFalse(change.wasPermutated()); + assertEquals(0, change.getFrom()); + assertEquals(1, change.getTo()); + assertEquals(1, change.getAddedSize()); + assertEquals(Arrays.asList("a"), change.getAddedSubList()); + assertEquals(0, change.getRemovedSize()); + assertEquals(Arrays.asList(), change.getRemoved()); + assertNotNull(change.toString()); + + assertFalse(change.next()); + } + + @Test + public void testSimpleRemove() { + Change change = new NonIterableChange.SimpleRemovedChange(0, 0, "a0", list); + + assertTrue(change.next()); + + assertFalse(change.wasAdded()); + assertTrue(change.wasRemoved()); + assertFalse(change.wasReplaced()); + assertFalse(change.wasUpdated()); + assertFalse(change.wasPermutated()); + assertEquals(0, change.getFrom()); + assertEquals(0, change.getTo()); + assertEquals(0, change.getAddedSize()); + assertEquals(Arrays.asList(), change.getAddedSubList()); + assertEquals(1, change.getRemovedSize()); + assertEquals(Arrays.asList("a0"), change.getRemoved()); + assertNotNull(change.toString()); + + assertFalse(change.next()); + } + + @Test + public void testSimpleUpdate() { + Change change = new NonIterableChange.SimpleUpdateChange(0, 1, list); + + assertTrue(change.next()); + + assertFalse(change.wasAdded()); + assertFalse(change.wasRemoved()); + assertFalse(change.wasReplaced()); + assertTrue(change.wasUpdated()); + assertFalse(change.wasPermutated()); + assertEquals(0, change.getFrom()); + assertEquals(1, change.getTo()); + assertEquals(0, change.getAddedSize()); + assertEquals(Arrays.asList(), change.getAddedSubList()); + assertEquals(0, change.getRemovedSize()); + assertEquals(Arrays.asList(), change.getRemoved()); + assertNotNull(change.toString()); + + assertFalse(change.next()); + } + + @Test + public void testSimplePermutation() { + Change change = new NonIterableChange.SimplePermutationChange(0, 2, new int[] {1, 0}, list); + + assertTrue(change.next()); + + assertFalse(change.wasAdded()); + assertFalse(change.wasRemoved()); + assertFalse(change.wasReplaced()); + assertFalse(change.wasUpdated()); + assertTrue(change.wasPermutated()); + assertEquals(0, change.getFrom()); + assertEquals(1, change.getPermutation(0)); + assertEquals(0, change.getPermutation(1)); + assertEquals(2, change.getTo()); + assertEquals(0, change.getAddedSize()); + assertEquals(Arrays.asList(), change.getAddedSubList()); + assertEquals(0, change.getRemovedSize()); + assertEquals(Arrays.asList(), change.getRemoved()); + assertNotNull(change.toString()); + + assertFalse(change.next()); + } + +} --- old/modules/base/src/test/java/com/sun/javafx/collections/SetListenerHelperTest.java 2015-08-31 10:23:00.097217781 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,742 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.collections; - -import com.sun.javafx.binding.SetExpressionHelper; -import javafx.beans.InvalidationListener; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.Observable; -import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener; -import javafx.collections.MockSetObserver; -import javafx.collections.ObservableSet; -import javafx.collections.SetChangeListener; -import org.junit.Before; -import org.junit.Test; - -import java.util.BitSet; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class SetListenerHelperTest { - - private InvalidationListenerMock[] invalidationListenerMock; - - private MockSetObserver[] changeListenerMock; - - private SetListenerHelper helper; - - private ObservableSet set; - private SetChangeListener.Change change; - - @Before - public void setUp() { - invalidationListenerMock = new InvalidationListenerMock[] { - new InvalidationListenerMock(), - new InvalidationListenerMock(), - new InvalidationListenerMock(), - new InvalidationListenerMock() - }; - changeListenerMock = new MockSetObserver[] { - new MockSetObserver(), - new MockSetObserver(), - new MockSetObserver(), - new MockSetObserver() - }; - helper = null; - set = FXCollections.observableSet(); - change = new SetExpressionHelper.SimpleChange(set).setRemoved(new Object()); - } - - private void resetAllListeners() { - for (final InvalidationListenerMock listener : invalidationListenerMock) { - listener.reset(); - } - for (final MockSetObserver listener : changeListenerMock) { - listener.clear(); - } - } - - @Test(expected = NullPointerException.class) - public void testAddInvalidationListener_Null() { - SetListenerHelper.addListener(helper, (InvalidationListener)null); - } - - @Test(expected = NullPointerException.class) - public void testRemoveInvalidationListener_Null() { - SetListenerHelper.removeListener(helper, (InvalidationListener) null); - } - - @Test(expected = NullPointerException.class) - public void testRemoveSetChangeListener_Null() { - SetListenerHelper.removeListener(helper, (SetChangeListener) null); - } - - @Test(expected = NullPointerException.class) - public void testAddSetChangeListener_Null() { - SetListenerHelper.addListener(helper, (SetChangeListener) null); - } - - @Test - public void testEmpty() { - assertFalse(SetListenerHelper.hasListeners(helper)); - - // these should be no-ops - SetListenerHelper.fireValueChangedEvent(helper, change); - SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); - SetListenerHelper.removeListener(helper, changeListenerMock[0]); - } - - @Test - public void testInvalidation_Simple() { - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - - helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[1]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - invalidationListenerMock[1].check(null, 0); - - helper = SetListenerHelper.removeListener(helper, changeListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - - helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - } - - @Test - public void testInvalidation_AddInvalidation() { - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[1]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - invalidationListenerMock[1].check(set, 1); - } - - @Test - public void testInvalidation_AddChange() { - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - } - - @Test - public void testInvalidation_ChangeInPulse() { - final InvalidationListener listener = observable -> { - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - }; - helper = SetListenerHelper.addListener(helper, listener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, listener); - invalidationListenerMock[0].reset(); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - } - - @Test - public void testChange_Simple() { - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - - helper = SetListenerHelper.removeListener(helper, changeListenerMock[1]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - changeListenerMock[0].clear(); - - helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - invalidationListenerMock[0].check(null, 0); - changeListenerMock[0].clear(); - - helper = SetListenerHelper.removeListener(helper, changeListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - } - - @Test - public void testChange_AddInvalidation() { - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - invalidationListenerMock[0].check(set, 1); - } - - @Test - public void testChange_AddChange() { - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - } - - @Test - public void testChange_ChangeInPulse() { - final SetChangeListener listener = change1 -> { - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - }; - helper = SetListenerHelper.addListener(helper, listener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, listener); - changeListenerMock[0].clear(); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - } - - @Test - public void testGeneric_AddInvalidation() { - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); - - // first invalidation listener creates the array - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - - // second and third invalidation listener enlarge the array - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[2]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - invalidationListenerMock[1].check(set, 1); - invalidationListenerMock[2].check(set, 1); - - // fourth invalidation listener fits into the array - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[3]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - invalidationListenerMock[1].check(set, 1); - invalidationListenerMock[2].check(set, 1); - invalidationListenerMock[3].check(set, 1); - } - - @Test - public void testGeneric_AddInvalidationInPulse() { - final SetChangeListener addListener = new SetChangeListener() { - int counter; - @Override - public void onChanged(Change change) { - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[counter++]); - } - }; - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - - helper = SetListenerHelper.addListener(helper, addListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(null, 0); - - helper = SetListenerHelper.addListener(helper, addListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - invalidationListenerMock[1].check(set, 1); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(null, 0); - - helper = SetListenerHelper.addListener(helper, addListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - invalidationListenerMock[1].check(set, 1); - invalidationListenerMock[2].check(set, 1); - invalidationListenerMock[3].check(null, 0); - - helper = SetListenerHelper.addListener(helper, addListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - invalidationListenerMock[1].check(set, 1); - invalidationListenerMock[2].check(set, 1); - invalidationListenerMock[3].check(set, 1); - } - - @Test - public void testGeneric_RemoveInvalidation() { - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[2]); - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[3]); - - // remove first element - helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[1].check(set, 1); - invalidationListenerMock[2].check(set, 1); - invalidationListenerMock[3].check(set, 1); - - // remove middle element - helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[2]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[1].check(set, 1); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(set, 1); - - // remove last element - helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[3]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[1].check(set, 1); - invalidationListenerMock[2].check(null, 0); - invalidationListenerMock[3].check(null, 0); - - // remove last invalidation with single change - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[1]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[1].check(null, 0); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - - // remove invalidation if array is empty - helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); - helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - changeListenerMock[0].clear(); - changeListenerMock[1].clear(); - - // remove last invalidation with two change - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - } - - - @Test - public void testGeneric_RemoveInvalidationInPulse() { - final SetChangeListener removeListener = new SetChangeListener() { - int counter; - @Override - public void onChanged(Change change) { - helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[counter++]); - } - }; - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[3]); - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[2]); - - helper = SetListenerHelper.addListener(helper, removeListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(set, 1); - invalidationListenerMock[1].check(set, 1); - invalidationListenerMock[2].check(set, 1); - - helper = SetListenerHelper.addListener(helper, removeListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(set, 1); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(set, 1); - - helper = SetListenerHelper.addListener(helper, removeListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(set, 1); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(null, 0); - - helper = SetListenerHelper.addListener(helper, removeListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(null, 0); - invalidationListenerMock[3].check(null, 0); - invalidationListenerMock[1].check(null, 0); - invalidationListenerMock[2].check(null, 0); - } - - @Test - public void testGeneric_AddChange() { - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - - // first change listener creates the array - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - - // second and third change listener enlarge the array - helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); - helper = SetListenerHelper.addListener(helper, changeListenerMock[2]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - resetAllListeners(); - - // fourth change listener fits into the array - helper = SetListenerHelper.addListener(helper, changeListenerMock[3]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - } - - @Test - public void testGeneric_AddChangeInPulse() { - final InvalidationListener addListener = new InvalidationListener() { - int counter; - @Override - public void invalidated(Observable observable) { - helper = SetListenerHelper.addListener(helper, changeListenerMock[counter++]); - - } - }; - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - - helper = SetListenerHelper.addListener(helper, addListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - assertEquals(0, changeListenerMock[3].getCallsNumber()); - - helper = SetListenerHelper.addListener(helper, addListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - assertEquals(0, changeListenerMock[3].getCallsNumber()); - - helper = SetListenerHelper.addListener(helper, addListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - assertEquals(0, changeListenerMock[3].getCallsNumber()); - - helper = SetListenerHelper.addListener(helper, addListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, addListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(1, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - } - - @Test - public void testGeneric_RemoveChange() { - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); - helper = SetListenerHelper.addListener(helper, changeListenerMock[2]); - helper = SetListenerHelper.addListener(helper, changeListenerMock[3]); - - // remove first element - helper = SetListenerHelper.removeListener(helper, changeListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - resetAllListeners(); - - // remove middle element - helper = SetListenerHelper.removeListener(helper, changeListenerMock[2]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - resetAllListeners(); - - // remove last element - helper = SetListenerHelper.removeListener(helper, changeListenerMock[3]); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - assertEquals(0, changeListenerMock[3].getCallsNumber()); - resetAllListeners(); - - // remove last change with single invalidation - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = SetListenerHelper.removeListener(helper, changeListenerMock[1]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - changeListenerMock[1].clear(); - - // remove change if array is empty - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[1]); - helper = SetListenerHelper.removeListener(helper, changeListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - invalidationListenerMock[1].check(set, 1); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - - // remove last change with two invalidation - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - helper = SetListenerHelper.removeListener(helper, changeListenerMock[0]); - SetListenerHelper.fireValueChangedEvent(helper, change); - invalidationListenerMock[0].check(set, 1); - invalidationListenerMock[1].check(set, 1); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - changeListenerMock[0].clear(); - } - - - @Test - public void testGeneric_RemoveChangeInPulse() { - final InvalidationListener removeListener = new InvalidationListener() { - int counter; - @Override - public void invalidated(Observable observable) { - helper = SetListenerHelper.removeListener(helper, changeListenerMock[counter++]); - } - }; - helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); - helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); - helper = SetListenerHelper.addListener(helper, changeListenerMock[3]); - helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); - helper = SetListenerHelper.addListener(helper, changeListenerMock[2]); - - helper = SetListenerHelper.addListener(helper, removeListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - assertEquals(1, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - - helper = SetListenerHelper.addListener(helper, removeListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - assertEquals(1, changeListenerMock[2].getCallsNumber()); - - helper = SetListenerHelper.addListener(helper, removeListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(1, changeListenerMock[3].getCallsNumber()); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - - helper = SetListenerHelper.addListener(helper, removeListener); - SetListenerHelper.fireValueChangedEvent(helper, change); - helper = SetListenerHelper.removeListener(helper, removeListener); - resetAllListeners(); - SetListenerHelper.fireValueChangedEvent(helper, change); - assertEquals(0, changeListenerMock[0].getCallsNumber()); - assertEquals(0, changeListenerMock[3].getCallsNumber()); - assertEquals(0, changeListenerMock[1].getCallsNumber()); - assertEquals(0, changeListenerMock[2].getCallsNumber()); - } - - - - @Test - public void testExceptionNotPropagatedFromSingleInvalidation() { - helper = SetListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - } - - @Test - public void testExceptionNotPropagatedFromMultipleInvalidation() { - BitSet called = new BitSet(); - - helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(0); throw new RuntimeException();}); - helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(1); throw new RuntimeException();}); - - helper.fireValueChangedEvent(change); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - } - - @Test - public void testExceptionNotPropagatedFromSingleChange() { - helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> { - throw new RuntimeException(); - }); - helper.fireValueChangedEvent(change); - } - - @Test - public void testExceptionNotPropagatedFromMultipleChange() { - BitSet called = new BitSet(); - - helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); - helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - } - - @Test - public void testExceptionNotPropagatedFromMultipleChangeAndInvalidation() { - BitSet called = new BitSet(); - - helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); - helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); - helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(2); throw new RuntimeException();}); - helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(3); throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get(0)); - assertTrue(called.get(1)); - assertTrue(called.get(2)); - assertTrue(called.get(3)); - } - - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInSingleInvalidation() { - AtomicBoolean called = new AtomicBoolean(false); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); - - helper = SetListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get()); - } - - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleInvalidation() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); - helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertEquals(2, called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInSingleChange() { - AtomicBoolean called = new AtomicBoolean(false); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); - helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertTrue(called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleChange() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {throw new RuntimeException();}); - helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertEquals(2, called.get()); - } - - @Test - public void testExceptionHandledByThreadUncaughtHandlerInMultipleChangeAndInvalidation() { - AtomicInteger called = new AtomicInteger(0); - - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); - - helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> { throw new RuntimeException();}); - helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> { throw new RuntimeException();}); - helper = SetListenerHelper.addListener(helper, (Observable o) -> { throw new RuntimeException();}); - helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); - helper.fireValueChangedEvent(change); - - assertEquals(4, called.get()); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/collections/SetListenerHelperTest.java 2015-08-31 10:22:59.909217783 -0400 @@ -0,0 +1,742 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.collections; + +import com.sun.javafx.binding.SetExpressionHelper; +import com.sun.javafx.collections.SetListenerHelper; +import javafx.beans.InvalidationListener; +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.Observable; +import javafx.collections.FXCollections; +import test.javafx.collections.MockSetObserver; +import javafx.collections.ObservableSet; +import javafx.collections.SetChangeListener; +import org.junit.Before; +import org.junit.Test; + +import java.util.BitSet; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class SetListenerHelperTest { + + private InvalidationListenerMock[] invalidationListenerMock; + + private MockSetObserver[] changeListenerMock; + + private SetListenerHelper helper; + + private ObservableSet set; + private SetChangeListener.Change change; + + @Before + public void setUp() { + invalidationListenerMock = new InvalidationListenerMock[] { + new InvalidationListenerMock(), + new InvalidationListenerMock(), + new InvalidationListenerMock(), + new InvalidationListenerMock() + }; + changeListenerMock = new MockSetObserver[] { + new MockSetObserver(), + new MockSetObserver(), + new MockSetObserver(), + new MockSetObserver() + }; + helper = null; + set = FXCollections.observableSet(); + change = new SetExpressionHelper.SimpleChange(set).setRemoved(new Object()); + } + + private void resetAllListeners() { + for (final InvalidationListenerMock listener : invalidationListenerMock) { + listener.reset(); + } + for (final MockSetObserver listener : changeListenerMock) { + listener.clear(); + } + } + + @Test(expected = NullPointerException.class) + public void testAddInvalidationListener_Null() { + SetListenerHelper.addListener(helper, (InvalidationListener)null); + } + + @Test(expected = NullPointerException.class) + public void testRemoveInvalidationListener_Null() { + SetListenerHelper.removeListener(helper, (InvalidationListener) null); + } + + @Test(expected = NullPointerException.class) + public void testRemoveSetChangeListener_Null() { + SetListenerHelper.removeListener(helper, (SetChangeListener) null); + } + + @Test(expected = NullPointerException.class) + public void testAddSetChangeListener_Null() { + SetListenerHelper.addListener(helper, (SetChangeListener) null); + } + + @Test + public void testEmpty() { + assertFalse(SetListenerHelper.hasListeners(helper)); + + // these should be no-ops + SetListenerHelper.fireValueChangedEvent(helper, change); + SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); + SetListenerHelper.removeListener(helper, changeListenerMock[0]); + } + + @Test + public void testInvalidation_Simple() { + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + + helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[1]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + invalidationListenerMock[1].check(null, 0); + + helper = SetListenerHelper.removeListener(helper, changeListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + + helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + } + + @Test + public void testInvalidation_AddInvalidation() { + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[1]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + invalidationListenerMock[1].check(set, 1); + } + + @Test + public void testInvalidation_AddChange() { + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + } + + @Test + public void testInvalidation_ChangeInPulse() { + final InvalidationListener listener = observable -> { + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + }; + helper = SetListenerHelper.addListener(helper, listener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, listener); + invalidationListenerMock[0].reset(); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + } + + @Test + public void testChange_Simple() { + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + + helper = SetListenerHelper.removeListener(helper, changeListenerMock[1]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + changeListenerMock[0].clear(); + + helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + invalidationListenerMock[0].check(null, 0); + changeListenerMock[0].clear(); + + helper = SetListenerHelper.removeListener(helper, changeListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + } + + @Test + public void testChange_AddInvalidation() { + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + invalidationListenerMock[0].check(set, 1); + } + + @Test + public void testChange_AddChange() { + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + } + + @Test + public void testChange_ChangeInPulse() { + final SetChangeListener listener = change1 -> { + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + }; + helper = SetListenerHelper.addListener(helper, listener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, listener); + changeListenerMock[0].clear(); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + } + + @Test + public void testGeneric_AddInvalidation() { + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); + + // first invalidation listener creates the array + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + + // second and third invalidation listener enlarge the array + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[2]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + invalidationListenerMock[1].check(set, 1); + invalidationListenerMock[2].check(set, 1); + + // fourth invalidation listener fits into the array + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[3]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + invalidationListenerMock[1].check(set, 1); + invalidationListenerMock[2].check(set, 1); + invalidationListenerMock[3].check(set, 1); + } + + @Test + public void testGeneric_AddInvalidationInPulse() { + final SetChangeListener addListener = new SetChangeListener() { + int counter; + @Override + public void onChanged(Change change) { + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[counter++]); + } + }; + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + + helper = SetListenerHelper.addListener(helper, addListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(null, 0); + + helper = SetListenerHelper.addListener(helper, addListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + invalidationListenerMock[1].check(set, 1); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(null, 0); + + helper = SetListenerHelper.addListener(helper, addListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + invalidationListenerMock[1].check(set, 1); + invalidationListenerMock[2].check(set, 1); + invalidationListenerMock[3].check(null, 0); + + helper = SetListenerHelper.addListener(helper, addListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + invalidationListenerMock[1].check(set, 1); + invalidationListenerMock[2].check(set, 1); + invalidationListenerMock[3].check(set, 1); + } + + @Test + public void testGeneric_RemoveInvalidation() { + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[2]); + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[3]); + + // remove first element + helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[1].check(set, 1); + invalidationListenerMock[2].check(set, 1); + invalidationListenerMock[3].check(set, 1); + + // remove middle element + helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[2]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[1].check(set, 1); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(set, 1); + + // remove last element + helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[3]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[1].check(set, 1); + invalidationListenerMock[2].check(null, 0); + invalidationListenerMock[3].check(null, 0); + + // remove last invalidation with single change + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[1]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[1].check(null, 0); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + + // remove invalidation if array is empty + helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); + helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + changeListenerMock[0].clear(); + changeListenerMock[1].clear(); + + // remove last invalidation with two change + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + } + + + @Test + public void testGeneric_RemoveInvalidationInPulse() { + final SetChangeListener removeListener = new SetChangeListener() { + int counter; + @Override + public void onChanged(Change change) { + helper = SetListenerHelper.removeListener(helper, invalidationListenerMock[counter++]); + } + }; + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[3]); + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[2]); + + helper = SetListenerHelper.addListener(helper, removeListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(set, 1); + invalidationListenerMock[1].check(set, 1); + invalidationListenerMock[2].check(set, 1); + + helper = SetListenerHelper.addListener(helper, removeListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(set, 1); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(set, 1); + + helper = SetListenerHelper.addListener(helper, removeListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(set, 1); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(null, 0); + + helper = SetListenerHelper.addListener(helper, removeListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(null, 0); + invalidationListenerMock[3].check(null, 0); + invalidationListenerMock[1].check(null, 0); + invalidationListenerMock[2].check(null, 0); + } + + @Test + public void testGeneric_AddChange() { + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + + // first change listener creates the array + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + + // second and third change listener enlarge the array + helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); + helper = SetListenerHelper.addListener(helper, changeListenerMock[2]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + resetAllListeners(); + + // fourth change listener fits into the array + helper = SetListenerHelper.addListener(helper, changeListenerMock[3]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + } + + @Test + public void testGeneric_AddChangeInPulse() { + final InvalidationListener addListener = new InvalidationListener() { + int counter; + @Override + public void invalidated(Observable observable) { + helper = SetListenerHelper.addListener(helper, changeListenerMock[counter++]); + + } + }; + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + + helper = SetListenerHelper.addListener(helper, addListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + assertEquals(0, changeListenerMock[3].getCallsNumber()); + + helper = SetListenerHelper.addListener(helper, addListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + assertEquals(0, changeListenerMock[3].getCallsNumber()); + + helper = SetListenerHelper.addListener(helper, addListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + assertEquals(0, changeListenerMock[3].getCallsNumber()); + + helper = SetListenerHelper.addListener(helper, addListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, addListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(1, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + } + + @Test + public void testGeneric_RemoveChange() { + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); + helper = SetListenerHelper.addListener(helper, changeListenerMock[2]); + helper = SetListenerHelper.addListener(helper, changeListenerMock[3]); + + // remove first element + helper = SetListenerHelper.removeListener(helper, changeListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + resetAllListeners(); + + // remove middle element + helper = SetListenerHelper.removeListener(helper, changeListenerMock[2]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + resetAllListeners(); + + // remove last element + helper = SetListenerHelper.removeListener(helper, changeListenerMock[3]); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + assertEquals(0, changeListenerMock[3].getCallsNumber()); + resetAllListeners(); + + // remove last change with single invalidation + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = SetListenerHelper.removeListener(helper, changeListenerMock[1]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + changeListenerMock[1].clear(); + + // remove change if array is empty + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[1]); + helper = SetListenerHelper.removeListener(helper, changeListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + invalidationListenerMock[1].check(set, 1); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + + // remove last change with two invalidation + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + helper = SetListenerHelper.removeListener(helper, changeListenerMock[0]); + SetListenerHelper.fireValueChangedEvent(helper, change); + invalidationListenerMock[0].check(set, 1); + invalidationListenerMock[1].check(set, 1); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + changeListenerMock[0].clear(); + } + + + @Test + public void testGeneric_RemoveChangeInPulse() { + final InvalidationListener removeListener = new InvalidationListener() { + int counter; + @Override + public void invalidated(Observable observable) { + helper = SetListenerHelper.removeListener(helper, changeListenerMock[counter++]); + } + }; + helper = SetListenerHelper.addListener(helper, invalidationListenerMock[0]); + helper = SetListenerHelper.addListener(helper, changeListenerMock[0]); + helper = SetListenerHelper.addListener(helper, changeListenerMock[3]); + helper = SetListenerHelper.addListener(helper, changeListenerMock[1]); + helper = SetListenerHelper.addListener(helper, changeListenerMock[2]); + + helper = SetListenerHelper.addListener(helper, removeListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + assertEquals(1, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + + helper = SetListenerHelper.addListener(helper, removeListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + assertEquals(1, changeListenerMock[2].getCallsNumber()); + + helper = SetListenerHelper.addListener(helper, removeListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(1, changeListenerMock[3].getCallsNumber()); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + + helper = SetListenerHelper.addListener(helper, removeListener); + SetListenerHelper.fireValueChangedEvent(helper, change); + helper = SetListenerHelper.removeListener(helper, removeListener); + resetAllListeners(); + SetListenerHelper.fireValueChangedEvent(helper, change); + assertEquals(0, changeListenerMock[0].getCallsNumber()); + assertEquals(0, changeListenerMock[3].getCallsNumber()); + assertEquals(0, changeListenerMock[1].getCallsNumber()); + assertEquals(0, changeListenerMock[2].getCallsNumber()); + } + + + + @Test + public void testExceptionNotPropagatedFromSingleInvalidation() { + helper = SetListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); + SetListenerHelper.fireValueChangedEvent(helper,change); + } + + @Test + public void testExceptionNotPropagatedFromMultipleInvalidation() { + BitSet called = new BitSet(); + + helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(0); throw new RuntimeException();}); + helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(1); throw new RuntimeException();}); + + SetListenerHelper.fireValueChangedEvent(helper,change); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + } + + @Test + public void testExceptionNotPropagatedFromSingleChange() { + helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> { + throw new RuntimeException(); + }); + SetListenerHelper.fireValueChangedEvent(helper,change); + } + + @Test + public void testExceptionNotPropagatedFromMultipleChange() { + BitSet called = new BitSet(); + + helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); + helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); + SetListenerHelper.fireValueChangedEvent(helper,change); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + } + + @Test + public void testExceptionNotPropagatedFromMultipleChangeAndInvalidation() { + BitSet called = new BitSet(); + + helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {called.set(0); throw new RuntimeException();}); + helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {called.set(1); throw new RuntimeException();}); + helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(2); throw new RuntimeException();}); + helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(3); throw new RuntimeException();}); + SetListenerHelper.fireValueChangedEvent(helper,change); + + assertTrue(called.get(0)); + assertTrue(called.get(1)); + assertTrue(called.get(2)); + assertTrue(called.get(3)); + } + + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInSingleInvalidation() { + AtomicBoolean called = new AtomicBoolean(false); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); + + helper = SetListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();}); + SetListenerHelper.fireValueChangedEvent(helper,change); + + assertTrue(called.get()); + } + + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleInvalidation() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); + helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); + SetListenerHelper.fireValueChangedEvent(helper,change); + + assertEquals(2, called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInSingleChange() { + AtomicBoolean called = new AtomicBoolean(false); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true)); + helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {throw new RuntimeException();}); + SetListenerHelper.fireValueChangedEvent(helper,change); + + assertTrue(called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleChange() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {throw new RuntimeException();}); + helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> {throw new RuntimeException();}); + SetListenerHelper.fireValueChangedEvent(helper,change); + + assertEquals(2, called.get()); + } + + @Test + public void testExceptionHandledByThreadUncaughtHandlerInMultipleChangeAndInvalidation() { + AtomicInteger called = new AtomicInteger(0); + + Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet()); + + helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> { throw new RuntimeException();}); + helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change c) -> { throw new RuntimeException();}); + helper = SetListenerHelper.addListener(helper, (Observable o) -> { throw new RuntimeException();}); + helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();}); + SetListenerHelper.fireValueChangedEvent(helper,change); + + assertEquals(4, called.get()); + } + +} --- old/modules/base/src/test/java/com/sun/javafx/event/CompositeEventDispatcherTest.java 2015-08-31 10:23:00.713217774 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.EventDispatchChain; -import org.junit.Assert; -import org.junit.Test; - -import com.sun.javafx.event.StubBasicEventDispatcher.ConsumeEvent; - -public final class CompositeEventDispatcherTest { - @Test - public void eventDispatchTest() { - final TestCompositeEventDispatcher compositeDispatcher = - new TestCompositeEventDispatcher(); - - final EventCountingDispatcher terminalDispatcher = - new EventCountingDispatcher(); - final EventDispatchChain eventDispatchChain = - StubEventDispatchChain.EMPTY_CHAIN - .append(compositeDispatcher) - .append(terminalDispatcher); - - Assert.assertNotNull(eventDispatchChain.dispatchEvent( - new EmptyEvent())); - verifyEventCounters(compositeDispatcher, 1, 1, 1, 1, 1, 1); - Assert.assertEquals(1, terminalDispatcher.getCapturingEventCount()); - - compositeDispatcher.getFirstChildDispatcher().setConsumeNextEvent( - ConsumeEvent.CAPTURING); - Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); - verifyEventCounters(compositeDispatcher, 2, 1, 1, 1, 1, 1); - Assert.assertEquals(1, terminalDispatcher.getCapturingEventCount()); - - compositeDispatcher.getSecondChildDispatcher().setConsumeNextEvent( - ConsumeEvent.CAPTURING); - Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); - verifyEventCounters(compositeDispatcher, 3, 2, 1, 1, 1, 1); - Assert.assertEquals(1, terminalDispatcher.getCapturingEventCount()); - - compositeDispatcher.getThirdChildDispatcher().setConsumeNextEvent( - ConsumeEvent.CAPTURING); - Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); - verifyEventCounters(compositeDispatcher, 4, 3, 2, 1, 1, 1); - Assert.assertEquals(1, terminalDispatcher.getCapturingEventCount()); - - compositeDispatcher.getThirdChildDispatcher().setConsumeNextEvent( - ConsumeEvent.BUBBLING); - Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); - verifyEventCounters(compositeDispatcher, 5, 4, 3, 1, 1, 2); - Assert.assertEquals(2, terminalDispatcher.getCapturingEventCount()); - - compositeDispatcher.getSecondChildDispatcher().setConsumeNextEvent( - ConsumeEvent.BUBBLING); - Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); - verifyEventCounters(compositeDispatcher, 6, 5, 4, 1, 2, 3); - Assert.assertEquals(3, terminalDispatcher.getCapturingEventCount()); - - compositeDispatcher.getFirstChildDispatcher().setConsumeNextEvent( - ConsumeEvent.BUBBLING); - Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); - verifyEventCounters(compositeDispatcher, 7, 6, 5, 2, 3, 4); - Assert.assertEquals(4, terminalDispatcher.getCapturingEventCount()); - } - - private void verifyEventCounters( - final TestCompositeEventDispatcher compositeDispatcher, - final int expectedChild1CapturingEventCount, - final int expectedChild2CapturingEventCount, - final int expectedChild3CapturingEventCount, - final int expectedChild1BubblingEventCount, - final int expectedChild2BubblingEventCount, - final int expectedChild3BubblingEventCount) { - Assert.assertEquals(expectedChild1CapturingEventCount, - compositeDispatcher.getFirstChildDispatcher() - .getCapturingEventCount()); - Assert.assertEquals(expectedChild2CapturingEventCount, - compositeDispatcher.getSecondChildDispatcher() - .getCapturingEventCount()); - Assert.assertEquals(expectedChild3CapturingEventCount, - compositeDispatcher.getThirdChildDispatcher() - .getCapturingEventCount()); - Assert.assertEquals(expectedChild1BubblingEventCount, - compositeDispatcher.getFirstChildDispatcher() - .getBubblingEventCount()); - Assert.assertEquals(expectedChild2BubblingEventCount, - compositeDispatcher.getSecondChildDispatcher() - .getBubblingEventCount()); - Assert.assertEquals(expectedChild3BubblingEventCount, - compositeDispatcher.getThirdChildDispatcher() - .getBubblingEventCount()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/CompositeEventDispatcherTest.java 2015-08-31 10:23:00.577217776 -0400 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import javafx.event.EventDispatchChain; +import org.junit.Assert; +import org.junit.Test; + +import test.com.sun.javafx.event.StubBasicEventDispatcher.ConsumeEvent; + +public final class CompositeEventDispatcherTest { + @Test + public void eventDispatchTest() { + final TestCompositeEventDispatcher compositeDispatcher = + new TestCompositeEventDispatcher(); + + final EventCountingDispatcher terminalDispatcher = + new EventCountingDispatcher(); + final EventDispatchChain eventDispatchChain = + StubEventDispatchChain.EMPTY_CHAIN + .append(compositeDispatcher) + .append(terminalDispatcher); + + Assert.assertNotNull(eventDispatchChain.dispatchEvent( + new EmptyEvent())); + verifyEventCounters(compositeDispatcher, 1, 1, 1, 1, 1, 1); + Assert.assertEquals(1, terminalDispatcher.getCapturingEventCount()); + + compositeDispatcher.getFirstChildDispatcher().setConsumeNextEvent( + ConsumeEvent.CAPTURING); + Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); + verifyEventCounters(compositeDispatcher, 2, 1, 1, 1, 1, 1); + Assert.assertEquals(1, terminalDispatcher.getCapturingEventCount()); + + compositeDispatcher.getSecondChildDispatcher().setConsumeNextEvent( + ConsumeEvent.CAPTURING); + Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); + verifyEventCounters(compositeDispatcher, 3, 2, 1, 1, 1, 1); + Assert.assertEquals(1, terminalDispatcher.getCapturingEventCount()); + + compositeDispatcher.getThirdChildDispatcher().setConsumeNextEvent( + ConsumeEvent.CAPTURING); + Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); + verifyEventCounters(compositeDispatcher, 4, 3, 2, 1, 1, 1); + Assert.assertEquals(1, terminalDispatcher.getCapturingEventCount()); + + compositeDispatcher.getThirdChildDispatcher().setConsumeNextEvent( + ConsumeEvent.BUBBLING); + Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); + verifyEventCounters(compositeDispatcher, 5, 4, 3, 1, 1, 2); + Assert.assertEquals(2, terminalDispatcher.getCapturingEventCount()); + + compositeDispatcher.getSecondChildDispatcher().setConsumeNextEvent( + ConsumeEvent.BUBBLING); + Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); + verifyEventCounters(compositeDispatcher, 6, 5, 4, 1, 2, 3); + Assert.assertEquals(3, terminalDispatcher.getCapturingEventCount()); + + compositeDispatcher.getFirstChildDispatcher().setConsumeNextEvent( + ConsumeEvent.BUBBLING); + Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); + verifyEventCounters(compositeDispatcher, 7, 6, 5, 2, 3, 4); + Assert.assertEquals(4, terminalDispatcher.getCapturingEventCount()); + } + + private void verifyEventCounters( + final TestCompositeEventDispatcher compositeDispatcher, + final int expectedChild1CapturingEventCount, + final int expectedChild2CapturingEventCount, + final int expectedChild3CapturingEventCount, + final int expectedChild1BubblingEventCount, + final int expectedChild2BubblingEventCount, + final int expectedChild3BubblingEventCount) { + Assert.assertEquals(expectedChild1CapturingEventCount, + compositeDispatcher.getFirstChildDispatcher() + .getCapturingEventCount()); + Assert.assertEquals(expectedChild2CapturingEventCount, + compositeDispatcher.getSecondChildDispatcher() + .getCapturingEventCount()); + Assert.assertEquals(expectedChild3CapturingEventCount, + compositeDispatcher.getThirdChildDispatcher() + .getCapturingEventCount()); + Assert.assertEquals(expectedChild1BubblingEventCount, + compositeDispatcher.getFirstChildDispatcher() + .getBubblingEventCount()); + Assert.assertEquals(expectedChild2BubblingEventCount, + compositeDispatcher.getSecondChildDispatcher() + .getBubblingEventCount()); + Assert.assertEquals(expectedChild3BubblingEventCount, + compositeDispatcher.getThirdChildDispatcher() + .getBubblingEventCount()); + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/CompositeEventHandlerTest.java 2015-08-31 10:23:01.397217767 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.Event; -import javafx.event.WeakEventHandler; -import javafx.event.WeakEventHandlerUtil; -import org.junit.Assert; - -import org.junit.Before; -import org.junit.Test; - -public class CompositeEventHandlerTest { - private CompositeEventHandler compositeEventHandler; - - @Before - public void setUp() { - compositeEventHandler = new CompositeEventHandler(); - } - - @Test - public void weakEventHandlerTest() { - final EventCountingHandler eventCountingHandler = - new EventCountingHandler(); - final WeakEventHandler weakEventHandler = - new WeakEventHandler(eventCountingHandler); - - compositeEventHandler.addEventHandler(weakEventHandler); - - Assert.assertTrue( - compositeEventHandler.containsHandler(weakEventHandler)); - compositeEventHandler.dispatchCapturingEvent(new EmptyEvent()); - Assert.assertEquals(0, eventCountingHandler.getEventCount()); - compositeEventHandler.dispatchBubblingEvent(new EmptyEvent()); - Assert.assertEquals(1, eventCountingHandler.getEventCount()); - - WeakEventHandlerUtil.clear(weakEventHandler); - - Assert.assertFalse( - compositeEventHandler.containsHandler(weakEventHandler)); - compositeEventHandler.dispatchCapturingEvent(new EmptyEvent()); - Assert.assertEquals(1, eventCountingHandler.getEventCount()); - compositeEventHandler.dispatchBubblingEvent(new EmptyEvent()); - Assert.assertEquals(1, eventCountingHandler.getEventCount()); - } - - @Test - public void weakEventFilterTest() { - final EventCountingHandler eventCountingFilter = - new EventCountingHandler(); - final WeakEventHandler weakEventFilter = - new WeakEventHandler(eventCountingFilter); - - compositeEventHandler.addEventFilter(weakEventFilter); - - Assert.assertTrue( - compositeEventHandler.containsFilter(weakEventFilter)); - compositeEventHandler.dispatchCapturingEvent(new EmptyEvent()); - Assert.assertEquals(1, eventCountingFilter.getEventCount()); - compositeEventHandler.dispatchBubblingEvent(new EmptyEvent()); - Assert.assertEquals(1, eventCountingFilter.getEventCount()); - - WeakEventHandlerUtil.clear(weakEventFilter); - - Assert.assertFalse( - compositeEventHandler.containsFilter(weakEventFilter)); - compositeEventHandler.dispatchCapturingEvent(new EmptyEvent()); - Assert.assertEquals(1, eventCountingFilter.getEventCount()); - compositeEventHandler.dispatchBubblingEvent(new EmptyEvent()); - Assert.assertEquals(1, eventCountingFilter.getEventCount()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/CompositeEventHandlerTest.java 2015-08-31 10:23:01.265217768 -0400 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import com.sun.javafx.event.CompositeEventHandler; +import com.sun.javafx.event.CompositeEventHandlerShim; +import test.com.sun.javafx.event.EventCountingHandler; +import test.com.sun.javafx.event.EmptyEvent; +import javafx.event.Event; +import javafx.event.WeakEventHandler; +import javafx.event.WeakEventHandlerUtil; +import org.junit.Assert; + +import org.junit.Before; +import org.junit.Test; + +public class CompositeEventHandlerTest { + private CompositeEventHandler compositeEventHandler; + + @Before + public void setUp() { + compositeEventHandler = new CompositeEventHandler(); + } + + @Test + public void weakEventHandlerTest() { + final EventCountingHandler eventCountingHandler = + new EventCountingHandler(); + final WeakEventHandler weakEventHandler = + new WeakEventHandler(eventCountingHandler); + + compositeEventHandler.addEventHandler(weakEventHandler); + + Assert.assertTrue( + CompositeEventHandlerShim.containsHandler(compositeEventHandler, weakEventHandler)); + compositeEventHandler.dispatchCapturingEvent(new EmptyEvent()); + Assert.assertEquals(0, eventCountingHandler.getEventCount()); + compositeEventHandler.dispatchBubblingEvent(new EmptyEvent()); + Assert.assertEquals(1, eventCountingHandler.getEventCount()); + + WeakEventHandlerUtil.clear(weakEventHandler); + + Assert.assertFalse( + CompositeEventHandlerShim.containsHandler(compositeEventHandler, weakEventHandler)); + compositeEventHandler.dispatchCapturingEvent(new EmptyEvent()); + Assert.assertEquals(1, eventCountingHandler.getEventCount()); + compositeEventHandler.dispatchBubblingEvent(new EmptyEvent()); + Assert.assertEquals(1, eventCountingHandler.getEventCount()); + } + + @Test + public void weakEventFilterTest() { + final EventCountingHandler eventCountingFilter = + new EventCountingHandler(); + final WeakEventHandler weakEventFilter = + new WeakEventHandler(eventCountingFilter); + + compositeEventHandler.addEventFilter(weakEventFilter); + + Assert.assertTrue( + CompositeEventHandlerShim.containsFilter(compositeEventHandler, weakEventFilter)); + compositeEventHandler.dispatchCapturingEvent(new EmptyEvent()); + Assert.assertEquals(1, eventCountingFilter.getEventCount()); + compositeEventHandler.dispatchBubblingEvent(new EmptyEvent()); + Assert.assertEquals(1, eventCountingFilter.getEventCount()); + + WeakEventHandlerUtil.clear(weakEventFilter); + + Assert.assertFalse( + CompositeEventHandlerShim.containsFilter(compositeEventHandler, weakEventFilter)); + compositeEventHandler.dispatchCapturingEvent(new EmptyEvent()); + Assert.assertEquals(1, eventCountingFilter.getEventCount()); + compositeEventHandler.dispatchBubblingEvent(new EmptyEvent()); + Assert.assertEquals(1, eventCountingFilter.getEventCount()); + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/EmptyEvent.java 2015-08-31 10:23:02.001217760 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.Event; -import javafx.event.EventType; - -public final class EmptyEvent extends Event { - public static final EventType EMPTY = - new EventType(Event.ANY, "EMPTY"); - - public EmptyEvent() { - super(EMPTY); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/EmptyEvent.java 2015-08-31 10:23:01.865217761 -0400 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import javafx.event.Event; +import javafx.event.EventType; + +public final class EmptyEvent extends Event { + public static final EventType EMPTY = + new EventType(Event.ANY, "EMPTY"); + + public EmptyEvent() { + super(EMPTY); + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/EventChangingDispatcher.java 2015-08-31 10:23:02.841217750 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.Event; -import javafx.event.EventDispatchChain; - -import org.junit.Assert; - -public final class EventChangingDispatcher extends LabeledEventDispatcher { - private final Operation capturingPhaseOperation; - private final Operation bubblingPhaseOperation; - - public EventChangingDispatcher(final Operation capturingPhaseOperation, - final Operation bubblingPhaseOperation) { - this(null, capturingPhaseOperation, bubblingPhaseOperation); - } - - public EventChangingDispatcher(final String label, - final Operation capturingPhaseOperation, - final Operation bubblingPhaseOperation) { - super(label); - this.capturingPhaseOperation = capturingPhaseOperation; - this.bubblingPhaseOperation = bubblingPhaseOperation; - } - - @Override - public Event dispatchEvent(final Event event, - final EventDispatchChain tail) { - Assert.assertTrue(event instanceof ValueEvent); - ValueEvent valueEvent = (ValueEvent) event; - - if (capturingPhaseOperation != null) { - valueEvent.setValue(capturingPhaseOperation.applyTo( - valueEvent.getValue())); - } - valueEvent = (ValueEvent) tail.dispatchEvent(valueEvent); - if (bubblingPhaseOperation != null) { - valueEvent.setValue(bubblingPhaseOperation.applyTo( - valueEvent.getValue())); - } - - return valueEvent; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/EventChangingDispatcher.java 2015-08-31 10:23:02.653217752 -0400 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import javafx.event.Event; +import javafx.event.EventDispatchChain; + +import org.junit.Assert; + +public final class EventChangingDispatcher extends LabeledEventDispatcher { + private final Operation capturingPhaseOperation; + private final Operation bubblingPhaseOperation; + + public EventChangingDispatcher(final Operation capturingPhaseOperation, + final Operation bubblingPhaseOperation) { + this(null, capturingPhaseOperation, bubblingPhaseOperation); + } + + public EventChangingDispatcher(final String label, + final Operation capturingPhaseOperation, + final Operation bubblingPhaseOperation) { + super(label); + this.capturingPhaseOperation = capturingPhaseOperation; + this.bubblingPhaseOperation = bubblingPhaseOperation; + } + + @Override + public Event dispatchEvent(final Event event, + final EventDispatchChain tail) { + Assert.assertTrue(event instanceof ValueEvent); + ValueEvent valueEvent = (ValueEvent) event; + + if (capturingPhaseOperation != null) { + valueEvent.setValue(capturingPhaseOperation.applyTo( + valueEvent.getValue())); + } + valueEvent = (ValueEvent) tail.dispatchEvent(valueEvent); + if (bubblingPhaseOperation != null) { + valueEvent.setValue(bubblingPhaseOperation.applyTo( + valueEvent.getValue())); + } + + return valueEvent; + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/EventChangingHandler.java 2015-08-31 10:23:03.569217742 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.EventHandler; - -public final class EventChangingHandler implements EventHandler { - private final Operation operation; - - public EventChangingHandler(final Operation operation) { - this.operation = operation; - } - - @Override - public void handle(final ValueEvent event) { - event.setValue(operation.applyTo(event.getValue())); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/EventChangingHandler.java 2015-08-31 10:23:03.393217744 -0400 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import javafx.event.EventHandler; + +public final class EventChangingHandler implements EventHandler { + private final Operation operation; + + public EventChangingHandler(final Operation operation) { + this.operation = operation; + } + + @Override + public void handle(final ValueEvent event) { + event.setValue(operation.applyTo(event.getValue())); + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/EventConsumingHandler.java 2015-08-31 10:23:04.205217735 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.Event; -import javafx.event.EventHandler; - -public final class EventConsumingHandler implements EventHandler { - @Override - public void handle(final Event event) { - event.consume(); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/EventConsumingHandler.java 2015-08-31 10:23:04.069217736 -0400 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import javafx.event.Event; +import javafx.event.EventHandler; + +public final class EventConsumingHandler implements EventHandler { + @Override + public void handle(final Event event) { + event.consume(); + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/EventCountingDispatcher.java 2015-08-31 10:23:04.813217728 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.Event; -import javafx.event.EventDispatchChain; - -public final class EventCountingDispatcher extends LabeledEventDispatcher { - private int capturingEventCount; - private int bubblingEventCount; - private boolean consumeCapturingEvent; - private boolean consumeBubblingEvent; - - public EventCountingDispatcher() { - } - - public EventCountingDispatcher(final String label) { - super(label); - } - - public int getCapturingEventCount() { - return capturingEventCount; - } - - public int getBubblingEventCount() { - return bubblingEventCount; - } - - public void setConsumeCapturingEvent(final boolean consume) { - consumeCapturingEvent = consume; - } - - public void setConsumeBubblingEvent(final boolean consume) { - consumeBubblingEvent = consume; - } - - @Override - public Event dispatchEvent(final Event event, - final EventDispatchChain tail) { - ++capturingEventCount; - if (consumeCapturingEvent) { - return null; - } - - final Event returnEvent = tail.dispatchEvent(event); - if (returnEvent != null) { - ++bubblingEventCount; - } - - return consumeBubblingEvent ? null : returnEvent; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/EventCountingDispatcher.java 2015-08-31 10:23:04.681217730 -0400 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import javafx.event.Event; +import javafx.event.EventDispatchChain; + +public final class EventCountingDispatcher extends LabeledEventDispatcher { + private int capturingEventCount; + private int bubblingEventCount; + private boolean consumeCapturingEvent; + private boolean consumeBubblingEvent; + + public EventCountingDispatcher() { + } + + public EventCountingDispatcher(final String label) { + super(label); + } + + public int getCapturingEventCount() { + return capturingEventCount; + } + + public int getBubblingEventCount() { + return bubblingEventCount; + } + + public void setConsumeCapturingEvent(final boolean consume) { + consumeCapturingEvent = consume; + } + + public void setConsumeBubblingEvent(final boolean consume) { + consumeBubblingEvent = consume; + } + + @Override + public Event dispatchEvent(final Event event, + final EventDispatchChain tail) { + ++capturingEventCount; + if (consumeCapturingEvent) { + return null; + } + + final Event returnEvent = tail.dispatchEvent(event); + if (returnEvent != null) { + ++bubblingEventCount; + } + + return consumeBubblingEvent ? null : returnEvent; + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/EventCountingHandler.java 2015-08-31 10:23:05.457217721 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.Event; -import javafx.event.EventHandler; - -public class EventCountingHandler implements EventHandler { - private int eventCount; - - public int getEventCount() { - return eventCount; - } - - @Override - public void handle(final T event) { - ++eventCount; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/EventCountingHandler.java 2015-08-31 10:23:05.321217722 -0400 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import javafx.event.Event; +import javafx.event.EventHandler; + +public class EventCountingHandler implements EventHandler { + private int eventCount; + + public int getEventCount() { + return eventCount; + } + + @Override + public void handle(final T event) { + ++eventCount; + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/EventDispatchChainTest.java 2015-08-31 10:23:06.293217711 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import java.util.Arrays; -import java.util.Collection; - -import javafx.event.EventDispatchChain; - -import org.junit.Test; -import org.junit.Assert; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -public final class EventDispatchChainTest { - private static final Operation[] IDENTITY_FUNCTION_OPS = { - Operation.mul(3), Operation.add(5), Operation.mul(4), Operation.sub(2), - Operation.div(6), Operation.add(9), Operation.div(2), Operation.sub(6) - }; - - @Parameters - public static Collection data() { - return Arrays.asList( - new Object[][] { - { EventDispatchChainImpl.class }, - { EventDispatchTreeImpl.class } - }); - } - - private EventDispatchChain eventDispatchChain; - - public EventDispatchChainTest(final Class chainClass) - throws InstantiationException, IllegalAccessException { - eventDispatchChain = chainClass.newInstance(); - } - - @Test - public void chainConstructionBeforeDispatchTest() { - eventDispatchChain = initializeTestChain(eventDispatchChain); - verifyChain(eventDispatchChain, 0, 702); - } - - @Test - public void chainModificationAfterDispatchTest() { - eventDispatchChain = initializeTestChain(eventDispatchChain); - eventDispatchChain.dispatchEvent(new ValueEvent()); - - eventDispatchChain = eventDispatchChain.append( - new EventChangingDispatcher( - Operation.sub(6), - Operation.div(3))); - verifyChain(eventDispatchChain, 0, 270); - - eventDispatchChain = prependIdentityChain(eventDispatchChain); - verifyChain(eventDispatchChain, 0, 270); - } - - @Test - public void chainModificationDuringDispatchTest() { - // x + 55, y + 55 - eventDispatchChain = prependSeriesChain(eventDispatchChain, 10); - eventDispatchChain = - eventDispatchChain.prepend( - new PathChangingDispatcher( - new EventChangingDispatcher(Operation.mul(3), - Operation.div(5)), - new EventChangingDispatcher(Operation.div(7), - Operation.mul(9)), - 1)); - // x + 15, y + 15 - eventDispatchChain = prependSeriesChain(eventDispatchChain, 5); - - eventDispatchChain = - eventDispatchChain.prepend( - new PathChangingDispatcher(null, null, 2)); - - // x + 6, y + 6 - eventDispatchChain = prependSeriesChain(eventDispatchChain, 3); - - for (int x = 0; x < 5; ++x) { - verifyChain(eventDispatchChain, 1225 * x - 86, 729 * x + 50); - } - } - - @Test - public void buildLongChainTest() { - eventDispatchChain = prependSeriesChain(eventDispatchChain, 100); - verifyChain(eventDispatchChain, 0, 10100); - - eventDispatchChain = prependIdentityChain(eventDispatchChain); - verifyChain(eventDispatchChain, 1, 10101); - - eventDispatchChain = prependSeriesChain(eventDispatchChain, 100); - verifyChain(eventDispatchChain, 2, 20202); - } - - private static EventDispatchChain prependIdentityChain( - EventDispatchChain tailChain) { - for (int i = 0; i < IDENTITY_FUNCTION_OPS.length; ++i) { - tailChain = tailChain.prepend( - new EventChangingDispatcher( - IDENTITY_FUNCTION_OPS[ - IDENTITY_FUNCTION_OPS.length - i - 1], - IDENTITY_FUNCTION_OPS[i])); - } - - return tailChain; - } - - private static EventDispatchChain prependSeriesChain( - EventDispatchChain tailChain, final int count) { - for (int i = 1; i <= count; ++i) { - tailChain = tailChain.prepend( - new EventChangingDispatcher(Operation.add(i), - Operation.add(i))); - } - - return tailChain; - } - - private static EventDispatchChain initializeTestChain( - final EventDispatchChain emptyChain) { - return emptyChain.append(new EventChangingDispatcher( - Operation.add(3), - Operation.div(2))) - .append(new EventChangingDispatcher( - Operation.mul(7), - Operation.sub(6))) - .prepend(new EventChangingDispatcher( - Operation.sub(4), - Operation.mul(6))) - .append(new EventChangingDispatcher( - Operation.div(3), - Operation.add(11))) - .prepend(new EventChangingDispatcher( - Operation.add(10), - Operation.mul(9))); - } - - private static void verifyChain(final EventDispatchChain testChain, - final int initialValue, - final int resultValue) { - final ValueEvent valueEvent = - (ValueEvent) testChain.dispatchEvent( - new ValueEvent(initialValue)); - - Assert.assertNotNull(valueEvent); - Assert.assertEquals(resultValue, valueEvent.getValue()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/EventDispatchChainTest.java 2015-08-31 10:23:06.085217714 -0400 @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import com.sun.javafx.event.EventDispatchChainImpl; +import com.sun.javafx.event.EventDispatchTreeImpl; +import java.util.Arrays; +import java.util.Collection; + +import javafx.event.EventDispatchChain; + +import org.junit.Test; +import org.junit.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public final class EventDispatchChainTest { + private static final Operation[] IDENTITY_FUNCTION_OPS = { + Operation.mul(3), Operation.add(5), Operation.mul(4), Operation.sub(2), + Operation.div(6), Operation.add(9), Operation.div(2), Operation.sub(6) + }; + + @Parameters + public static Collection data() { + return Arrays.asList( + new Object[][] { + { EventDispatchChainImpl.class }, + { EventDispatchTreeImpl.class } + }); + } + + private EventDispatchChain eventDispatchChain; + + public EventDispatchChainTest(final Class chainClass) + throws InstantiationException, IllegalAccessException { + eventDispatchChain = chainClass.newInstance(); + } + + @Test + public void chainConstructionBeforeDispatchTest() { + eventDispatchChain = initializeTestChain(eventDispatchChain); + verifyChain(eventDispatchChain, 0, 702); + } + + @Test + public void chainModificationAfterDispatchTest() { + eventDispatchChain = initializeTestChain(eventDispatchChain); + eventDispatchChain.dispatchEvent(new ValueEvent()); + + eventDispatchChain = eventDispatchChain.append( + new EventChangingDispatcher( + Operation.sub(6), + Operation.div(3))); + verifyChain(eventDispatchChain, 0, 270); + + eventDispatchChain = prependIdentityChain(eventDispatchChain); + verifyChain(eventDispatchChain, 0, 270); + } + + @Test + public void chainModificationDuringDispatchTest() { + // x + 55, y + 55 + eventDispatchChain = prependSeriesChain(eventDispatchChain, 10); + eventDispatchChain = + eventDispatchChain.prepend( + new PathChangingDispatcher( + new EventChangingDispatcher(Operation.mul(3), + Operation.div(5)), + new EventChangingDispatcher(Operation.div(7), + Operation.mul(9)), + 1)); + // x + 15, y + 15 + eventDispatchChain = prependSeriesChain(eventDispatchChain, 5); + + eventDispatchChain = + eventDispatchChain.prepend( + new PathChangingDispatcher(null, null, 2)); + + // x + 6, y + 6 + eventDispatchChain = prependSeriesChain(eventDispatchChain, 3); + + for (int x = 0; x < 5; ++x) { + verifyChain(eventDispatchChain, 1225 * x - 86, 729 * x + 50); + } + } + + @Test + public void buildLongChainTest() { + eventDispatchChain = prependSeriesChain(eventDispatchChain, 100); + verifyChain(eventDispatchChain, 0, 10100); + + eventDispatchChain = prependIdentityChain(eventDispatchChain); + verifyChain(eventDispatchChain, 1, 10101); + + eventDispatchChain = prependSeriesChain(eventDispatchChain, 100); + verifyChain(eventDispatchChain, 2, 20202); + } + + private static EventDispatchChain prependIdentityChain( + EventDispatchChain tailChain) { + for (int i = 0; i < IDENTITY_FUNCTION_OPS.length; ++i) { + tailChain = tailChain.prepend( + new EventChangingDispatcher( + IDENTITY_FUNCTION_OPS[ + IDENTITY_FUNCTION_OPS.length - i - 1], + IDENTITY_FUNCTION_OPS[i])); + } + + return tailChain; + } + + private static EventDispatchChain prependSeriesChain( + EventDispatchChain tailChain, final int count) { + for (int i = 1; i <= count; ++i) { + tailChain = tailChain.prepend( + new EventChangingDispatcher(Operation.add(i), + Operation.add(i))); + } + + return tailChain; + } + + private static EventDispatchChain initializeTestChain( + final EventDispatchChain emptyChain) { + return emptyChain.append(new EventChangingDispatcher( + Operation.add(3), + Operation.div(2))) + .append(new EventChangingDispatcher( + Operation.mul(7), + Operation.sub(6))) + .prepend(new EventChangingDispatcher( + Operation.sub(4), + Operation.mul(6))) + .append(new EventChangingDispatcher( + Operation.div(3), + Operation.add(11))) + .prepend(new EventChangingDispatcher( + Operation.add(10), + Operation.mul(9))); + } + + private static void verifyChain(final EventDispatchChain testChain, + final int initialValue, + final int resultValue) { + final ValueEvent valueEvent = + (ValueEvent) testChain.dispatchEvent( + new ValueEvent(initialValue)); + + Assert.assertNotNull(valueEvent); + Assert.assertEquals(resultValue, valueEvent.getValue()); + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/EventDispatchTreeTest.java 2015-08-31 10:23:07.029217703 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,235 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.EventDispatcher; -import org.junit.Assert; -import org.junit.Test; - -public final class EventDispatchTreeTest { - @Test - public void resetTest() { - EventDispatchTree eventDispatchTree = new EventDispatchTreeImpl(); - - final EventDispatcher dispatcherA = new LabeledEventDispatcher("A"); - final EventDispatcher dispatcherB = new LabeledEventDispatcher("B"); - final EventDispatcher dispatcherC = new LabeledEventDispatcher("C"); - - eventDispatchTree = eventDispatchTree.append(dispatcherA); - ((EventDispatchTreeImpl) eventDispatchTree).reset(); - - eventDispatchTree = eventDispatchTree.append(dispatcherB) - .append(dispatcherC); - - Assert.assertEquals("(B->(C))", eventDispatchTree.toString()); - } - - @Test - public void mergeTreeTest() { - EventDispatchTree eventDispatchTree = - new EventDispatchTreeImpl(); - - final EventDispatcher[] dispatchers = - new EventDispatcher[12]; - for (int i = 0; i < dispatchers.length; ++i) { - dispatchers[i] = new LabeledEventDispatcher(Integer.toString(i)); - } - - eventDispatchTree = - eventDispatchTree.mergeTree( - eventDispatchTree.createTree() - .append(dispatchers[0]) - .append(dispatchers[1]) - .append(dispatchers[2]) - .append(dispatchers[3])); - - eventDispatchTree = - eventDispatchTree.mergeTree( - eventDispatchTree.createTree() - .append(dispatchers[4]) - .append(dispatchers[6]) - .prepend(dispatchers[2]) - .prepend(dispatchers[1]) - .prepend(dispatchers[0])); - - eventDispatchTree = - eventDispatchTree.mergeTree( - eventDispatchTree.createTree() - .prepend(dispatchers[7]) - .prepend(dispatchers[5]) - .prepend(dispatchers[4]) - .prepend(dispatchers[2]) - .prepend(dispatchers[1]) - .prepend(dispatchers[0])); - - eventDispatchTree = - eventDispatchTree.mergeTree( - eventDispatchTree.createTree() - .prepend(dispatchers[2]) - .prepend(dispatchers[1]) - .prepend(dispatchers[0]) - .append(dispatchers[4]) - .append(dispatchers[5]) - .append(dispatchers[8])); - - - eventDispatchTree = eventDispatchTree.prepend(dispatchers[9]); - eventDispatchTree = eventDispatchTree.append(dispatchers[10]); - - - eventDispatchTree = - eventDispatchTree.mergeTree( - eventDispatchTree.createTree() - .append(dispatchers[0]) - .append(dispatchers[1]) - .append(dispatchers[2]) - .append(dispatchers[4]) - .append(dispatchers[6]) - .append(dispatchers[10]) - .append(dispatchers[11])); - eventDispatchTree = - eventDispatchTree.mergeTree( - eventDispatchTree.createTree() - .append(dispatchers[9]) - .append(dispatchers[0]) - .append(dispatchers[1]) - .append(dispatchers[2]) - .append(dispatchers[4]) - .append(dispatchers[6]) - .append(dispatchers[10]) - .append(dispatchers[11])); - - // /| - // 9 0 - // / | - // 0 1 - // / | - // 1 2 - // / | - // 2 4 - // / \ | - // 3 4 6 - // / / \ | - // 10 6 5 10 - // / / \ | - // 10 7 8 11 - // | | | - // 11 10 10 - - Assert.assertEquals( - "(9->(0->(1->(2->(3->(10),4->(6->(10->(11)),5->" - + "(7->(10),8->(10)))))))," - + "0->(1->(2->(4->(6->(10->(11)))))))", - eventDispatchTree.toString()); - } - - @Test - public void dispatchEventTest() { - final EventCountingDispatcher[] dispatchers = - new EventCountingDispatcher[8]; - for (int i = 0; i < dispatchers.length; ++i) { - dispatchers[i] = new EventCountingDispatcher(Integer.toString(i)); - } - - EventDispatchTree eventDispatchTree = - new EventDispatchTreeImpl(); - - eventDispatchTree = eventDispatchTree.append(dispatchers[1]); - - eventDispatchTree = - eventDispatchTree.mergeTree( - eventDispatchTree.createTree().append(dispatchers[2]) - .append(dispatchers[4])); - - eventDispatchTree = - eventDispatchTree.mergeTree( - eventDispatchTree.createTree().append(dispatchers[2]) - .append(dispatchers[5]) - .append(dispatchers[7])); - - eventDispatchTree = - eventDispatchTree.mergeTree( - eventDispatchTree.createTree().append(dispatchers[3]) - .append(dispatchers[6])); - - eventDispatchTree = eventDispatchTree.prepend(dispatchers[0]); - - // 0 - // /|\ - // 1 2 3 - // / \ \ - // 4 5 6 - // | - // 7 - - eventDispatchTree.dispatchEvent(new EmptyEvent()); - verifyCapturingEventCounters(dispatchers, 1, 1, 1, 1, 1, 1, 1, 1); - verifyBubblingEventCounters(dispatchers, 1, 1, 1, 1, 1, 1, 1, 1); - - dispatchers[0].setConsumeCapturingEvent(true); - eventDispatchTree.dispatchEvent(new EmptyEvent()); - verifyCapturingEventCounters(dispatchers, 2, 1, 1, 1, 1, 1, 1, 1); - verifyBubblingEventCounters(dispatchers, 1, 1, 1, 1, 1, 1, 1, 1); - - dispatchers[0].setConsumeCapturingEvent(false); - dispatchers[2].setConsumeCapturingEvent(true); - eventDispatchTree.dispatchEvent(new EmptyEvent()); - verifyCapturingEventCounters(dispatchers, 3, 2, 2, 2, 1, 1, 2, 1); - verifyBubblingEventCounters(dispatchers, 2, 2, 1, 2, 1, 1, 2, 1); - - dispatchers[2].setConsumeCapturingEvent(false); - dispatchers[7].setConsumeBubblingEvent(true); - eventDispatchTree.dispatchEvent(new EmptyEvent()); - verifyCapturingEventCounters(dispatchers, 4, 3, 3, 3, 2, 2, 3, 2); - verifyBubblingEventCounters(dispatchers, 3, 3, 2, 3, 2, 1, 3, 2); - - dispatchers[4].setConsumeBubblingEvent(true); - dispatchers[7].setConsumeBubblingEvent(true); - eventDispatchTree.dispatchEvent(new EmptyEvent()); - verifyCapturingEventCounters(dispatchers, 5, 4, 4, 4, 3, 3, 4, 3); - verifyBubblingEventCounters(dispatchers, 4, 4, 2, 4, 3, 1, 4, 3); - } - - private static void verifyCapturingEventCounters( - final EventCountingDispatcher[] dispatchers, - final int... counters) { - for (int i = 0; i < dispatchers.length; ++i) { - Assert.assertEquals( - counters[i], - dispatchers[i].getCapturingEventCount()); - } - } - - private static void verifyBubblingEventCounters( - final EventCountingDispatcher[] dispatchers, - final int... counters) { - for (int i = 0; i < dispatchers.length; ++i) { - Assert.assertEquals( - counters[i], - dispatchers[i].getBubblingEventCount()); - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/EventDispatchTreeTest.java 2015-08-31 10:23:06.833217705 -0400 @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import com.sun.javafx.event.EventDispatchTree; +import com.sun.javafx.event.EventDispatchTreeImpl; +import javafx.event.EventDispatcher; +import org.junit.Assert; +import org.junit.Test; + +public final class EventDispatchTreeTest { + @Test + public void resetTest() { + EventDispatchTree eventDispatchTree = new EventDispatchTreeImpl(); + + final EventDispatcher dispatcherA = new LabeledEventDispatcher("A"); + final EventDispatcher dispatcherB = new LabeledEventDispatcher("B"); + final EventDispatcher dispatcherC = new LabeledEventDispatcher("C"); + + eventDispatchTree = eventDispatchTree.append(dispatcherA); + ((EventDispatchTreeImpl) eventDispatchTree).reset(); + + eventDispatchTree = eventDispatchTree.append(dispatcherB) + .append(dispatcherC); + + Assert.assertEquals("(B->(C))", eventDispatchTree.toString()); + } + + @Test + public void mergeTreeTest() { + EventDispatchTree eventDispatchTree = + new EventDispatchTreeImpl(); + + final EventDispatcher[] dispatchers = + new EventDispatcher[12]; + for (int i = 0; i < dispatchers.length; ++i) { + dispatchers[i] = new LabeledEventDispatcher(Integer.toString(i)); + } + + eventDispatchTree = + eventDispatchTree.mergeTree( + eventDispatchTree.createTree() + .append(dispatchers[0]) + .append(dispatchers[1]) + .append(dispatchers[2]) + .append(dispatchers[3])); + + eventDispatchTree = + eventDispatchTree.mergeTree( + eventDispatchTree.createTree() + .append(dispatchers[4]) + .append(dispatchers[6]) + .prepend(dispatchers[2]) + .prepend(dispatchers[1]) + .prepend(dispatchers[0])); + + eventDispatchTree = + eventDispatchTree.mergeTree( + eventDispatchTree.createTree() + .prepend(dispatchers[7]) + .prepend(dispatchers[5]) + .prepend(dispatchers[4]) + .prepend(dispatchers[2]) + .prepend(dispatchers[1]) + .prepend(dispatchers[0])); + + eventDispatchTree = + eventDispatchTree.mergeTree( + eventDispatchTree.createTree() + .prepend(dispatchers[2]) + .prepend(dispatchers[1]) + .prepend(dispatchers[0]) + .append(dispatchers[4]) + .append(dispatchers[5]) + .append(dispatchers[8])); + + + eventDispatchTree = eventDispatchTree.prepend(dispatchers[9]); + eventDispatchTree = eventDispatchTree.append(dispatchers[10]); + + + eventDispatchTree = + eventDispatchTree.mergeTree( + eventDispatchTree.createTree() + .append(dispatchers[0]) + .append(dispatchers[1]) + .append(dispatchers[2]) + .append(dispatchers[4]) + .append(dispatchers[6]) + .append(dispatchers[10]) + .append(dispatchers[11])); + eventDispatchTree = + eventDispatchTree.mergeTree( + eventDispatchTree.createTree() + .append(dispatchers[9]) + .append(dispatchers[0]) + .append(dispatchers[1]) + .append(dispatchers[2]) + .append(dispatchers[4]) + .append(dispatchers[6]) + .append(dispatchers[10]) + .append(dispatchers[11])); + + // /| + // 9 0 + // / | + // 0 1 + // / | + // 1 2 + // / | + // 2 4 + // / \ | + // 3 4 6 + // / / \ | + // 10 6 5 10 + // / / \ | + // 10 7 8 11 + // | | | + // 11 10 10 + + Assert.assertEquals( + "(9->(0->(1->(2->(3->(10),4->(6->(10->(11)),5->" + + "(7->(10),8->(10)))))))," + + "0->(1->(2->(4->(6->(10->(11)))))))", + eventDispatchTree.toString()); + } + + @Test + public void dispatchEventTest() { + final EventCountingDispatcher[] dispatchers = + new EventCountingDispatcher[8]; + for (int i = 0; i < dispatchers.length; ++i) { + dispatchers[i] = new EventCountingDispatcher(Integer.toString(i)); + } + + EventDispatchTree eventDispatchTree = + new EventDispatchTreeImpl(); + + eventDispatchTree = eventDispatchTree.append(dispatchers[1]); + + eventDispatchTree = + eventDispatchTree.mergeTree( + eventDispatchTree.createTree().append(dispatchers[2]) + .append(dispatchers[4])); + + eventDispatchTree = + eventDispatchTree.mergeTree( + eventDispatchTree.createTree().append(dispatchers[2]) + .append(dispatchers[5]) + .append(dispatchers[7])); + + eventDispatchTree = + eventDispatchTree.mergeTree( + eventDispatchTree.createTree().append(dispatchers[3]) + .append(dispatchers[6])); + + eventDispatchTree = eventDispatchTree.prepend(dispatchers[0]); + + // 0 + // /|\ + // 1 2 3 + // / \ \ + // 4 5 6 + // | + // 7 + + eventDispatchTree.dispatchEvent(new EmptyEvent()); + verifyCapturingEventCounters(dispatchers, 1, 1, 1, 1, 1, 1, 1, 1); + verifyBubblingEventCounters(dispatchers, 1, 1, 1, 1, 1, 1, 1, 1); + + dispatchers[0].setConsumeCapturingEvent(true); + eventDispatchTree.dispatchEvent(new EmptyEvent()); + verifyCapturingEventCounters(dispatchers, 2, 1, 1, 1, 1, 1, 1, 1); + verifyBubblingEventCounters(dispatchers, 1, 1, 1, 1, 1, 1, 1, 1); + + dispatchers[0].setConsumeCapturingEvent(false); + dispatchers[2].setConsumeCapturingEvent(true); + eventDispatchTree.dispatchEvent(new EmptyEvent()); + verifyCapturingEventCounters(dispatchers, 3, 2, 2, 2, 1, 1, 2, 1); + verifyBubblingEventCounters(dispatchers, 2, 2, 1, 2, 1, 1, 2, 1); + + dispatchers[2].setConsumeCapturingEvent(false); + dispatchers[7].setConsumeBubblingEvent(true); + eventDispatchTree.dispatchEvent(new EmptyEvent()); + verifyCapturingEventCounters(dispatchers, 4, 3, 3, 3, 2, 2, 3, 2); + verifyBubblingEventCounters(dispatchers, 3, 3, 2, 3, 2, 1, 3, 2); + + dispatchers[4].setConsumeBubblingEvent(true); + dispatchers[7].setConsumeBubblingEvent(true); + eventDispatchTree.dispatchEvent(new EmptyEvent()); + verifyCapturingEventCounters(dispatchers, 5, 4, 4, 4, 3, 3, 4, 3); + verifyBubblingEventCounters(dispatchers, 4, 4, 2, 4, 3, 1, 4, 3); + } + + private static void verifyCapturingEventCounters( + final EventCountingDispatcher[] dispatchers, + final int... counters) { + for (int i = 0; i < dispatchers.length; ++i) { + Assert.assertEquals( + counters[i], + dispatchers[i].getCapturingEventCount()); + } + } + + private static void verifyBubblingEventCounters( + final EventCountingDispatcher[] dispatchers, + final int... counters) { + for (int i = 0; i < dispatchers.length; ++i) { + Assert.assertEquals( + counters[i], + dispatchers[i].getBubblingEventCount()); + } + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/EventHandlerManagerTest.java 2015-08-31 10:23:07.637217696 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,566 +0,0 @@ -/* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.Event; -import javafx.event.EventDispatchChain; -import javafx.event.EventDispatcher; -import javafx.event.EventHandler; -import javafx.event.EventType; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public final class EventHandlerManagerTest { - private EventHandlerManager eventHandlerManager; - - @Before - public void setUp() { - eventHandlerManager = new EventHandlerManager(this); - } - - @Test - public void shouldForwardEventsToChain() { - final EventDispatchChain eventDispatchChain = - StubEventDispatchChain.EMPTY_CHAIN - .append(eventHandlerManager) - .append(new EventChangingDispatcher( - Operation.add(4), - Operation.div(3))); - - ValueEvent valueEvent; - - valueEvent = (ValueEvent) eventDispatchChain.dispatchEvent( - new ValueEvent(2)); - Assert.assertEquals(2, valueEvent.getValue()); - - valueEvent = (ValueEvent) eventDispatchChain.dispatchEvent( - new ValueEvent(5)); - Assert.assertEquals(3, valueEvent.getValue()); - } - - @Test - public void shouldCallCorrectSingletonHandlers() { - eventHandlerManager.setEventHandler( - ValueEvent.VALUE_A, - new EventChangingHandler(Operation.add(5))); - eventHandlerManager.setEventHandler( - ValueEvent.VALUE_B, - new EventChangingHandler(Operation.mul(3))); - eventHandlerManager.setEventHandler( - ValueEvent.VALUE_C, - new EventChangingHandler(Operation.mul(7))); - - final EventCountingHandler emptyEventCountingHandler = - new EventCountingHandler(); - eventHandlerManager.setEventHandler( - EmptyEvent.EMPTY, - emptyEventCountingHandler); - - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_A, 11, 16); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_C, 3, 21); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_B, 6, 18); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_C, 5, 35); - - Assert.assertEquals(0, emptyEventCountingHandler.getEventCount()); - dispatchEmptyEvent(eventHandlerManager); - Assert.assertEquals(1, emptyEventCountingHandler.getEventCount()); - dispatchEmptyEvent(eventHandlerManager); - Assert.assertEquals(2, emptyEventCountingHandler.getEventCount()); - } - - @Test - public void shouldAllowReplaceSingletonHandlers() { - eventHandlerManager.setEventHandler( - ValueEvent.VALUE_B, - new EventChangingHandler(Operation.add(5))); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_B, 3, 8); - - eventHandlerManager.setEventHandler( - ValueEvent.VALUE_B, - new EventChangingHandler(Operation.mul(3))); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_B, 7, 21); - - eventHandlerManager.setEventHandler( - ValueEvent.VALUE_B, - null); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_B, 5, 5); - } - - @Test - public void shouldCallCorrectAddedHandlers() { - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_A, - new EventChangingHandler(Operation.add(5))); - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_B, - new EventChangingHandler(Operation.mul(3))); - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_C, - new EventChangingHandler(Operation.mul(7))); - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_A, - new EventChangingHandler(Operation.add(2))); - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_B, - new EventChangingHandler(Operation.mul(4))); - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_C, - new EventChangingHandler(Operation.mul(6))); - - final EventCountingHandler emptyEventCountingHandler = - new EventCountingHandler(); - eventHandlerManager.addEventHandler( - EmptyEvent.EMPTY, - emptyEventCountingHandler); - - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_A, 11, 18); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_C, 3, 126); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_B, 6, 72); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_C, 5, 210); - - Assert.assertEquals(0, emptyEventCountingHandler.getEventCount()); - dispatchEmptyEvent(eventHandlerManager); - Assert.assertEquals(1, emptyEventCountingHandler.getEventCount()); - dispatchEmptyEvent(eventHandlerManager); - Assert.assertEquals(2, emptyEventCountingHandler.getEventCount()); - } - - @Test - public void shouldCallCorrectAddedFilters() { - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_A, - new EventChangingHandler(Operation.add(5))); - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_B, - new EventChangingHandler(Operation.mul(3))); - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_C, - new EventChangingHandler(Operation.mul(7))); - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_A, - new EventChangingHandler(Operation.add(2))); - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_B, - new EventChangingHandler(Operation.mul(4))); - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_C, - new EventChangingHandler(Operation.mul(6))); - - final EventCountingHandler emptyEventCountingHandler = - new EventCountingHandler(); - eventHandlerManager.addEventFilter( - EmptyEvent.EMPTY, - emptyEventCountingHandler); - - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_A, 11, 18); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_C, 3, 126); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_B, 6, 72); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_C, 5, 210); - - Assert.assertEquals(0, emptyEventCountingHandler.getEventCount()); - dispatchEmptyEvent(eventHandlerManager); - Assert.assertEquals(1, emptyEventCountingHandler.getEventCount()); - dispatchEmptyEvent(eventHandlerManager); - Assert.assertEquals(2, emptyEventCountingHandler.getEventCount()); - } - - @Test - public void shouldAllowRemoveHandlersAndFilters() { - final EventHandler handlerFilterToRemove = - new EventChangingHandler(Operation.add(5)); - - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_A, - handlerFilterToRemove); - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_A, - new EventChangingHandler(Operation.add(2))); - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_A, - handlerFilterToRemove); - - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_A, 11, 23); - eventHandlerManager.removeEventHandler( - ValueEvent.VALUE_A, handlerFilterToRemove); - eventHandlerManager.removeEventFilter( - ValueEvent.VALUE_B, handlerFilterToRemove); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_A, 11, 18); - eventHandlerManager.removeEventFilter( - ValueEvent.VALUE_A, handlerFilterToRemove); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_A, 11, 13); - } - - @Test - public void shouldNotAddHandlerTwice() { - final EventHandler eventHandler = - new EventChangingHandler(Operation.mul(2)); - - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_A, - eventHandler); - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_B, - eventHandler); - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_A, - eventHandler); - - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_A, 1, 2); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_B, 1, 2); - - eventHandlerManager.removeEventHandler( - ValueEvent.VALUE_A, eventHandler); - - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_A, 1, 1); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_B, 1, 2); - } - - @Test - public void shouldNotAddFilterTwice() { - final EventHandler eventFilter = - new EventChangingHandler(Operation.mul(2)); - - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_A, - eventFilter); - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_B, - eventFilter); - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_A, - eventFilter); - - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_A, 1, 2); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_B, 1, 2); - - eventHandlerManager.removeEventFilter( - ValueEvent.VALUE_A, eventFilter); - - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_A, 1, 1); - testValueEventDispatch( - eventHandlerManager, ValueEvent.VALUE_B, 1, 2); - } - - @Test - public void shouldCallInCorrectOrder() { - final EventDispatchChain eventDispatchChain = - StubEventDispatchChain.EMPTY_CHAIN - .append(eventHandlerManager) - .append(new EventChangingDispatcher( - Operation.add(4), - Operation.div(3))); - - eventHandlerManager.setEventHandler( - ValueEvent.VALUE_A, - new EventChangingHandler(Operation.mul(2))); - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_A, - new EventChangingHandler(Operation.add(5))); - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_A, - new EventChangingHandler(Operation.div(7))); - - ValueEvent valueEvent; - - valueEvent = (ValueEvent) eventDispatchChain.dispatchEvent( - new ValueEvent(35)); - Assert.assertEquals(16, valueEvent.getValue()); - } - - @Test - public void shouldCallHandlersForSuperTypes() { - final EventCountingHandler rootEventCounter = - new EventCountingHandler(); - final EventCountingHandler valueEventCounter = - new EventCountingHandler(); - final EventCountingHandler valueAEventCounter = - new EventCountingHandler(); - final EventCountingHandler valueBEventCounter = - new EventCountingHandler(); - final EventCountingHandler emptyEventCounter = - new EventCountingHandler(); - - eventHandlerManager.addEventHandler( - EventType.ROOT, rootEventCounter); - eventHandlerManager.addEventHandler( - ValueEvent.ANY, valueEventCounter); - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_A, valueAEventCounter); - eventHandlerManager.addEventHandler( - ValueEvent.VALUE_B, valueBEventCounter); - eventHandlerManager.addEventHandler( - EmptyEvent.EMPTY, emptyEventCounter); - - dispatchEmptyEvent(eventHandlerManager); - dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_A); - dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_B); - dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_C); - dispatchEmptyEvent(eventHandlerManager); - - Assert.assertEquals(5, rootEventCounter.getEventCount()); - Assert.assertEquals(3, valueEventCounter.getEventCount()); - Assert.assertEquals(1, valueAEventCounter.getEventCount()); - Assert.assertEquals(1, valueBEventCounter.getEventCount()); - Assert.assertEquals(2, emptyEventCounter.getEventCount()); - } - - @Test - public void shouldCallFiltersForSuperTypes() { - final EventCountingHandler rootEventCounter = - new EventCountingHandler(); - final EventCountingHandler valueEventCounter = - new EventCountingHandler(); - final EventCountingHandler valueAEventCounter = - new EventCountingHandler(); - final EventCountingHandler valueBEventCounter = - new EventCountingHandler(); - final EventCountingHandler emptyEventCounter = - new EventCountingHandler(); - - eventHandlerManager.addEventFilter( - EventType.ROOT, rootEventCounter); - eventHandlerManager.addEventFilter( - ValueEvent.ANY, valueEventCounter); - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_A, valueAEventCounter); - eventHandlerManager.addEventFilter( - ValueEvent.VALUE_B, valueBEventCounter); - eventHandlerManager.addEventFilter( - EmptyEvent.EMPTY, emptyEventCounter); - - dispatchEmptyEvent(eventHandlerManager); - dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_A); - dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_B); - dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_C); - dispatchEmptyEvent(eventHandlerManager); - - Assert.assertEquals(5, rootEventCounter.getEventCount()); - Assert.assertEquals(3, valueEventCounter.getEventCount()); - Assert.assertEquals(1, valueAEventCounter.getEventCount()); - Assert.assertEquals(1, valueBEventCounter.getEventCount()); - Assert.assertEquals(2, emptyEventCounter.getEventCount()); - } - - @Test - public void eventConsumedInHandlerTest() { - final EventCountingDispatcher eventCountingDispatcher = - new EventCountingDispatcher(); - final EventDispatchChain eventDispatchChain = - StubEventDispatchChain.EMPTY_CHAIN - .append(eventHandlerManager) - .append(eventCountingDispatcher); - - final EventCountingHandler eventCountingFilter = - new EventCountingHandler(); - final EventCountingHandler eventCountingHandler = - new EventCountingHandler(); - final EventConsumingHandler eventConsumingHandler = - new EventConsumingHandler(); - - eventHandlerManager.addEventFilter(Event.ANY, eventCountingFilter); - - // add counting first, consuming second - eventHandlerManager.addEventHandler(Event.ANY, eventCountingHandler); - eventHandlerManager.addEventHandler(Event.ANY, eventConsumingHandler); - - Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); - Assert.assertEquals(1, eventCountingFilter.getEventCount()); - Assert.assertEquals( - 1, eventCountingDispatcher.getCapturingEventCount()); - Assert.assertEquals(1, eventCountingHandler.getEventCount()); - - eventHandlerManager.removeEventHandler( - Event.ANY, eventCountingHandler); - eventHandlerManager.removeEventHandler( - Event.ANY, eventConsumingHandler); - - // add consuming first, counting second - eventHandlerManager.addEventHandler(Event.ANY, eventConsumingHandler); - eventHandlerManager.addEventHandler(Event.ANY, eventCountingHandler); - - Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); - Assert.assertEquals(2, eventCountingFilter.getEventCount()); - Assert.assertEquals( - 2, eventCountingDispatcher.getCapturingEventCount()); - Assert.assertEquals(2, eventCountingHandler.getEventCount()); - } - - @Test - public void eventConsumedInFilterTest() { - final EventCountingDispatcher eventCountingDispatcher = - new EventCountingDispatcher(); - final EventDispatchChain eventDispatchChain = - StubEventDispatchChain.EMPTY_CHAIN - .append(eventHandlerManager) - .append(eventCountingDispatcher); - - final EventCountingHandler eventCountingFilter = - new EventCountingHandler(); - final EventConsumingHandler eventConsumingFilter = - new EventConsumingHandler(); - final EventCountingHandler eventCountingHandler = - new EventCountingHandler(); - - eventHandlerManager.addEventHandler(Event.ANY, eventCountingHandler); - - // add counting first, consuming second - eventHandlerManager.addEventFilter(Event.ANY, eventCountingFilter); - eventHandlerManager.addEventFilter(Event.ANY, eventConsumingFilter); - - Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); - Assert.assertEquals(1, eventCountingFilter.getEventCount()); - Assert.assertEquals( - 0, eventCountingDispatcher.getCapturingEventCount()); - Assert.assertEquals(0, eventCountingHandler.getEventCount()); - - eventHandlerManager.removeEventFilter(Event.ANY, eventCountingFilter); - eventHandlerManager.removeEventFilter(Event.ANY, eventConsumingFilter); - - // add consuming first, counting second - eventHandlerManager.addEventFilter(Event.ANY, eventConsumingFilter); - eventHandlerManager.addEventFilter(Event.ANY, eventCountingFilter); - - Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); - Assert.assertEquals(2, eventCountingFilter.getEventCount()); - Assert.assertEquals( - 0, eventCountingDispatcher.getCapturingEventCount()); - Assert.assertEquals(0, eventCountingHandler.getEventCount()); - } - - @Test(expected=NullPointerException.class) - public void addEventHandlerShouldThrowNPEForNullEventType() { - eventHandlerManager.addEventHandler( - null, - event -> { - }); - } - - @Test(expected=NullPointerException.class) - public void addEventHandlerShouldThrowNPEForNullEventHandler() { - eventHandlerManager.addEventHandler(Event.ANY, null); - } - - @Test(expected=NullPointerException.class) - public void removeEventHandlerShouldThrowNPEForNullEventType() { - eventHandlerManager.removeEventHandler( - null, - event -> { - }); - } - - @Test(expected=NullPointerException.class) - public void removeEventHandlerShouldThrowNPEForNullEventHandler() { - eventHandlerManager.removeEventHandler(Event.ANY, null); - } - - @Test(expected=NullPointerException.class) - public void addEventFilterShouldThrowNPEForNullEventType() { - eventHandlerManager.addEventFilter( - null, - event -> { - }); - } - - @Test(expected=NullPointerException.class) - public void addEventFilterShouldThrowNPEForNullEventHandler() { - eventHandlerManager.addEventFilter(Event.ANY, null); - } - - @Test(expected=NullPointerException.class) - public void removeEventFilterShouldThrowNPEForNullEventType() { - eventHandlerManager.removeEventHandler( - null, - event -> { - }); - } - - @Test(expected=NullPointerException.class) - public void removeEventFilterShouldThrowNPEForNullEventHandler() { - eventHandlerManager.removeEventHandler(Event.ANY, null); - } - - @Test(expected=NullPointerException.class) - public void setEventHandlerShouldThrowNPEForNullEventType() { - eventHandlerManager.setEventHandler( - null, - event -> { - }); - } - - private static void testValueEventDispatch( - final EventDispatcher eventDispatcher, - final EventType eventType, - final int initialValue, - final int calculatedValue) { - final ValueEvent valueEvent = - (ValueEvent) eventDispatcher.dispatchEvent( - new ValueEvent(eventType, initialValue), - StubEventDispatchChain.EMPTY_CHAIN); - Assert.assertEquals(calculatedValue, valueEvent.getValue()); - } - - private static Event dispatchEmptyEvent( - final EventDispatcher eventDispatcher) { - return eventDispatcher.dispatchEvent( - new EmptyEvent(), - StubEventDispatchChain.EMPTY_CHAIN); - } - - private static Event dispatchValueEvent( - final EventDispatcher eventDispatcher, - final EventType eventType) { - return eventDispatcher.dispatchEvent( - new ValueEvent(eventType, 0), - StubEventDispatchChain.EMPTY_CHAIN); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/EventHandlerManagerTest.java 2015-08-31 10:23:07.501217698 -0400 @@ -0,0 +1,567 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import com.sun.javafx.event.EventHandlerManager; +import javafx.event.Event; +import javafx.event.EventDispatchChain; +import javafx.event.EventDispatcher; +import javafx.event.EventHandler; +import javafx.event.EventType; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public final class EventHandlerManagerTest { + private EventHandlerManager eventHandlerManager; + + @Before + public void setUp() { + eventHandlerManager = new EventHandlerManager(this); + } + + @Test + public void shouldForwardEventsToChain() { + final EventDispatchChain eventDispatchChain = + StubEventDispatchChain.EMPTY_CHAIN + .append(eventHandlerManager) + .append(new EventChangingDispatcher( + Operation.add(4), + Operation.div(3))); + + ValueEvent valueEvent; + + valueEvent = (ValueEvent) eventDispatchChain.dispatchEvent( + new ValueEvent(2)); + Assert.assertEquals(2, valueEvent.getValue()); + + valueEvent = (ValueEvent) eventDispatchChain.dispatchEvent( + new ValueEvent(5)); + Assert.assertEquals(3, valueEvent.getValue()); + } + + @Test + public void shouldCallCorrectSingletonHandlers() { + eventHandlerManager.setEventHandler( + ValueEvent.VALUE_A, + new EventChangingHandler(Operation.add(5))); + eventHandlerManager.setEventHandler( + ValueEvent.VALUE_B, + new EventChangingHandler(Operation.mul(3))); + eventHandlerManager.setEventHandler( + ValueEvent.VALUE_C, + new EventChangingHandler(Operation.mul(7))); + + final EventCountingHandler emptyEventCountingHandler = + new EventCountingHandler(); + eventHandlerManager.setEventHandler( + EmptyEvent.EMPTY, + emptyEventCountingHandler); + + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_A, 11, 16); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_C, 3, 21); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_B, 6, 18); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_C, 5, 35); + + Assert.assertEquals(0, emptyEventCountingHandler.getEventCount()); + dispatchEmptyEvent(eventHandlerManager); + Assert.assertEquals(1, emptyEventCountingHandler.getEventCount()); + dispatchEmptyEvent(eventHandlerManager); + Assert.assertEquals(2, emptyEventCountingHandler.getEventCount()); + } + + @Test + public void shouldAllowReplaceSingletonHandlers() { + eventHandlerManager.setEventHandler( + ValueEvent.VALUE_B, + new EventChangingHandler(Operation.add(5))); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_B, 3, 8); + + eventHandlerManager.setEventHandler( + ValueEvent.VALUE_B, + new EventChangingHandler(Operation.mul(3))); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_B, 7, 21); + + eventHandlerManager.setEventHandler( + ValueEvent.VALUE_B, + null); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_B, 5, 5); + } + + @Test + public void shouldCallCorrectAddedHandlers() { + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_A, + new EventChangingHandler(Operation.add(5))); + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_B, + new EventChangingHandler(Operation.mul(3))); + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_C, + new EventChangingHandler(Operation.mul(7))); + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_A, + new EventChangingHandler(Operation.add(2))); + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_B, + new EventChangingHandler(Operation.mul(4))); + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_C, + new EventChangingHandler(Operation.mul(6))); + + final EventCountingHandler emptyEventCountingHandler = + new EventCountingHandler(); + eventHandlerManager.addEventHandler( + EmptyEvent.EMPTY, + emptyEventCountingHandler); + + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_A, 11, 18); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_C, 3, 126); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_B, 6, 72); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_C, 5, 210); + + Assert.assertEquals(0, emptyEventCountingHandler.getEventCount()); + dispatchEmptyEvent(eventHandlerManager); + Assert.assertEquals(1, emptyEventCountingHandler.getEventCount()); + dispatchEmptyEvent(eventHandlerManager); + Assert.assertEquals(2, emptyEventCountingHandler.getEventCount()); + } + + @Test + public void shouldCallCorrectAddedFilters() { + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_A, + new EventChangingHandler(Operation.add(5))); + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_B, + new EventChangingHandler(Operation.mul(3))); + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_C, + new EventChangingHandler(Operation.mul(7))); + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_A, + new EventChangingHandler(Operation.add(2))); + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_B, + new EventChangingHandler(Operation.mul(4))); + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_C, + new EventChangingHandler(Operation.mul(6))); + + final EventCountingHandler emptyEventCountingHandler = + new EventCountingHandler(); + eventHandlerManager.addEventFilter( + EmptyEvent.EMPTY, + emptyEventCountingHandler); + + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_A, 11, 18); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_C, 3, 126); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_B, 6, 72); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_C, 5, 210); + + Assert.assertEquals(0, emptyEventCountingHandler.getEventCount()); + dispatchEmptyEvent(eventHandlerManager); + Assert.assertEquals(1, emptyEventCountingHandler.getEventCount()); + dispatchEmptyEvent(eventHandlerManager); + Assert.assertEquals(2, emptyEventCountingHandler.getEventCount()); + } + + @Test + public void shouldAllowRemoveHandlersAndFilters() { + final EventHandler handlerFilterToRemove = + new EventChangingHandler(Operation.add(5)); + + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_A, + handlerFilterToRemove); + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_A, + new EventChangingHandler(Operation.add(2))); + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_A, + handlerFilterToRemove); + + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_A, 11, 23); + eventHandlerManager.removeEventHandler( + ValueEvent.VALUE_A, handlerFilterToRemove); + eventHandlerManager.removeEventFilter( + ValueEvent.VALUE_B, handlerFilterToRemove); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_A, 11, 18); + eventHandlerManager.removeEventFilter( + ValueEvent.VALUE_A, handlerFilterToRemove); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_A, 11, 13); + } + + @Test + public void shouldNotAddHandlerTwice() { + final EventHandler eventHandler = + new EventChangingHandler(Operation.mul(2)); + + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_A, + eventHandler); + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_B, + eventHandler); + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_A, + eventHandler); + + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_A, 1, 2); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_B, 1, 2); + + eventHandlerManager.removeEventHandler( + ValueEvent.VALUE_A, eventHandler); + + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_A, 1, 1); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_B, 1, 2); + } + + @Test + public void shouldNotAddFilterTwice() { + final EventHandler eventFilter = + new EventChangingHandler(Operation.mul(2)); + + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_A, + eventFilter); + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_B, + eventFilter); + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_A, + eventFilter); + + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_A, 1, 2); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_B, 1, 2); + + eventHandlerManager.removeEventFilter( + ValueEvent.VALUE_A, eventFilter); + + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_A, 1, 1); + testValueEventDispatch( + eventHandlerManager, ValueEvent.VALUE_B, 1, 2); + } + + @Test + public void shouldCallInCorrectOrder() { + final EventDispatchChain eventDispatchChain = + StubEventDispatchChain.EMPTY_CHAIN + .append(eventHandlerManager) + .append(new EventChangingDispatcher( + Operation.add(4), + Operation.div(3))); + + eventHandlerManager.setEventHandler( + ValueEvent.VALUE_A, + new EventChangingHandler(Operation.mul(2))); + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_A, + new EventChangingHandler(Operation.add(5))); + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_A, + new EventChangingHandler(Operation.div(7))); + + ValueEvent valueEvent; + + valueEvent = (ValueEvent) eventDispatchChain.dispatchEvent( + new ValueEvent(35)); + Assert.assertEquals(16, valueEvent.getValue()); + } + + @Test + public void shouldCallHandlersForSuperTypes() { + final EventCountingHandler rootEventCounter = + new EventCountingHandler(); + final EventCountingHandler valueEventCounter = + new EventCountingHandler(); + final EventCountingHandler valueAEventCounter = + new EventCountingHandler(); + final EventCountingHandler valueBEventCounter = + new EventCountingHandler(); + final EventCountingHandler emptyEventCounter = + new EventCountingHandler(); + + eventHandlerManager.addEventHandler( + EventType.ROOT, rootEventCounter); + eventHandlerManager.addEventHandler( + ValueEvent.ANY, valueEventCounter); + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_A, valueAEventCounter); + eventHandlerManager.addEventHandler( + ValueEvent.VALUE_B, valueBEventCounter); + eventHandlerManager.addEventHandler( + EmptyEvent.EMPTY, emptyEventCounter); + + dispatchEmptyEvent(eventHandlerManager); + dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_A); + dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_B); + dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_C); + dispatchEmptyEvent(eventHandlerManager); + + Assert.assertEquals(5, rootEventCounter.getEventCount()); + Assert.assertEquals(3, valueEventCounter.getEventCount()); + Assert.assertEquals(1, valueAEventCounter.getEventCount()); + Assert.assertEquals(1, valueBEventCounter.getEventCount()); + Assert.assertEquals(2, emptyEventCounter.getEventCount()); + } + + @Test + public void shouldCallFiltersForSuperTypes() { + final EventCountingHandler rootEventCounter = + new EventCountingHandler(); + final EventCountingHandler valueEventCounter = + new EventCountingHandler(); + final EventCountingHandler valueAEventCounter = + new EventCountingHandler(); + final EventCountingHandler valueBEventCounter = + new EventCountingHandler(); + final EventCountingHandler emptyEventCounter = + new EventCountingHandler(); + + eventHandlerManager.addEventFilter( + EventType.ROOT, rootEventCounter); + eventHandlerManager.addEventFilter( + ValueEvent.ANY, valueEventCounter); + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_A, valueAEventCounter); + eventHandlerManager.addEventFilter( + ValueEvent.VALUE_B, valueBEventCounter); + eventHandlerManager.addEventFilter( + EmptyEvent.EMPTY, emptyEventCounter); + + dispatchEmptyEvent(eventHandlerManager); + dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_A); + dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_B); + dispatchValueEvent(eventHandlerManager, ValueEvent.VALUE_C); + dispatchEmptyEvent(eventHandlerManager); + + Assert.assertEquals(5, rootEventCounter.getEventCount()); + Assert.assertEquals(3, valueEventCounter.getEventCount()); + Assert.assertEquals(1, valueAEventCounter.getEventCount()); + Assert.assertEquals(1, valueBEventCounter.getEventCount()); + Assert.assertEquals(2, emptyEventCounter.getEventCount()); + } + + @Test + public void eventConsumedInHandlerTest() { + final EventCountingDispatcher eventCountingDispatcher = + new EventCountingDispatcher(); + final EventDispatchChain eventDispatchChain = + StubEventDispatchChain.EMPTY_CHAIN + .append(eventHandlerManager) + .append(eventCountingDispatcher); + + final EventCountingHandler eventCountingFilter = + new EventCountingHandler(); + final EventCountingHandler eventCountingHandler = + new EventCountingHandler(); + final EventConsumingHandler eventConsumingHandler = + new EventConsumingHandler(); + + eventHandlerManager.addEventFilter(Event.ANY, eventCountingFilter); + + // add counting first, consuming second + eventHandlerManager.addEventHandler(Event.ANY, eventCountingHandler); + eventHandlerManager.addEventHandler(Event.ANY, eventConsumingHandler); + + Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); + Assert.assertEquals(1, eventCountingFilter.getEventCount()); + Assert.assertEquals( + 1, eventCountingDispatcher.getCapturingEventCount()); + Assert.assertEquals(1, eventCountingHandler.getEventCount()); + + eventHandlerManager.removeEventHandler( + Event.ANY, eventCountingHandler); + eventHandlerManager.removeEventHandler( + Event.ANY, eventConsumingHandler); + + // add consuming first, counting second + eventHandlerManager.addEventHandler(Event.ANY, eventConsumingHandler); + eventHandlerManager.addEventHandler(Event.ANY, eventCountingHandler); + + Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); + Assert.assertEquals(2, eventCountingFilter.getEventCount()); + Assert.assertEquals( + 2, eventCountingDispatcher.getCapturingEventCount()); + Assert.assertEquals(2, eventCountingHandler.getEventCount()); + } + + @Test + public void eventConsumedInFilterTest() { + final EventCountingDispatcher eventCountingDispatcher = + new EventCountingDispatcher(); + final EventDispatchChain eventDispatchChain = + StubEventDispatchChain.EMPTY_CHAIN + .append(eventHandlerManager) + .append(eventCountingDispatcher); + + final EventCountingHandler eventCountingFilter = + new EventCountingHandler(); + final EventConsumingHandler eventConsumingFilter = + new EventConsumingHandler(); + final EventCountingHandler eventCountingHandler = + new EventCountingHandler(); + + eventHandlerManager.addEventHandler(Event.ANY, eventCountingHandler); + + // add counting first, consuming second + eventHandlerManager.addEventFilter(Event.ANY, eventCountingFilter); + eventHandlerManager.addEventFilter(Event.ANY, eventConsumingFilter); + + Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); + Assert.assertEquals(1, eventCountingFilter.getEventCount()); + Assert.assertEquals( + 0, eventCountingDispatcher.getCapturingEventCount()); + Assert.assertEquals(0, eventCountingHandler.getEventCount()); + + eventHandlerManager.removeEventFilter(Event.ANY, eventCountingFilter); + eventHandlerManager.removeEventFilter(Event.ANY, eventConsumingFilter); + + // add consuming first, counting second + eventHandlerManager.addEventFilter(Event.ANY, eventConsumingFilter); + eventHandlerManager.addEventFilter(Event.ANY, eventCountingFilter); + + Assert.assertNull(eventDispatchChain.dispatchEvent(new EmptyEvent())); + Assert.assertEquals(2, eventCountingFilter.getEventCount()); + Assert.assertEquals( + 0, eventCountingDispatcher.getCapturingEventCount()); + Assert.assertEquals(0, eventCountingHandler.getEventCount()); + } + + @Test(expected=NullPointerException.class) + public void addEventHandlerShouldThrowNPEForNullEventType() { + eventHandlerManager.addEventHandler( + null, + event -> { + }); + } + + @Test(expected=NullPointerException.class) + public void addEventHandlerShouldThrowNPEForNullEventHandler() { + eventHandlerManager.addEventHandler(Event.ANY, null); + } + + @Test(expected=NullPointerException.class) + public void removeEventHandlerShouldThrowNPEForNullEventType() { + eventHandlerManager.removeEventHandler( + null, + event -> { + }); + } + + @Test(expected=NullPointerException.class) + public void removeEventHandlerShouldThrowNPEForNullEventHandler() { + eventHandlerManager.removeEventHandler(Event.ANY, null); + } + + @Test(expected=NullPointerException.class) + public void addEventFilterShouldThrowNPEForNullEventType() { + eventHandlerManager.addEventFilter( + null, + event -> { + }); + } + + @Test(expected=NullPointerException.class) + public void addEventFilterShouldThrowNPEForNullEventHandler() { + eventHandlerManager.addEventFilter(Event.ANY, null); + } + + @Test(expected=NullPointerException.class) + public void removeEventFilterShouldThrowNPEForNullEventType() { + eventHandlerManager.removeEventHandler( + null, + event -> { + }); + } + + @Test(expected=NullPointerException.class) + public void removeEventFilterShouldThrowNPEForNullEventHandler() { + eventHandlerManager.removeEventHandler(Event.ANY, null); + } + + @Test(expected=NullPointerException.class) + public void setEventHandlerShouldThrowNPEForNullEventType() { + eventHandlerManager.setEventHandler( + null, + event -> { + }); + } + + private static void testValueEventDispatch( + final EventDispatcher eventDispatcher, + final EventType eventType, + final int initialValue, + final int calculatedValue) { + final ValueEvent valueEvent = + (ValueEvent) eventDispatcher.dispatchEvent( + new ValueEvent(eventType, initialValue), + StubEventDispatchChain.EMPTY_CHAIN); + Assert.assertEquals(calculatedValue, valueEvent.getValue()); + } + + private static Event dispatchEmptyEvent( + final EventDispatcher eventDispatcher) { + return eventDispatcher.dispatchEvent( + new EmptyEvent(), + StubEventDispatchChain.EMPTY_CHAIN); + } + + private static Event dispatchValueEvent( + final EventDispatcher eventDispatcher, + final EventType eventType) { + return eventDispatcher.dispatchEvent( + new ValueEvent(eventType, 0), + StubEventDispatchChain.EMPTY_CHAIN); + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/LabeledEventDispatcher.java 2015-08-31 10:23:08.245217690 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.Event; -import javafx.event.EventDispatchChain; -import javafx.event.EventDispatcher; - -public class LabeledEventDispatcher implements EventDispatcher { - private final String label; - - public LabeledEventDispatcher() { - this(null); - } - - public LabeledEventDispatcher(final String label) { - this.label = label; - } - - @Override - public Event dispatchEvent(final Event event, - final EventDispatchChain tail) { - return tail.dispatchEvent(event); - } - - @Override - public String toString() { - return label; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/LabeledEventDispatcher.java 2015-08-31 10:23:08.113217691 -0400 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import javafx.event.Event; +import javafx.event.EventDispatchChain; +import javafx.event.EventDispatcher; + +public class LabeledEventDispatcher implements EventDispatcher { + private final String label; + + public LabeledEventDispatcher() { + this(null); + } + + public LabeledEventDispatcher(final String label) { + this.label = label; + } + + @Override + public Event dispatchEvent(final Event event, + final EventDispatchChain tail) { + return tail.dispatchEvent(event); + } + + @Override + public String toString() { + return label; + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/Operation.java 2015-08-31 10:23:08.937217682 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -public abstract class Operation { - private final int constant; - - private Operation(final int constant) { - this.constant = constant; - } - - public abstract int applyTo(int value); - - public static Operation add(final int constant) { - return new Operation(constant) { - @Override - public int applyTo(final int value) { - return value + constant; - } - }; - } - - public static Operation sub(final int constant) { - return new Operation(constant) { - @Override - public int applyTo(final int value) { - return value - constant; - } - }; - } - - public static Operation mul(final int constant) { - return new Operation(constant) { - @Override - public int applyTo(final int value) { - return value * constant; - } - }; - } - - public static Operation div(final int constant) { - return new Operation(constant) { - @Override - public int applyTo(final int value) { - return value / constant; - } - }; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/Operation.java 2015-08-31 10:23:08.729217684 -0400 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +public abstract class Operation { + private final int constant; + + private Operation(final int constant) { + this.constant = constant; + } + + public abstract int applyTo(int value); + + public static Operation add(final int constant) { + return new Operation(constant) { + @Override + public int applyTo(final int value) { + return value + constant; + } + }; + } + + public static Operation sub(final int constant) { + return new Operation(constant) { + @Override + public int applyTo(final int value) { + return value - constant; + } + }; + } + + public static Operation mul(final int constant) { + return new Operation(constant) { + @Override + public int applyTo(final int value) { + return value * constant; + } + }; + } + + public static Operation div(final int constant) { + return new Operation(constant) { + @Override + public int applyTo(final int value) { + return value / constant; + } + }; + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/PathChangingDispatcher.java 2015-08-31 10:23:09.637217674 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.Event; -import javafx.event.EventDispatchChain; -import javafx.event.EventDispatcher; - -public final class PathChangingDispatcher implements EventDispatcher { - private final EventDispatcher prependDispatcher; - private final EventDispatcher appendDispatcher; - private final int dispatchCount; - - public PathChangingDispatcher(final EventDispatcher prependDispatcher, - final EventDispatcher appendDispatcher, - final int dispatchCount) { - this.prependDispatcher = prependDispatcher; - this.appendDispatcher = appendDispatcher; - this.dispatchCount = dispatchCount; - } - - @Override - public Event dispatchEvent(Event event, EventDispatchChain tail) { - if (prependDispatcher != null) { - tail = tail.prepend(prependDispatcher); - } - if (appendDispatcher != null) { - tail = tail.append(appendDispatcher); - } - - for (int i = 0; i < dispatchCount; ++i) { - event = tail.dispatchEvent(event); - } - - return event; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/PathChangingDispatcher.java 2015-08-31 10:23:09.497217675 -0400 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import javafx.event.Event; +import javafx.event.EventDispatchChain; +import javafx.event.EventDispatcher; + +public final class PathChangingDispatcher implements EventDispatcher { + private final EventDispatcher prependDispatcher; + private final EventDispatcher appendDispatcher; + private final int dispatchCount; + + public PathChangingDispatcher(final EventDispatcher prependDispatcher, + final EventDispatcher appendDispatcher, + final int dispatchCount) { + this.prependDispatcher = prependDispatcher; + this.appendDispatcher = appendDispatcher; + this.dispatchCount = dispatchCount; + } + + @Override + public Event dispatchEvent(Event event, EventDispatchChain tail) { + if (prependDispatcher != null) { + tail = tail.prepend(prependDispatcher); + } + if (appendDispatcher != null) { + tail = tail.append(appendDispatcher); + } + + for (int i = 0; i < dispatchCount; ++i) { + event = tail.dispatchEvent(event); + } + + return event; + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/StubBasicEventDispatcher.java 2015-08-31 10:23:10.265217667 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.Event; - -public final class StubBasicEventDispatcher extends BasicEventDispatcher { - private int capturingEventCount; - private int bubblingEventCount; - private ConsumeEvent consumeNextEvent; - - public enum ConsumeEvent { - CAPTURING, BUBBLING - } - - public int getCapturingEventCount() { - return capturingEventCount; - } - - public int getBubblingEventCount() { - return bubblingEventCount; - } - - public void setConsumeNextEvent(final ConsumeEvent consumeNextEvent) { - this.consumeNextEvent = consumeNextEvent; - } - - @Override - public Event dispatchCapturingEvent(final Event event) { - ++capturingEventCount; - if (consumeNextEvent == ConsumeEvent.CAPTURING) { - event.consume(); - consumeNextEvent = null; - } - return event; - } - - @Override - public Event dispatchBubblingEvent(final Event event) { - ++bubblingEventCount; - if (consumeNextEvent == ConsumeEvent.BUBBLING) { - event.consume(); - consumeNextEvent = null; - } - return event; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/StubBasicEventDispatcher.java 2015-08-31 10:23:10.129217668 -0400 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import com.sun.javafx.event.BasicEventDispatcher; +import javafx.event.Event; + +public final class StubBasicEventDispatcher extends BasicEventDispatcher { + private int capturingEventCount; + private int bubblingEventCount; + private ConsumeEvent consumeNextEvent; + + public enum ConsumeEvent { + CAPTURING, BUBBLING + } + + public int getCapturingEventCount() { + return capturingEventCount; + } + + public int getBubblingEventCount() { + return bubblingEventCount; + } + + public void setConsumeNextEvent(final ConsumeEvent consumeNextEvent) { + this.consumeNextEvent = consumeNextEvent; + } + + @Override + public Event dispatchCapturingEvent(final Event event) { + ++capturingEventCount; + if (consumeNextEvent == ConsumeEvent.CAPTURING) { + event.consume(); + consumeNextEvent = null; + } + return event; + } + + @Override + public Event dispatchBubblingEvent(final Event event) { + ++bubblingEventCount; + if (consumeNextEvent == ConsumeEvent.BUBBLING) { + event.consume(); + consumeNextEvent = null; + } + return event; + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/StubEventDispatchChain.java 2015-08-31 10:23:10.865217660 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import java.util.LinkedList; -import java.util.List; - -import javafx.event.Event; -import javafx.event.EventDispatchChain; -import javafx.event.EventDispatcher; - -public final class StubEventDispatchChain implements EventDispatchChain { - private final LinkedList eventDispatchers; - - public static final EventDispatchChain EMPTY_CHAIN = - new StubEventDispatchChain(); - - private StubEventDispatchChain() { - this(new LinkedList()); - } - - private StubEventDispatchChain( - final LinkedList eventDispatchers) { - this.eventDispatchers = eventDispatchers; - } - - @Override - public EventDispatchChain append(final EventDispatcher eventDispatcher) { - final LinkedList newDispatchers = - copyDispatchers(eventDispatchers); - newDispatchers.addLast(eventDispatcher); - return new StubEventDispatchChain(newDispatchers); - } - - @Override - public EventDispatchChain prepend(final EventDispatcher eventDispatcher) { - final LinkedList newDispatchers = - copyDispatchers(eventDispatchers); - newDispatchers.addFirst(eventDispatcher); - return new StubEventDispatchChain(newDispatchers); - } - - @Override - public Event dispatchEvent(final Event event) { - if (eventDispatchers.isEmpty()) { - return event; - } - - final LinkedList tailDispatchers = - copyDispatchers(eventDispatchers.subList( - 1, eventDispatchers.size())); - return eventDispatchers.element().dispatchEvent( - event, new StubEventDispatchChain(tailDispatchers)); - } - - private static LinkedList copyDispatchers( - final List dispatchers) { - return new LinkedList(dispatchers); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/StubEventDispatchChain.java 2015-08-31 10:23:10.733217662 -0400 @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import java.util.LinkedList; +import java.util.List; + +import javafx.event.Event; +import javafx.event.EventDispatchChain; +import javafx.event.EventDispatcher; + +public final class StubEventDispatchChain implements EventDispatchChain { + private final LinkedList eventDispatchers; + + public static final EventDispatchChain EMPTY_CHAIN = + new StubEventDispatchChain(); + + private StubEventDispatchChain() { + this(new LinkedList()); + } + + private StubEventDispatchChain( + final LinkedList eventDispatchers) { + this.eventDispatchers = eventDispatchers; + } + + @Override + public EventDispatchChain append(final EventDispatcher eventDispatcher) { + final LinkedList newDispatchers = + copyDispatchers(eventDispatchers); + newDispatchers.addLast(eventDispatcher); + return new StubEventDispatchChain(newDispatchers); + } + + @Override + public EventDispatchChain prepend(final EventDispatcher eventDispatcher) { + final LinkedList newDispatchers = + copyDispatchers(eventDispatchers); + newDispatchers.addFirst(eventDispatcher); + return new StubEventDispatchChain(newDispatchers); + } + + @Override + public Event dispatchEvent(final Event event) { + if (eventDispatchers.isEmpty()) { + return event; + } + + final LinkedList tailDispatchers = + copyDispatchers(eventDispatchers.subList( + 1, eventDispatchers.size())); + return eventDispatchers.element().dispatchEvent( + event, new StubEventDispatchChain(tailDispatchers)); + } + + private static LinkedList copyDispatchers( + final List dispatchers) { + return new LinkedList(dispatchers); + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/TestCompositeEventDispatcher.java 2015-08-31 10:23:11.501217653 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -public class TestCompositeEventDispatcher extends CompositeEventDispatcher { - private final StubBasicEventDispatcher firstChildDispatcher; - private final StubBasicEventDispatcher secondChildDispatcher; - private final StubBasicEventDispatcher thirdChildDispatcher; - - public TestCompositeEventDispatcher() { - firstChildDispatcher = new StubBasicEventDispatcher(); - secondChildDispatcher = new StubBasicEventDispatcher(); - thirdChildDispatcher = new StubBasicEventDispatcher(); - - firstChildDispatcher.insertNextDispatcher(secondChildDispatcher); - secondChildDispatcher.insertNextDispatcher(thirdChildDispatcher); - } - - public StubBasicEventDispatcher getFirstChildDispatcher() { - return firstChildDispatcher; - } - - public StubBasicEventDispatcher getSecondChildDispatcher() { - return secondChildDispatcher; - } - - public StubBasicEventDispatcher getThirdChildDispatcher() { - return thirdChildDispatcher; - } - - @Override - public BasicEventDispatcher getFirstDispatcher() { - return firstChildDispatcher; - } - - @Override - public BasicEventDispatcher getLastDispatcher() { - return thirdChildDispatcher; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/TestCompositeEventDispatcher.java 2015-08-31 10:23:11.365217654 -0400 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import com.sun.javafx.event.BasicEventDispatcher; +import com.sun.javafx.event.CompositeEventDispatcher; + +public class TestCompositeEventDispatcher extends CompositeEventDispatcher { + private final StubBasicEventDispatcher firstChildDispatcher; + private final StubBasicEventDispatcher secondChildDispatcher; + private final StubBasicEventDispatcher thirdChildDispatcher; + + public TestCompositeEventDispatcher() { + firstChildDispatcher = new StubBasicEventDispatcher(); + secondChildDispatcher = new StubBasicEventDispatcher(); + thirdChildDispatcher = new StubBasicEventDispatcher(); + + firstChildDispatcher.insertNextDispatcher(secondChildDispatcher); + secondChildDispatcher.insertNextDispatcher(thirdChildDispatcher); + } + + public StubBasicEventDispatcher getFirstChildDispatcher() { + return firstChildDispatcher; + } + + public StubBasicEventDispatcher getSecondChildDispatcher() { + return secondChildDispatcher; + } + + public StubBasicEventDispatcher getThirdChildDispatcher() { + return thirdChildDispatcher; + } + + @Override + public BasicEventDispatcher getFirstDispatcher() { + return firstChildDispatcher; + } + + @Override + public BasicEventDispatcher getLastDispatcher() { + return thirdChildDispatcher; + } +} --- old/modules/base/src/test/java/com/sun/javafx/event/ValueEvent.java 2015-08-31 10:23:12.185217645 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.event; - -import javafx.event.Event; -import javafx.event.EventType; - -public final class ValueEvent extends Event { - public static final EventType ANY = - new EventType(Event.ANY, "VALUE"); - - public static final EventType VALUE_A = - new EventType(ValueEvent.ANY, "VALUE_A"); - public static final EventType VALUE_B = - new EventType(ValueEvent.ANY, "VALUE_B"); - public static final EventType VALUE_C = - new EventType(ValueEvent.ANY, "VALUE_C"); - - private int value; - - public ValueEvent() { - this(VALUE_A, 0); - } - - public ValueEvent(final int initialValue) { - this(VALUE_A, initialValue); - } - - public ValueEvent(final EventType eventType, - final int initialValue) { - super(eventType); - value = initialValue; - } - - public void setValue(int value) { - this.value = value; - } - - public int getValue() { - return value; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/event/ValueEvent.java 2015-08-31 10:23:12.053217647 -0400 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.event; + +import javafx.event.Event; +import javafx.event.EventType; + +public final class ValueEvent extends Event { + public static final EventType ANY = + new EventType(Event.ANY, "VALUE"); + + public static final EventType VALUE_A = + new EventType(ValueEvent.ANY, "VALUE_A"); + public static final EventType VALUE_B = + new EventType(ValueEvent.ANY, "VALUE_B"); + public static final EventType VALUE_C = + new EventType(ValueEvent.ANY, "VALUE_C"); + + private int value; + + public ValueEvent() { + this(VALUE_A, 0); + } + + public ValueEvent(final int initialValue) { + this(VALUE_A, initialValue); + } + + public ValueEvent(final EventType eventType, + final int initialValue) { + super(eventType); + value = initialValue; + } + + public void setValue(int value) { + this.value = value; + } + + public int getValue() { + return value; + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/property/adapter/JavaBeanPropertyBuilderHelperTest.java 2015-08-31 10:23:12.673217640 -0400 @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.property.adapter; + +import com.sun.javafx.property.adapter.JavaBeanPropertyBuilderHelper; +import com.sun.javafx.property.adapter.PropertyDescriptor; +import org.junit.Before; +import org.junit.Test; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** +*/ +public class JavaBeanPropertyBuilderHelperTest { + + private JavaBeanPropertyBuilderHelper helperPOJOBean; + private JavaBeanPropertyBuilderHelper helperPOJOBeanWithNonStandardNames; + + @Before + public void setUp() { + helperPOJOBean = new JavaBeanPropertyBuilderHelper(); + helperPOJOBean.beanClass(POJOBean.class); + helperPOJOBean.name("x"); + + helperPOJOBeanWithNonStandardNames = new JavaBeanPropertyBuilderHelper(); + helperPOJOBeanWithNonStandardNames.beanClass(POJOBeanWithNonStandardNames.class); + helperPOJOBeanWithNonStandardNames.name("x"); + helperPOJOBeanWithNonStandardNames.getterName("readX"); + helperPOJOBeanWithNonStandardNames.setterName("writeX"); + } + + @Test(expected = NullPointerException.class) + public void testSetup_WithNameIsNull() { + try { + helperPOJOBean.name(null); + helperPOJOBean.getDescriptor(); + } catch (NoSuchMethodException e) { + fail(); + } + } + + @Test(expected = IllegalArgumentException.class) + public void testSetup_WithNameIsEmpty() { + try { + helperPOJOBean.name(""); + helperPOJOBean.getDescriptor(); + } catch (NoSuchMethodException e) { + fail(); + } + } + + @Test(expected = NullPointerException.class) + public void testSetup_WithBeanClassIsNull() { + try { + helperPOJOBean.beanClass(null); + helperPOJOBean.getDescriptor(); + } catch (NoSuchMethodException e) { + fail(); + } + } + + @Test(expected = NullPointerException.class) + public void testSetup_WithNonStandardNames_WithNameIsNull() { + try { + helperPOJOBeanWithNonStandardNames.name(null); + helperPOJOBeanWithNonStandardNames.getDescriptor(); + } catch (NoSuchMethodException e) { + fail(); + } + } + + @Test(expected = NullPointerException.class) + public void testSetup_WithNonStandardNames_WithBeanClassIsNull() { + try { + helperPOJOBeanWithNonStandardNames.beanClass(null); + helperPOJOBeanWithNonStandardNames.getDescriptor(); + } catch (NoSuchMethodException e) { + fail(); + } + } + + @Test(expected = NoSuchMethodException.class) + public void testSetup_WithNonStandardNames_WithGetterNameIsNull() throws NoSuchMethodException { + helperPOJOBeanWithNonStandardNames.getterName(null); + helperPOJOBeanWithNonStandardNames.getDescriptor(); + } + + @Test(expected = NoSuchMethodException.class) + public void testSetup_WithNonStandardNames_WithSetterNameIsNull() throws NoSuchMethodException { + helperPOJOBeanWithNonStandardNames.setterName(null); + helperPOJOBeanWithNonStandardNames.getDescriptor(); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetup_WithNonStandardNames_WithNameIsEmpty() { + try { + helperPOJOBeanWithNonStandardNames.name(""); + helperPOJOBeanWithNonStandardNames.getDescriptor(); + } catch (NoSuchMethodException e) { + fail(); + } + } + + @Test(expected = NoSuchMethodException.class) + public void testSetup_WithNonStandardNames_WithGetterNameIsEmpty() throws NoSuchMethodException { + helperPOJOBeanWithNonStandardNames.getterName(""); + helperPOJOBeanWithNonStandardNames.getDescriptor(); + } + + @Test(expected = NoSuchMethodException.class) + public void testSetup_WithNonStandardNames_WithSetterNameIsEmpty() throws NoSuchMethodException { + helperPOJOBeanWithNonStandardNames.setterName(""); + helperPOJOBeanWithNonStandardNames.getDescriptor(); + } + + @Test(expected = NullPointerException.class) + public void testSetup_WithNonStandardAccessors_WithNameIsNull() throws NoSuchMethodException { + helperPOJOBeanWithNonStandardNames.getterName(null); + helperPOJOBeanWithNonStandardNames.setterName(null); + try { + final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); + final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); + helperPOJOBeanWithNonStandardNames.getter(getter); + helperPOJOBeanWithNonStandardNames.setter(setter); + + helperPOJOBeanWithNonStandardNames.name(null); + } catch (NoSuchMethodException e) { + fail("Error in test code. Should not happen."); + } + helperPOJOBeanWithNonStandardNames.getDescriptor(); + } + + @Test(expected = NoSuchMethodException.class) + public void testSetup_WithNonStandardAccessors_WithGetterIsNull() throws NoSuchMethodException { + helperPOJOBeanWithNonStandardNames.getterName(null); + helperPOJOBeanWithNonStandardNames.setterName(null); + try { + final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); + helperPOJOBeanWithNonStandardNames.setter(setter); + + helperPOJOBeanWithNonStandardNames.getter(null); + } catch (NoSuchMethodException e) { + fail("Error in test code. Should not happen."); + } + helperPOJOBeanWithNonStandardNames.getDescriptor(); + } + + @Test(expected = NoSuchMethodException.class) + public void testSetup_WithNonStandardAccessors_WithSetterIsNull() throws NoSuchMethodException { + helperPOJOBeanWithNonStandardNames.getterName(null); + helperPOJOBeanWithNonStandardNames.setterName(null); + try { + final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); + helperPOJOBeanWithNonStandardNames.getter(getter); + + helperPOJOBeanWithNonStandardNames.setter(null); + } catch (NoSuchMethodException e) { + fail("Error in test code. Should not happen."); + } + helperPOJOBeanWithNonStandardNames.getDescriptor(); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetup_WithNonStandardAccessors_WithNameIsEmpty() throws NoSuchMethodException { + helperPOJOBeanWithNonStandardNames.getterName(null); + helperPOJOBeanWithNonStandardNames.setterName(null); + try { + final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); + final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); + helperPOJOBeanWithNonStandardNames.getter(getter); + helperPOJOBeanWithNonStandardNames.setter(setter); + + helperPOJOBeanWithNonStandardNames.name(""); + } catch (NoSuchMethodException e) { + fail("Error in test code. Should not happen."); + } + helperPOJOBeanWithNonStandardNames.getDescriptor(); + } + + @Test + public void testReusabilityWhenChangeOfBeanClass() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Object x = new Object(); + + PropertyDescriptor descriptor = helperPOJOBean.getDescriptor(); + assertEquals(x, descriptor.getGetter().invoke(new POJOBean(x))); + descriptor.getSetter().invoke(new POJOBean(x), new Object()); + + helperPOJOBean.beanClass(POJOBean2.class); + + descriptor = helperPOJOBean.getDescriptor(); + assertEquals(x, descriptor.getGetter().invoke(new POJOBean2(x))); + descriptor.getSetter().invoke(new POJOBean2(x), new Object()); + } + + public static class POJOBean { + private Object x; + + public POJOBean(Object x) {this.x = x;} + + public Object getX() {return x;} + public void setX(Object x) {this.x = x;} + } + + public static class POJOBean2 { + private Object x; + + public POJOBean2(Object x) {this.x = x;} + + public Object getX() {return x;} + public void setX(Object x) {this.x = x;} + + } + + public static class POJOBeanWithNonStandardNames { + private Object x; + + public POJOBeanWithNonStandardNames(Object x) {this.x = x;} + + public Object readX() {return x;} + public void writeX(Object x) {this.x = x;} + } + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/property/adapter/PropertyDescriptorTest.java 2015-08-31 10:23:13.313217633 -0400 @@ -0,0 +1,844 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.property.adapter; + +//package com.sun.javafx.property.adapter; +// +//import javafx.beans.property.ObjectProperty; +//import javafx.beans.property.adapter.JavaBeanObjectProperty; +//import org.junit.Before; +//import org.junit.Test; +// +//import java.beans.*; +//import java.lang.reflect.Method; +//import java.util.ArrayList; +//import java.util.List; +// +//import static org.junit.Assert.assertEquals; +//import static org.junit.Assert.fail; +// +///** +//*/ +//public class PropertyDescriptorTest { +// +// @Before +// public void setUp() { +// } +// +// @Test +// public void testSetup() throws NoSuchMethodException { +// final Object initialValue = new Object(); +// final Object secondValue = new Object(); +// final POJOBean bean = new POJOBean(initialValue); +// helperPOJOBean.bean(bean); +// final ObjectProperty property = new JavaBeanObjectProperty(helperPOJOBean.getDescriptor(), bean); +// assertEquals(initialValue, property.get()); +// property.set(secondValue); +// assertEquals(secondValue, bean.getX()); +// assertEquals(secondValue, property.get()); +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNameIsNull() { +// try { +// helperPOJOBean.name(null); +// helperPOJOBean.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void testSetup_WithNameIsEmpty() { +// try { +// helperPOJOBean.name(""); +// helperPOJOBean.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithBeanClassIsNull() { +// try { +// helperPOJOBean.beanClass(null); +// helperPOJOBean.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test +// public void testSetup_WithNonStandardNames() { +// final Object initialValue = new Object(); +// final Object secondValue = new Object(); +// final POJOBeanWithNonStandardNames bean = new POJOBeanWithNonStandardNames(initialValue); +// helperPOJOBeanWithNonStandardNames.bean(bean); +// final ObjectProperty property = builder.createObjectProperty(bean); +// assertEquals(initialValue, property.get()); +// property.set(secondValue); +// assertEquals(secondValue, bean.readX()); +// assertEquals(secondValue, property.get()); +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardNames_WithNameIsNull() { +// try { +// helperPOJOBeanWithNonStandardNames.name(null); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardNames_WithBeanClassIsNull() { +// try { +// helperPOJOBeanWithNonStandardNames.beanClass(null); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardNames_WithGetterNameIsNull() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(null); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardNames_WithSetterNameIsNull() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.setterName(null); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void testSetup_WithNonStandardNames_WithNameIsEmpty() { +// try { +// helperPOJOBeanWithNonStandardNames.name(""); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardNames_WithGetterNameIsEmpty() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(""); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardNames_WithSetterNameIsEmpty() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.setterName(""); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +//// @Test +//// public void testSetup_WithNonStandardAccessors() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +//// final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); +//// builder = new JavaBeanPropertyBuilder("x", POJOBeanWithNonStandardNames.class, getter, setter); +//// } catch (NoSuchMethodException e) { +//// fail("Error in test code. Should not happen."); +//// } +//// final Object initialValue = new Object(); +//// final Object secondValue = new Object(); +//// final POJOBeanWithNonStandardNames bean = new POJOBeanWithNonStandardNames(initialValue); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// assertEquals(initialValue, property.get()); +//// property.set(secondValue); +//// assertEquals(secondValue, bean.readX()); +//// assertEquals(secondValue, property.get()); +//// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardAccessors_WithNameIsNull() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(null); +// helperPOJOBeanWithNonStandardNames.setterName(null); +// try { +// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +// final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); +// helperPOJOBeanWithNonStandardNames.getter(getter); +// helperPOJOBeanWithNonStandardNames.setter(setter); +// +// helperPOJOBeanWithNonStandardNames.name(null); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardAccessors_WithGetterIsNull() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(null); +// helperPOJOBeanWithNonStandardNames.setterName(null); +// try { +// final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); +// helperPOJOBeanWithNonStandardNames.setter(setter); +// +// helperPOJOBeanWithNonStandardNames.getter(null); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardAccessors_WithSetterIsNull() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(null); +// helperPOJOBeanWithNonStandardNames.setterName(null); +// try { +// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +// helperPOJOBeanWithNonStandardNames.getter(getter); +// +// helperPOJOBeanWithNonStandardNames.setter(null); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void testSetup_WithNonStandardAccessors_WithNameIsEmpty() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(null); +// helperPOJOBeanWithNonStandardNames.setterName(null); +// try { +// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +// final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); +// helperPOJOBeanWithNonStandardNames.getter(getter); +// helperPOJOBeanWithNonStandardNames.setter(setter); +// +// helperPOJOBeanWithNonStandardNames.name(""); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +//// @Test(expected = IllegalArgumentException.class) +//// public void testCreatePropertyWithWrongType_Boolean() { +//// final POJOBean bean = new POJOBean(new Object()); +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", POJOBean.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// builder.createBooleanProperty(bean); +//// } +//// +//// @Test +//// public void testDisposal_GeneralAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +//// JavaBeanObjectProperty property = builder.createObjectProperty(bean); +//// +//// // initial state +//// assertEquals(value0, property.get()); +//// assertTrue(bean.hasChangeListeners()); +//// assertTrue(bean.hasVetoListeners()); +//// +//// // dispose +//// property.dispose(); +//// try { +//// bean.setX(value1); +//// } catch (PropertyVetoException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// assertFalse(bean.hasChangeListeners()); +//// assertFalse(bean.hasVetoListeners()); +//// } +//// +//// @Test +//// public void testDisposal_ParameterizedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); +//// JavaBeanObjectProperty property = builder.createObjectProperty(bean); +//// +//// // initial state +//// assertEquals(value0, property.get()); +//// assertTrue(bean.hasChangeListeners()); +//// assertTrue(bean.hasVetoListeners()); +//// +//// // dispose +//// property.dispose(); +//// try { +//// bean.setX(value1); +//// } catch (PropertyVetoException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// assertFalse(bean.hasChangeListeners()); +//// assertFalse(bean.hasVetoListeners()); +//// } +//// +//// @Test +//// public void testDisposal_NamedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); +//// JavaBeanObjectProperty property = builder.createObjectProperty(bean); +//// +//// // initial state +//// assertEquals(value0, property.get()); +//// assertTrue(bean.hasChangeListeners()); +//// assertTrue(bean.hasVetoListeners()); +//// +//// // dispose +//// property.dispose(); +//// try { +//// bean.setX(value1); +//// } catch (PropertyVetoException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// assertFalse(bean.hasChangeListeners()); +//// assertFalse(bean.hasVetoListeners()); +//// } +//// +//// @Test +//// public void testDisposal_Bound() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +//// JavaBeanObjectProperty property = builder.createObjectProperty(bean); +//// final ObjectProperty observable = new SimpleObjectProperty(value1); +//// property.bind(observable); +//// +//// // initial state +//// assertEquals(value1, property.get()); +//// assertTrue(bean.hasChangeListeners()); +//// assertTrue(bean.hasVetoListeners()); +//// +//// // dispose +//// property.dispose(); +//// observable.set(value0); +//// assertFalse(bean.hasChangeListeners()); +//// assertFalse(bean.hasVetoListeners()); +//// } +//// +//// @Test +//// public void testInvalidationListener_GeneralAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final InvalidationListener listener = new InvalidationListener() { +//// @Override +//// public void invalidated(Observable observable) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testChangeListener_GeneralAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final ChangeListener listener = new ChangeListener() { +//// @Override +//// public void changed(ObservableValue observable, Object oldValue, Object newValue) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testInvalidationListener_ParameterizedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final InvalidationListener listener = new InvalidationListener() { +//// @Override +//// public void invalidated(Observable observable) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testChangeListener_ParameterizedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final ChangeListener listener = new ChangeListener() { +//// @Override +//// public void changed(ObservableValue observable, Object oldValue, Object newValue) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testInvalidationListener_NamedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final InvalidationListener listener = new InvalidationListener() { +//// @Override +//// public void invalidated(Observable observable) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testChangeListener_NamedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final ChangeListener listener = new ChangeListener() { +//// @Override +//// public void changed(ObservableValue observable, Object oldValue, Object newValue) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testSet_Bound() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// final Property observable = new SimpleObjectProperty(); +//// property.bind(observable); +//// +//// try { +//// bean.setX(value1); +//// fail(); +//// } catch (PropertyVetoException e) { +//// final PropertyChangeEvent event = e.getPropertyChangeEvent(); +//// assertEquals("x", event.getPropertyName()); +//// assertEquals(bean, event.getSource()); +//// } +//// } +//// +//// @Test +//// public void testListenerWithOtherParameters() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithRawListenerSupport.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithRawListenerSupport bean = new BeanWithRawListenerSupport(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// final Property observable = new SimpleObjectProperty(value1); +//// property.bind(observable); +//// +//// try { +//// bean.fireVetoableChange(new PropertyChangeEvent(new Object(), "x", value1, value0)); +//// assertEquals(value1, property.get()); +//// assertEquals(value1, bean.getX()); +//// bean.fireVetoableChange(new PropertyChangeEvent(bean, "y", value1, value0)); +//// assertEquals(value1, property.get()); +//// assertEquals(value1, bean.getX()); +//// } catch (PropertyVetoException e) { +//// fail(); +//// } +//// +//// bean.firePropertyChange(new PropertyChangeEvent(new Object(), "x", value1, value0)); +//// assertEquals(value1, property.get()); +//// assertEquals(value1, bean.getX()); +//// bean.firePropertyChange(new PropertyChangeEvent(bean, "y", value1, value0)); +//// assertEquals(value1, property.get()); +//// assertEquals(value1, bean.getX()); +//// } +// +// public static class POJOBean { +// private Object x; +// +// public POJOBean(Object x) {this.x = x;} +// +// public Object getX() {return x;} +// public void setX(Object x) {this.x = x;} +// } +// +// public static class POJOBeanWithNonStandardNames { +// private Object x; +// +// public POJOBeanWithNonStandardNames(Object x) {this.x = x;} +// +// public Object readX() {return x;} +// public void writeX(Object x) {this.x = x;} +// } +// +// public static class BeanWithGeneralAddRemove { +// private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); +// private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this); +// +// private Object x; +// private int changeListenerCount; +// private int vetoListenerCount; +// +// public Object getX() {return x;} +// public void setX(Object x) throws PropertyVetoException { +// final Object oldX = this.x; +// vetoableChangeSupport.fireVetoableChange("x", oldX, x); +// this.x = x; +// propertyChangeSupport.firePropertyChange("x", oldX, x); +// } +// +// public BeanWithGeneralAddRemove(Object x) {this.x = x;} +// +// public boolean hasChangeListeners() { +// return changeListenerCount > 0; +// } +// +// public boolean hasVetoListeners() { +// return vetoListenerCount > 0; +// } +// +// public void addPropertyChangeListener(PropertyChangeListener listener) { +// changeListenerCount++; +// propertyChangeSupport.addPropertyChangeListener(listener); +// } +// +// public void removePropertyChangeListener(PropertyChangeListener listener) { +// changeListenerCount = Math.max(0, changeListenerCount-1); +// propertyChangeSupport.removePropertyChangeListener(listener); +// } +// +// public void addVetoableChangeListener(VetoableChangeListener listener) { +// vetoListenerCount++; +// vetoableChangeSupport.addVetoableChangeListener(listener); +// } +// +// public void removeVetoableChangeListener(VetoableChangeListener listener) { +// vetoListenerCount = Math.max(0, vetoListenerCount-1); +// vetoableChangeSupport.removeVetoableChangeListener(listener); +// } +// } +// +// public static class BeanWithParameterizedAddRemove { +// private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); +// private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this); +// +// private Object x; +// private int changeListenerCount; +// private int vetoListenerCount; +// +// public Object getX() {return x;} +// public void setX(Object x) throws PropertyVetoException { +// final Object oldX = this.x; +// vetoableChangeSupport.fireVetoableChange("x", oldX, x); +// this.x = x; +// propertyChangeSupport.firePropertyChange("x", oldX, x); +// } +// +// public BeanWithParameterizedAddRemove(Object x) {this.x = x;} +// +// public boolean hasChangeListeners() { +// return changeListenerCount > 0; +// } +// +// public boolean hasVetoListeners() { +// return vetoListenerCount > 0; +// } +// +// public void addPropertyChangeListener(String name, PropertyChangeListener listener) { +// changeListenerCount++; +// propertyChangeSupport.addPropertyChangeListener(name, listener); +// } +// +// public void removePropertyChangeListener(String name, PropertyChangeListener listener) { +// changeListenerCount = Math.max(0, changeListenerCount-1); +// propertyChangeSupport.removePropertyChangeListener(name, listener); +// } +// +// public void addVetoableChangeListener(String name, VetoableChangeListener listener) { +// vetoListenerCount++; +// vetoableChangeSupport.addVetoableChangeListener(name, listener); +// } +// +// public void removeVetoableChangeListener(String name, VetoableChangeListener listener) { +// vetoListenerCount = Math.max(0, vetoListenerCount-1); +// vetoableChangeSupport.removeVetoableChangeListener(name, listener); +// } +// } +// +// public static class BeanWithNamedAddRemove { +// private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); +// private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this); +// +// private Object x; +// private int changeListenerCount; +// private int vetoListenerCount; +// +// public Object getX() {return x;} +// public void setX(Object x) throws PropertyVetoException { +// final Object oldX = this.x; +// vetoableChangeSupport.fireVetoableChange("x", oldX, x); +// this.x = x; +// propertyChangeSupport.firePropertyChange("x", oldX, x); +// } +// +// public BeanWithNamedAddRemove(Object x) {this.x = x;} +// +// public boolean hasChangeListeners() { +// return changeListenerCount > 0; +// } +// +// public boolean hasVetoListeners() { +// return vetoListenerCount > 0; +// } +// +// public void addXListener(PropertyChangeListener listener) { +// changeListenerCount++; +// propertyChangeSupport.addPropertyChangeListener("x", listener); +// } +// +// public void removeXListener(PropertyChangeListener listener) { +// changeListenerCount = Math.max(0, changeListenerCount-1); +// propertyChangeSupport.removePropertyChangeListener("x", listener); +// } +// +// public void addXListener(VetoableChangeListener listener) { +// vetoListenerCount++; +// vetoableChangeSupport.addVetoableChangeListener("x", listener); +// } +// +// public void removeXListener(VetoableChangeListener listener) { +// vetoListenerCount = Math.max(0, vetoListenerCount-1); +// vetoableChangeSupport.removeVetoableChangeListener("x", listener); +// } +// } +// +// public class BeanWithRawListenerSupport { +// private final List vetoListeners = new ArrayList(); +// private final List changeListeners = new ArrayList(); +// +// private Object x; +// +// public Object getX() {return x;} +// public void setX(Object x) throws PropertyVetoException { +// final Object oldX = this.x; +// final PropertyChangeEvent event = new PropertyChangeEvent(this, "x", oldX, x); +// fireVetoableChange(event); +// this.x = x; +// firePropertyChange(event); +// } +// +// private void fireVetoableChange(PropertyChangeEvent event) throws PropertyVetoException { +// for (final VetoableChangeListener listener : vetoListeners) { +// listener.vetoableChange(event); +// } +// } +// +// private void firePropertyChange(PropertyChangeEvent event) { +// for (final PropertyChangeListener listener : changeListeners) { +// listener.propertyChange(event); +// } +// } +// +// public BeanWithRawListenerSupport(Object x) {this.x = x;} +// +// public boolean hasChangeListeners() { +// return !changeListeners.isEmpty(); +// } +// +// public boolean hasVetoListeners() { +// return !vetoListeners.isEmpty(); +// } +// +// public void addPropertyChangeListener(PropertyChangeListener listener) { +// changeListeners.add(listener); +// } +// +// public void removePropertyChangeListener(PropertyChangeListener listener) { +// changeListeners.remove(listener); +// } +// +// public void addVetoableChangeListener(VetoableChangeListener listener) { +// vetoListeners.add(listener); +// } +// +// public void removeVetoableChangeListener(VetoableChangeListener listener) { +// vetoListeners.remove(listener); +// } +// } +//} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/property/adapter/ReadOnlyPropertyDescriptorTest.java 2015-08-31 10:23:14.037217624 -0400 @@ -0,0 +1,842 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.property.adapter;//package com.sun.javafx.property.adapter; +// +//import javafx.beans.property.ObjectProperty; +//import javafx.beans.property.adapter.JavaBeanObjectProperty; +//import org.junit.Before; +//import org.junit.Test; +// +//import java.beans.*; +//import java.lang.reflect.Method; +//import java.util.ArrayList; +//import java.util.List; +// +//import static org.junit.Assert.assertEquals; +//import static org.junit.Assert.fail; +// +///** +//*/ +//public class PropertyDescriptorTest { +// +// @Before +// public void setUp() { +// } +// +// @Test +// public void testSetup() throws NoSuchMethodException { +// final Object initialValue = new Object(); +// final Object secondValue = new Object(); +// final POJOBean bean = new POJOBean(initialValue); +// helperPOJOBean.bean(bean); +// final ObjectProperty property = new JavaBeanObjectProperty(helperPOJOBean.getDescriptor(), bean); +// assertEquals(initialValue, property.get()); +// property.set(secondValue); +// assertEquals(secondValue, bean.getX()); +// assertEquals(secondValue, property.get()); +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNameIsNull() { +// try { +// helperPOJOBean.name(null); +// helperPOJOBean.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void testSetup_WithNameIsEmpty() { +// try { +// helperPOJOBean.name(""); +// helperPOJOBean.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithBeanClassIsNull() { +// try { +// helperPOJOBean.beanClass(null); +// helperPOJOBean.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test +// public void testSetup_WithNonStandardNames() { +// final Object initialValue = new Object(); +// final Object secondValue = new Object(); +// final POJOBeanWithNonStandardNames bean = new POJOBeanWithNonStandardNames(initialValue); +// helperPOJOBeanWithNonStandardNames.bean(bean); +// final ObjectProperty property = builder.createObjectProperty(bean); +// assertEquals(initialValue, property.get()); +// property.set(secondValue); +// assertEquals(secondValue, bean.readX()); +// assertEquals(secondValue, property.get()); +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardNames_WithNameIsNull() { +// try { +// helperPOJOBeanWithNonStandardNames.name(null); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardNames_WithBeanClassIsNull() { +// try { +// helperPOJOBeanWithNonStandardNames.beanClass(null); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardNames_WithGetterNameIsNull() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(null); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardNames_WithSetterNameIsNull() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.setterName(null); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void testSetup_WithNonStandardNames_WithNameIsEmpty() { +// try { +// helperPOJOBeanWithNonStandardNames.name(""); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } catch (NoSuchMethodException e) { +// fail(); +// } +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardNames_WithGetterNameIsEmpty() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(""); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardNames_WithSetterNameIsEmpty() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.setterName(""); +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +//// @Test +//// public void testSetup_WithNonStandardAccessors() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +//// final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); +//// builder = new JavaBeanPropertyBuilder("x", POJOBeanWithNonStandardNames.class, getter, setter); +//// } catch (NoSuchMethodException e) { +//// fail("Error in test code. Should not happen."); +//// } +//// final Object initialValue = new Object(); +//// final Object secondValue = new Object(); +//// final POJOBeanWithNonStandardNames bean = new POJOBeanWithNonStandardNames(initialValue); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// assertEquals(initialValue, property.get()); +//// property.set(secondValue); +//// assertEquals(secondValue, bean.readX()); +//// assertEquals(secondValue, property.get()); +//// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardAccessors_WithNameIsNull() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(null); +// helperPOJOBeanWithNonStandardNames.setterName(null); +// try { +// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +// final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); +// helperPOJOBeanWithNonStandardNames.getter(getter); +// helperPOJOBeanWithNonStandardNames.setter(setter); +// +// helperPOJOBeanWithNonStandardNames.name(null); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardAccessors_WithGetterIsNull() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(null); +// helperPOJOBeanWithNonStandardNames.setterName(null); +// try { +// final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); +// helperPOJOBeanWithNonStandardNames.setter(setter); +// +// helperPOJOBeanWithNonStandardNames.getter(null); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = NoSuchMethodException.class) +// public void testSetup_WithNonStandardAccessors_WithSetterIsNull() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(null); +// helperPOJOBeanWithNonStandardNames.setterName(null); +// try { +// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +// helperPOJOBeanWithNonStandardNames.getter(getter); +// +// helperPOJOBeanWithNonStandardNames.setter(null); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void testSetup_WithNonStandardAccessors_WithNameIsEmpty() throws NoSuchMethodException { +// helperPOJOBeanWithNonStandardNames.getterName(null); +// helperPOJOBeanWithNonStandardNames.setterName(null); +// try { +// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +// final Method setter = POJOBeanWithNonStandardNames.class.getMethod("writeX", Object.class); +// helperPOJOBeanWithNonStandardNames.getter(getter); +// helperPOJOBeanWithNonStandardNames.setter(setter); +// +// helperPOJOBeanWithNonStandardNames.name(""); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// helperPOJOBeanWithNonStandardNames.getDescriptor(); +// } +// +//// @Test(expected = IllegalArgumentException.class) +//// public void testCreatePropertyWithWrongType_Boolean() { +//// final POJOBean bean = new POJOBean(new Object()); +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", POJOBean.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// builder.createBooleanProperty(bean); +//// } +//// +//// @Test +//// public void testDisposal_GeneralAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +//// JavaBeanObjectProperty property = builder.createObjectProperty(bean); +//// +//// // initial state +//// assertEquals(value0, property.get()); +//// assertTrue(bean.hasChangeListeners()); +//// assertTrue(bean.hasVetoListeners()); +//// +//// // dispose +//// property.dispose(); +//// try { +//// bean.setX(value1); +//// } catch (PropertyVetoException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// assertFalse(bean.hasChangeListeners()); +//// assertFalse(bean.hasVetoListeners()); +//// } +//// +//// @Test +//// public void testDisposal_ParameterizedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); +//// JavaBeanObjectProperty property = builder.createObjectProperty(bean); +//// +//// // initial state +//// assertEquals(value0, property.get()); +//// assertTrue(bean.hasChangeListeners()); +//// assertTrue(bean.hasVetoListeners()); +//// +//// // dispose +//// property.dispose(); +//// try { +//// bean.setX(value1); +//// } catch (PropertyVetoException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// assertFalse(bean.hasChangeListeners()); +//// assertFalse(bean.hasVetoListeners()); +//// } +//// +//// @Test +//// public void testDisposal_NamedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); +//// JavaBeanObjectProperty property = builder.createObjectProperty(bean); +//// +//// // initial state +//// assertEquals(value0, property.get()); +//// assertTrue(bean.hasChangeListeners()); +//// assertTrue(bean.hasVetoListeners()); +//// +//// // dispose +//// property.dispose(); +//// try { +//// bean.setX(value1); +//// } catch (PropertyVetoException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// assertFalse(bean.hasChangeListeners()); +//// assertFalse(bean.hasVetoListeners()); +//// } +//// +//// @Test +//// public void testDisposal_Bound() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +//// JavaBeanObjectProperty property = builder.createObjectProperty(bean); +//// final ObjectProperty observable = new SimpleObjectProperty(value1); +//// property.bind(observable); +//// +//// // initial state +//// assertEquals(value1, property.get()); +//// assertTrue(bean.hasChangeListeners()); +//// assertTrue(bean.hasVetoListeners()); +//// +//// // dispose +//// property.dispose(); +//// observable.set(value0); +//// assertFalse(bean.hasChangeListeners()); +//// assertFalse(bean.hasVetoListeners()); +//// } +//// +//// @Test +//// public void testInvalidationListener_GeneralAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final InvalidationListener listener = new InvalidationListener() { +//// @Override +//// public void invalidated(Observable observable) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testChangeListener_GeneralAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final ChangeListener listener = new ChangeListener() { +//// @Override +//// public void changed(ObservableValue observable, Object oldValue, Object newValue) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testInvalidationListener_ParameterizedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final InvalidationListener listener = new InvalidationListener() { +//// @Override +//// public void invalidated(Observable observable) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testChangeListener_ParameterizedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final ChangeListener listener = new ChangeListener() { +//// @Override +//// public void changed(ObservableValue observable, Object oldValue, Object newValue) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testInvalidationListener_NamedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final InvalidationListener listener = new InvalidationListener() { +//// @Override +//// public void invalidated(Observable observable) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testChangeListener_NamedAddRemove() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final BooleanProperty fired = new SimpleBooleanProperty(false); +//// final ChangeListener listener = new ChangeListener() { +//// @Override +//// public void changed(ObservableValue observable, Object oldValue, Object newValue) { +//// fired.set(true); +//// } +//// }; +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// +//// property.addListener(listener); +//// fired.set(false); +//// property.setValue(value1); +//// assertTrue(fired.get()); +//// +//// property.removeListener(listener); +//// fired.set(false); +//// property.setValue(value0); +//// assertFalse(fired.get()); +//// } +//// +//// @Test +//// public void testSet_Bound() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// final Property observable = new SimpleObjectProperty(); +//// property.bind(observable); +//// +//// try { +//// bean.setX(value1); +//// fail(); +//// } catch (PropertyVetoException e) { +//// final PropertyChangeEvent event = e.getPropertyChangeEvent(); +//// assertEquals("x", event.getPropertyName()); +//// assertEquals(bean, event.getSource()); +//// } +//// } +//// +//// @Test +//// public void testListenerWithOtherParameters() { +//// JavaBeanPropertyBuilder builder = null; +//// try { +//// builder = new JavaBeanPropertyBuilder("x", BeanWithRawListenerSupport.class); +//// } catch (NoSuchMethodException e) { +//// e.printStackTrace(); +//// fail(); +//// } +//// final Object value0 = new Object(); +//// final Object value1 = new Object(); +//// final BeanWithRawListenerSupport bean = new BeanWithRawListenerSupport(value0); +//// final ObjectProperty property = builder.createObjectProperty(bean); +//// final Property observable = new SimpleObjectProperty(value1); +//// property.bind(observable); +//// +//// try { +//// bean.fireVetoableChange(new PropertyChangeEvent(new Object(), "x", value1, value0)); +//// assertEquals(value1, property.get()); +//// assertEquals(value1, bean.getX()); +//// bean.fireVetoableChange(new PropertyChangeEvent(bean, "y", value1, value0)); +//// assertEquals(value1, property.get()); +//// assertEquals(value1, bean.getX()); +//// } catch (PropertyVetoException e) { +//// fail(); +//// } +//// +//// bean.firePropertyChange(new PropertyChangeEvent(new Object(), "x", value1, value0)); +//// assertEquals(value1, property.get()); +//// assertEquals(value1, bean.getX()); +//// bean.firePropertyChange(new PropertyChangeEvent(bean, "y", value1, value0)); +//// assertEquals(value1, property.get()); +//// assertEquals(value1, bean.getX()); +//// } +// +// public static class POJOBean { +// private Object x; +// +// public POJOBean(Object x) {this.x = x;} +// +// public Object getX() {return x;} +// public void setX(Object x) {this.x = x;} +// } +// +// public static class POJOBeanWithNonStandardNames { +// private Object x; +// +// public POJOBeanWithNonStandardNames(Object x) {this.x = x;} +// +// public Object readX() {return x;} +// public void writeX(Object x) {this.x = x;} +// } +// +// public static class BeanWithGeneralAddRemove { +// private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); +// private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this); +// +// private Object x; +// private int changeListenerCount; +// private int vetoListenerCount; +// +// public Object getX() {return x;} +// public void setX(Object x) throws PropertyVetoException { +// final Object oldX = this.x; +// vetoableChangeSupport.fireVetoableChange("x", oldX, x); +// this.x = x; +// propertyChangeSupport.firePropertyChange("x", oldX, x); +// } +// +// public BeanWithGeneralAddRemove(Object x) {this.x = x;} +// +// public boolean hasChangeListeners() { +// return changeListenerCount > 0; +// } +// +// public boolean hasVetoListeners() { +// return vetoListenerCount > 0; +// } +// +// public void addPropertyChangeListener(PropertyChangeListener listener) { +// changeListenerCount++; +// propertyChangeSupport.addPropertyChangeListener(listener); +// } +// +// public void removePropertyChangeListener(PropertyChangeListener listener) { +// changeListenerCount = Math.max(0, changeListenerCount-1); +// propertyChangeSupport.removePropertyChangeListener(listener); +// } +// +// public void addVetoableChangeListener(VetoableChangeListener listener) { +// vetoListenerCount++; +// vetoableChangeSupport.addVetoableChangeListener(listener); +// } +// +// public void removeVetoableChangeListener(VetoableChangeListener listener) { +// vetoListenerCount = Math.max(0, vetoListenerCount-1); +// vetoableChangeSupport.removeVetoableChangeListener(listener); +// } +// } +// +// public static class BeanWithParameterizedAddRemove { +// private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); +// private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this); +// +// private Object x; +// private int changeListenerCount; +// private int vetoListenerCount; +// +// public Object getX() {return x;} +// public void setX(Object x) throws PropertyVetoException { +// final Object oldX = this.x; +// vetoableChangeSupport.fireVetoableChange("x", oldX, x); +// this.x = x; +// propertyChangeSupport.firePropertyChange("x", oldX, x); +// } +// +// public BeanWithParameterizedAddRemove(Object x) {this.x = x;} +// +// public boolean hasChangeListeners() { +// return changeListenerCount > 0; +// } +// +// public boolean hasVetoListeners() { +// return vetoListenerCount > 0; +// } +// +// public void addPropertyChangeListener(String name, PropertyChangeListener listener) { +// changeListenerCount++; +// propertyChangeSupport.addPropertyChangeListener(name, listener); +// } +// +// public void removePropertyChangeListener(String name, PropertyChangeListener listener) { +// changeListenerCount = Math.max(0, changeListenerCount-1); +// propertyChangeSupport.removePropertyChangeListener(name, listener); +// } +// +// public void addVetoableChangeListener(String name, VetoableChangeListener listener) { +// vetoListenerCount++; +// vetoableChangeSupport.addVetoableChangeListener(name, listener); +// } +// +// public void removeVetoableChangeListener(String name, VetoableChangeListener listener) { +// vetoListenerCount = Math.max(0, vetoListenerCount-1); +// vetoableChangeSupport.removeVetoableChangeListener(name, listener); +// } +// } +// +// public static class BeanWithNamedAddRemove { +// private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); +// private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this); +// +// private Object x; +// private int changeListenerCount; +// private int vetoListenerCount; +// +// public Object getX() {return x;} +// public void setX(Object x) throws PropertyVetoException { +// final Object oldX = this.x; +// vetoableChangeSupport.fireVetoableChange("x", oldX, x); +// this.x = x; +// propertyChangeSupport.firePropertyChange("x", oldX, x); +// } +// +// public BeanWithNamedAddRemove(Object x) {this.x = x;} +// +// public boolean hasChangeListeners() { +// return changeListenerCount > 0; +// } +// +// public boolean hasVetoListeners() { +// return vetoListenerCount > 0; +// } +// +// public void addXListener(PropertyChangeListener listener) { +// changeListenerCount++; +// propertyChangeSupport.addPropertyChangeListener("x", listener); +// } +// +// public void removeXListener(PropertyChangeListener listener) { +// changeListenerCount = Math.max(0, changeListenerCount-1); +// propertyChangeSupport.removePropertyChangeListener("x", listener); +// } +// +// public void addXListener(VetoableChangeListener listener) { +// vetoListenerCount++; +// vetoableChangeSupport.addVetoableChangeListener("x", listener); +// } +// +// public void removeXListener(VetoableChangeListener listener) { +// vetoListenerCount = Math.max(0, vetoListenerCount-1); +// vetoableChangeSupport.removeVetoableChangeListener("x", listener); +// } +// } +// +// public class BeanWithRawListenerSupport { +// private final List vetoListeners = new ArrayList(); +// private final List changeListeners = new ArrayList(); +// +// private Object x; +// +// public Object getX() {return x;} +// public void setX(Object x) throws PropertyVetoException { +// final Object oldX = this.x; +// final PropertyChangeEvent event = new PropertyChangeEvent(this, "x", oldX, x); +// fireVetoableChange(event); +// this.x = x; +// firePropertyChange(event); +// } +// +// private void fireVetoableChange(PropertyChangeEvent event) throws PropertyVetoException { +// for (final VetoableChangeListener listener : vetoListeners) { +// listener.vetoableChange(event); +// } +// } +// +// private void firePropertyChange(PropertyChangeEvent event) { +// for (final PropertyChangeListener listener : changeListeners) { +// listener.propertyChange(event); +// } +// } +// +// public BeanWithRawListenerSupport(Object x) {this.x = x;} +// +// public boolean hasChangeListeners() { +// return !changeListeners.isEmpty(); +// } +// +// public boolean hasVetoListeners() { +// return !vetoListeners.isEmpty(); +// } +// +// public void addPropertyChangeListener(PropertyChangeListener listener) { +// changeListeners.add(listener); +// } +// +// public void removePropertyChangeListener(PropertyChangeListener listener) { +// changeListeners.remove(listener); +// } +// +// public void addVetoableChangeListener(VetoableChangeListener listener) { +// vetoListeners.add(listener); +// } +// +// public void removeVetoableChangeListener(VetoableChangeListener listener) { +// vetoListeners.remove(listener); +// } +// } +//} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/com/sun/javafx/runtime/VersionInfoTest.java 2015-08-31 10:23:14.837217615 -0400 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.com.sun.javafx.runtime; + +import com.sun.javafx.runtime.VersionInfo; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + */ +public class VersionInfoTest { + + @Test + public void testMajorVersion() { + String version = VersionInfo.getVersion(); + // Need to update major version number when we develop the next + // major release. + assertTrue(version.startsWith("9.")); + String runtimeVersion = VersionInfo.getRuntimeVersion(); + assertTrue(runtimeVersion.startsWith(version)); + } +} --- old/modules/base/src/test/java/javafx/beans/Foo.java 2015-08-31 10:23:15.861217604 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans; - -import com.sun.javafx.property.PropertyReference; - -// NOTE: Foo must be a public interface, otherwise the test in PropertySupportTest -// that uses Foo will fail. -public interface Foo { - public static final PropertyReference NAME = new PropertyReference(Foo.class, "name"); - public void setName(String name); - public String getName(); -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/Foo.java 2015-08-31 10:23:15.661217606 -0400 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans; + +import com.sun.javafx.property.PropertyReference; + +// NOTE: Foo must be a public interface, otherwise the test in PropertySupportTest +// that uses Foo will fail. +public interface Foo { + public static final PropertyReference NAME = new PropertyReference(Foo.class, "name"); + public void setName(String name); + public String getName(); +} --- old/modules/base/src/test/java/javafx/beans/InvalidationListenerMock.java 2015-08-31 10:23:16.689217595 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans; - -import javafx.beans.InvalidationListener; -import javafx.beans.Observable; - -import static org.junit.Assert.assertEquals; - -public class InvalidationListenerMock implements InvalidationListener { - - private Observable observable = null; - private int counter = 0; - - @Override public void invalidated(Observable valueModel) { - this.observable = valueModel; - counter++; - } - - public void reset() { - observable = null; - counter = 0; - } - - public void check(Observable observable, int counter) { - assertEquals(observable, this.observable); - assertEquals(counter, this.counter); - reset(); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/InvalidationListenerMock.java 2015-08-31 10:23:16.489217597 -0400 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans; + +import javafx.beans.InvalidationListener; +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; +import javafx.beans.Observable; + +import static org.junit.Assert.assertEquals; + +public class InvalidationListenerMock implements InvalidationListener { + + private Observable observable = null; + private int counter = 0; + + @Override public void invalidated(Observable valueModel) { + this.observable = valueModel; + counter++; + } + + public void reset() { + observable = null; + counter = 0; + } + + public void check(Observable observable, int counter) { + assertEquals(observable, this.observable); + assertEquals(counter, this.counter); + reset(); + } +} --- old/modules/base/src/test/java/javafx/beans/Person.java 2015-08-31 10:23:17.369217587 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans; - -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.FloatProperty; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.LongProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.ReadOnlyIntegerProperty; -import javafx.beans.property.ReadOnlyIntegerWrapper; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleLongProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; - -import com.sun.javafx.property.PropertyReference; - -/** - * - */ -public class Person { - private final StringProperty name = new SimpleStringProperty(); - public final String getName() {return name.get();} - public void setName(String value) {name.set(value);} - public StringProperty nameProperty() {return name;} - - private final IntegerProperty age = new SimpleIntegerProperty(); - public final int getAge() {return age.get();} - public void setAge(int value) {age.set(value);} - public IntegerProperty ageProperty() {return age;} - - private final BooleanProperty retired = new SimpleBooleanProperty(); - public final boolean getRetired() {return retired.get();} - public void setRetired(boolean value) {retired.set(value);} - public BooleanProperty retiredProperty() {return retired;} - - private final IntegerProperty weight = new SimpleIntegerProperty(); // in cm?? :-) - public final int getWeight() {return weight.get();} - public void setWeight(int value) {weight.set(value);} - public IntegerProperty weightProperty() {return weight;} - - private final LongProperty income = new SimpleLongProperty(); // wow, can have a HUGE income! - public final long getIncome() {return income.get();} - public void setIncome(long value) {income.set(value);} - public LongProperty incomeProperty() {return income;} - - private final FloatProperty miles = new SimpleFloatProperty(); - public final float getMiles() {return miles.get();} - public void setMiles(float value) {miles.set(value);} - public FloatProperty milesProperty() {return miles;} - - private final DoubleProperty something = new SimpleDoubleProperty(); // I have no idea... - public final double getSomething() {return something.get();} - public void setSomething(double value) {something.set(value);} - public DoubleProperty somethingProperty() {return something;} - - private final ObjectProperty data = new SimpleObjectProperty(); - public final Object getData() {return data.get();} - public void setData(Object value) {data.set(value);} - public ObjectProperty dataProperty() {return data;} - - public final ReadOnlyIntegerWrapper noWrite = new ReadOnlyIntegerWrapper(); - public static final PropertyReference NO_WRITE = new PropertyReference(Person.class, "noWrite"); - public final int getNoWrite() { return noWrite.get(); } - public ReadOnlyIntegerProperty noWriteProperty() {return noWrite.getReadOnlyProperty();} - - public final IntegerProperty noRead = new SimpleIntegerProperty(); // do not expect it back - public static final PropertyReference NO_READ = new PropertyReference(Person.class, "noRead"); - public void setNoRead(int value) {noRead.set(value);} - - int noReadWrite; - public static final PropertyReference NO_READ_WRITE = new PropertyReference(Person.class, "noReadWrite"); - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/Person.java 2015-08-31 10:23:17.233217589 -0400 @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.FloatProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.LongProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.ReadOnlyIntegerWrapper; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +import com.sun.javafx.property.PropertyReference; + +/** + * + */ +public class Person { + private final StringProperty name = new SimpleStringProperty(); + public final String getName() {return name.get();} + public void setName(String value) {name.set(value);} + public StringProperty nameProperty() {return name;} + + private final IntegerProperty age = new SimpleIntegerProperty(); + public final int getAge() {return age.get();} + public void setAge(int value) {age.set(value);} + public IntegerProperty ageProperty() {return age;} + + private final BooleanProperty retired = new SimpleBooleanProperty(); + public final boolean getRetired() {return retired.get();} + public void setRetired(boolean value) {retired.set(value);} + public BooleanProperty retiredProperty() {return retired;} + + private final IntegerProperty weight = new SimpleIntegerProperty(); // in cm?? :-) + public final int getWeight() {return weight.get();} + public void setWeight(int value) {weight.set(value);} + public IntegerProperty weightProperty() {return weight;} + + private final LongProperty income = new SimpleLongProperty(); // wow, can have a HUGE income! + public final long getIncome() {return income.get();} + public void setIncome(long value) {income.set(value);} + public LongProperty incomeProperty() {return income;} + + private final FloatProperty miles = new SimpleFloatProperty(); + public final float getMiles() {return miles.get();} + public void setMiles(float value) {miles.set(value);} + public FloatProperty milesProperty() {return miles;} + + private final DoubleProperty something = new SimpleDoubleProperty(); // I have no idea... + public final double getSomething() {return something.get();} + public void setSomething(double value) {something.set(value);} + public DoubleProperty somethingProperty() {return something;} + + private final ObjectProperty data = new SimpleObjectProperty(); + public final Object getData() {return data.get();} + public void setData(Object value) {data.set(value);} + public ObjectProperty dataProperty() {return data;} + + public final ReadOnlyIntegerWrapper noWrite = new ReadOnlyIntegerWrapper(); + public static final PropertyReference NO_WRITE = new PropertyReference(Person.class, "noWrite"); + public final int getNoWrite() { return noWrite.get(); } + public ReadOnlyIntegerProperty noWriteProperty() {return noWrite.getReadOnlyProperty();} + + public final IntegerProperty noRead = new SimpleIntegerProperty(); // do not expect it back + public static final PropertyReference NO_READ = new PropertyReference(Person.class, "noRead"); + public void setNoRead(int value) {noRead.set(value);} + + int noReadWrite; + public static final PropertyReference NO_READ_WRITE = new PropertyReference(Person.class, "noReadWrite"); + +} --- old/modules/base/src/test/java/javafx/beans/WeakInvalidationListenerMock.java 2015-08-31 10:23:17.973217580 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans; - -public class WeakInvalidationListenerMock implements InvalidationListener, WeakListener { - @Override public void invalidated(Observable observable) {} - - @Override public boolean wasGarbageCollected() { - return true; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/WeakInvalidationListenerMock.java 2015-08-31 10:23:17.837217582 -0400 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans; + +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; +import javafx.beans.WeakListener; + +public class WeakInvalidationListenerMock implements InvalidationListener, WeakListener { + @Override public void invalidated(Observable observable) {} + + @Override public boolean wasGarbageCollected() { + return true; + } +} --- old/modules/base/src/test/java/javafx/beans/WeakInvalidationListenerTest.java 2015-08-31 10:23:18.845217570 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; - -import org.junit.Test; - -public class WeakInvalidationListenerTest { - - @Test(expected=NullPointerException.class) - public void testConstructWithNull() { - new WeakInvalidationListener(null); - } - - @Test - public void testHandle() { - InvalidationListenerMock listener = new InvalidationListenerMock(); - final WeakInvalidationListener weakListener = new WeakInvalidationListener(listener); - final ObservableMock o = new ObservableMock(); - - // regular call - weakListener.invalidated(o); - listener.check(o, 1); - assertFalse(weakListener.wasGarbageCollected()); - - // GC-ed call - o.reset(); - listener = null; - System.gc(); - assertTrue(weakListener.wasGarbageCollected()); - weakListener.invalidated(o); - assertEquals(1, o.removeCounter); - } - - private static class ObservableMock implements ObservableValue { - private int removeCounter; - - private void reset() { - removeCounter = 0; - } - - @Override - public Object getValue() { - return null; - } - - @Override - public void addListener(InvalidationListener listener) { - // not used - } - - @Override - public void addListener(ChangeListener listener) { - // not used - } - - @Override - public void removeListener(InvalidationListener listener) { - removeCounter++; - } - - @Override - public void removeListener(ChangeListener listener) { - // not used - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/WeakInvalidationListenerTest.java 2015-08-31 10:23:18.637217573 -0400 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans; + +import javafx.beans.InvalidationListener; +import javafx.beans.WeakInvalidationListener; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; + +import org.junit.Test; + +public class WeakInvalidationListenerTest { + + @Test(expected=NullPointerException.class) + public void testConstructWithNull() { + new WeakInvalidationListener(null); + } + + @Test + public void testHandle() { + InvalidationListenerMock listener = new InvalidationListenerMock(); + final WeakInvalidationListener weakListener = new WeakInvalidationListener(listener); + final ObservableMock o = new ObservableMock(); + + // regular call + weakListener.invalidated(o); + listener.check(o, 1); + assertFalse(weakListener.wasGarbageCollected()); + + // GC-ed call + o.reset(); + listener = null; + System.gc(); + assertTrue(weakListener.wasGarbageCollected()); + weakListener.invalidated(o); + assertEquals(1, o.removeCounter); + } + + private static class ObservableMock implements ObservableValue { + private int removeCounter; + + private void reset() { + removeCounter = 0; + } + + @Override + public Object getValue() { + return null; + } + + @Override + public void addListener(InvalidationListener listener) { + // not used + } + + @Override + public void addListener(ChangeListener listener) { + // not used + } + + @Override + public void removeListener(InvalidationListener listener) { + removeCounter++; + } + + @Override + public void removeListener(ChangeListener listener) { + // not used + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/BooleanPropertyBaseTest.java 2015-08-31 10:23:19.493217563 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,515 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableBooleanValueStub; -import javafx.beans.value.ObservableObjectValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class BooleanPropertyBaseTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final Boolean UNDEFINED = null; - - private BooleanPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new BooleanPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - } - - private void attachChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - } - - @Test - public void testConstructor() { - final BooleanProperty p1 = new SimpleBooleanProperty(); - assertEquals(false, p1.get()); - assertEquals(Boolean.FALSE, p1.getValue()); - assertFalse(property.isBound()); - - final BooleanProperty p2 = new SimpleBooleanProperty(true); - assertEquals(true, p2.get()); - assertEquals(Boolean.TRUE, p2.getValue()); - assertFalse(property.isBound()); - } - - @Test - public void testInvalidationListener() { - attachInvalidationListener(); - property.set(true); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(false); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - attachChangeListener(); - property.set(true); - changeListener.check(property, false, true, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(false); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testLazySet() { - attachInvalidationListener(); - - // set value once - property.set(true); - assertEquals(true, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.set(true); - assertEquals(true, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.set(false); - property.set(true); - assertEquals(true, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSet() { - attachChangeListener(); - - // set value once - property.set(true); - assertEquals(true, property.get()); - property.check(1); - changeListener.check(property, false, true, 1); - - // set same value again - property.set(true); - assertEquals(true, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(false); - property.set(true); - assertEquals(true, property.get()); - property.check(2); - changeListener.check(property, false, true, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListener(); - - // set value once - property.setValue(true); - assertEquals(true, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.setValue(true); - assertEquals(true, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(false); - property.setValue(true); - assertEquals(true, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSetValue() { - attachChangeListener(); - - // set value once - property.setValue(true); - assertEquals(true, property.get()); - property.check(1); - changeListener.check(property, false, true, 1); - - // set same value again - property.setValue(true); - assertEquals(true, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(false); - property.setValue(true); - assertEquals(true, property.get()); - property.check(2); - changeListener.check(property, false, true, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final BooleanProperty v = new SimpleBooleanProperty(true); - property.bind(v); - property.set(true); - } - - @Test - public void testLazyBind_primitive() { - attachInvalidationListener(); - final ObservableBooleanValueStub v = new ObservableBooleanValueStub(true); - - property.bind(v); - assertEquals(true, property.get()); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(false); - assertEquals(false, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(true); - v.set(false); - assertEquals(false, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(true); - v.set(true); - assertEquals(true, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBind_primitive() { - attachChangeListener(); - final ObservableBooleanValueStub v = new ObservableBooleanValueStub(true); - - property.bind(v); - assertEquals(true, property.get()); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, false, true, 1); - - // change binding once - v.set(false); - assertEquals(false, property.get()); - property.check(1); - changeListener.check(property, true, false, 1); - - // change binding twice without reading - v.set(true); - v.set(false); - assertEquals(false, property.get()); - property.check(2); - changeListener.check(property, true, false, 2); - - // change binding twice to same value - v.set(true); - v.set(true); - assertEquals(true, property.get()); - property.check(2); - changeListener.check(property, false, true, 1); - } - - @Test - public void testLazyBind_generic() { - attachInvalidationListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(true); - - property.bind(v); - assertEquals(true, property.get()); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(false); - assertEquals(false, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(true); - v.set(false); - assertEquals(false, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(true); - v.set(true); - assertEquals(true, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set binding to null - v.set(null); - assertEquals(false, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBind_generic() { - attachChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(true); - - property.bind(v); - assertEquals(true, property.get()); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, false, true, 1); - - // change binding once - v.set(false); - assertEquals(false, property.get()); - property.check(1); - changeListener.check(property, true, false, 1); - - // change binding twice without reading - v.set(true); - v.set(false); - assertEquals(false, property.get()); - property.check(2); - changeListener.check(property, true, false, 2); - - // change binding twice to same value - v.set(true); - v.set(true); - assertEquals(true, property.get()); - property.check(2); - changeListener.check(property, false, true, 1); - - // set binding to null - v.set(null); - assertEquals(false, property.get()); - property.check(1); - changeListener.check(property, true, false, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListener(); - final BooleanProperty v1 = new SimpleBooleanProperty(true); - final BooleanProperty v2 = new SimpleBooleanProperty(false); - property.bind(v1); - property.get(); - property.reset(); - invalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(false, property.get()); - assertTrue(property.isBound()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // change new binding - v2.set(true); - assertEquals(true, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // change old binding - v1.set(false); - assertEquals(true, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(true, property.get()); - assertTrue(property.isBound()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListener(); - final BooleanProperty v = new SimpleBooleanProperty(true); - property.bind(v); - property.unbind(); - assertEquals(true, property.get()); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(false); - assertEquals(true, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(false); - assertEquals(false, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final BooleanProperty v = new SimpleBooleanProperty(true); - final InvalidationListenerMock listener2 = new InvalidationListenerMock(); - final InvalidationListenerMock listener3 = new InvalidationListenerMock(); - - // setting the property - property.set(true); - property.addListener(listener2); - listener2.reset(); - property.set(false); - listener2.check(property, 1); - - // binding the property - property.bind(v); - v.set(false); - property.addListener(listener3); - v.get(); - listener3.reset(); - v.set(true); - listener3.check(property, 1); - } - - @Test - public void testToString() { - final BooleanProperty v = new SimpleBooleanProperty(true); - - property.set(true); - assertEquals("BooleanProperty [value: true]", property.toString()); - - property.bind(v); - assertEquals("BooleanProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("BooleanProperty [bound, value: true]", property.toString()); - v.set(false); - assertEquals("BooleanProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("BooleanProperty [bound, value: false]", property.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final BooleanProperty v1 = new BooleanPropertyMock(bean, name); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", name: My name, value: false]", v1.toString()); - v1.set(true); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", name: My name, value: true]", v1.toString()); - - final BooleanProperty v2 = new BooleanPropertyMock(bean, NO_NAME_1); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: false]", v2.toString()); - v2.set(true); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: true]", v2.toString()); - - final BooleanProperty v3 = new BooleanPropertyMock(bean, NO_NAME_2); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: false]", v3.toString()); - v3.set(true); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: true]", v3.toString()); - - final BooleanProperty v4 = new BooleanPropertyMock(NO_BEAN, name); - assertEquals("BooleanProperty [name: My name, value: false]", v4.toString()); - v4.set(true); - assertEquals("BooleanProperty [name: My name, value: true]", v4.toString()); - } - - private static class BooleanPropertyMock extends BooleanPropertyBase { - - private final Object bean; - private final String name; - private int counter; - - private BooleanPropertyMock() { - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - private BooleanPropertyMock(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - - @Override public Object getBean() { return bean; } - - @Override public String getName() { return name; } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/BooleanPropertyBaseTest.java 2015-08-31 10:23:19.361217565 -0400 @@ -0,0 +1,518 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.BooleanPropertyBase; +import javafx.beans.property.SimpleBooleanProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableBooleanValueStub; +import javafx.beans.value.ObservableObjectValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class BooleanPropertyBaseTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final Boolean UNDEFINED = null; + + private BooleanPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new BooleanPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + } + + private void attachChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + } + + @Test + public void testConstructor() { + final BooleanProperty p1 = new SimpleBooleanProperty(); + assertEquals(false, p1.get()); + assertEquals(Boolean.FALSE, p1.getValue()); + assertFalse(property.isBound()); + + final BooleanProperty p2 = new SimpleBooleanProperty(true); + assertEquals(true, p2.get()); + assertEquals(Boolean.TRUE, p2.getValue()); + assertFalse(property.isBound()); + } + + @Test + public void testInvalidationListener() { + attachInvalidationListener(); + property.set(true); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(false); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + attachChangeListener(); + property.set(true); + changeListener.check(property, false, true, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(false); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testLazySet() { + attachInvalidationListener(); + + // set value once + property.set(true); + assertEquals(true, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.set(true); + assertEquals(true, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.set(false); + property.set(true); + assertEquals(true, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSet() { + attachChangeListener(); + + // set value once + property.set(true); + assertEquals(true, property.get()); + property.check(1); + changeListener.check(property, false, true, 1); + + // set same value again + property.set(true); + assertEquals(true, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(false); + property.set(true); + assertEquals(true, property.get()); + property.check(2); + changeListener.check(property, false, true, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListener(); + + // set value once + property.setValue(true); + assertEquals(true, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.setValue(true); + assertEquals(true, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(false); + property.setValue(true); + assertEquals(true, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSetValue() { + attachChangeListener(); + + // set value once + property.setValue(true); + assertEquals(true, property.get()); + property.check(1); + changeListener.check(property, false, true, 1); + + // set same value again + property.setValue(true); + assertEquals(true, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(false); + property.setValue(true); + assertEquals(true, property.get()); + property.check(2); + changeListener.check(property, false, true, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final BooleanProperty v = new SimpleBooleanProperty(true); + property.bind(v); + property.set(true); + } + + @Test + public void testLazyBind_primitive() { + attachInvalidationListener(); + final ObservableBooleanValueStub v = new ObservableBooleanValueStub(true); + + property.bind(v); + assertEquals(true, property.get()); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(false); + assertEquals(false, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(true); + v.set(false); + assertEquals(false, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(true); + v.set(true); + assertEquals(true, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBind_primitive() { + attachChangeListener(); + final ObservableBooleanValueStub v = new ObservableBooleanValueStub(true); + + property.bind(v); + assertEquals(true, property.get()); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, false, true, 1); + + // change binding once + v.set(false); + assertEquals(false, property.get()); + property.check(1); + changeListener.check(property, true, false, 1); + + // change binding twice without reading + v.set(true); + v.set(false); + assertEquals(false, property.get()); + property.check(2); + changeListener.check(property, true, false, 2); + + // change binding twice to same value + v.set(true); + v.set(true); + assertEquals(true, property.get()); + property.check(2); + changeListener.check(property, false, true, 1); + } + + @Test + public void testLazyBind_generic() { + attachInvalidationListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(true); + + property.bind(v); + assertEquals(true, property.get()); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(false); + assertEquals(false, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(true); + v.set(false); + assertEquals(false, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(true); + v.set(true); + assertEquals(true, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set binding to null + v.set(null); + assertEquals(false, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBind_generic() { + attachChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(true); + + property.bind(v); + assertEquals(true, property.get()); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, false, true, 1); + + // change binding once + v.set(false); + assertEquals(false, property.get()); + property.check(1); + changeListener.check(property, true, false, 1); + + // change binding twice without reading + v.set(true); + v.set(false); + assertEquals(false, property.get()); + property.check(2); + changeListener.check(property, true, false, 2); + + // change binding twice to same value + v.set(true); + v.set(true); + assertEquals(true, property.get()); + property.check(2); + changeListener.check(property, false, true, 1); + + // set binding to null + v.set(null); + assertEquals(false, property.get()); + property.check(1); + changeListener.check(property, true, false, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListener(); + final BooleanProperty v1 = new SimpleBooleanProperty(true); + final BooleanProperty v2 = new SimpleBooleanProperty(false); + property.bind(v1); + property.get(); + property.reset(); + invalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(false, property.get()); + assertTrue(property.isBound()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // change new binding + v2.set(true); + assertEquals(true, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // change old binding + v1.set(false); + assertEquals(true, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(true, property.get()); + assertTrue(property.isBound()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListener(); + final BooleanProperty v = new SimpleBooleanProperty(true); + property.bind(v); + property.unbind(); + assertEquals(true, property.get()); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(false); + assertEquals(true, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(false); + assertEquals(false, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final BooleanProperty v = new SimpleBooleanProperty(true); + final InvalidationListenerMock listener2 = new InvalidationListenerMock(); + final InvalidationListenerMock listener3 = new InvalidationListenerMock(); + + // setting the property + property.set(true); + property.addListener(listener2); + listener2.reset(); + property.set(false); + listener2.check(property, 1); + + // binding the property + property.bind(v); + v.set(false); + property.addListener(listener3); + v.get(); + listener3.reset(); + v.set(true); + listener3.check(property, 1); + } + + @Test + public void testToString() { + final BooleanProperty v = new SimpleBooleanProperty(true); + + property.set(true); + assertEquals("BooleanProperty [value: true]", property.toString()); + + property.bind(v); + assertEquals("BooleanProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("BooleanProperty [bound, value: true]", property.toString()); + v.set(false); + assertEquals("BooleanProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("BooleanProperty [bound, value: false]", property.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final BooleanProperty v1 = new BooleanPropertyMock(bean, name); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", name: My name, value: false]", v1.toString()); + v1.set(true); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", name: My name, value: true]", v1.toString()); + + final BooleanProperty v2 = new BooleanPropertyMock(bean, NO_NAME_1); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: false]", v2.toString()); + v2.set(true); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: true]", v2.toString()); + + final BooleanProperty v3 = new BooleanPropertyMock(bean, NO_NAME_2); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: false]", v3.toString()); + v3.set(true); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: true]", v3.toString()); + + final BooleanProperty v4 = new BooleanPropertyMock(NO_BEAN, name); + assertEquals("BooleanProperty [name: My name, value: false]", v4.toString()); + v4.set(true); + assertEquals("BooleanProperty [name: My name, value: true]", v4.toString()); + } + + private static class BooleanPropertyMock extends BooleanPropertyBase { + + private final Object bean; + private final String name; + private int counter; + + private BooleanPropertyMock() { + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + private BooleanPropertyMock(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + + @Override public Object getBean() { return bean; } + + @Override public String getName() { return name; } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/BooleanPropertyTest.java 2015-08-31 10:23:20.197217555 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,226 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import com.sun.javafx.binding.ErrorLoggingUtiltity; -import javafx.beans.binding.ObjectExpression; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class BooleanPropertyTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final boolean VALUE_1 = true; - private static final boolean VALUE_2 = false; - private static final boolean DEFAULT = false; - - private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); - - @BeforeClass - public static void setUpClass() { - log.start(); - } - - @AfterClass - public static void tearDownClass() { - log.stop(); - } - - @Test - public void testSetValue_Null() { - final BooleanProperty p = new SimpleBooleanProperty(VALUE_1); - p.setValue(null); - assertEquals(DEFAULT, p.get()); - log.checkFine(NullPointerException.class); - } - - @Test - public void testBindBidirectional() { - final BooleanProperty p1 = new SimpleBooleanProperty(VALUE_2); - final BooleanProperty p2 = new SimpleBooleanProperty(VALUE_1); - - p1.bindBidirectional(p2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_2, p2.get()); - - p2.set(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.unbindBidirectional(p2); - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_1); - p2.set(VALUE_2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_2, p2.get()); - } - - @Test - public void testToString() { - final BooleanProperty v0 = new BooleanPropertyStub(NO_BEAN, NO_NAME_1); - assertEquals("BooleanProperty [value: " + DEFAULT + "]", v0.toString()); - - final BooleanProperty v1 = new BooleanPropertyStub(NO_BEAN, NO_NAME_2); - assertEquals("BooleanProperty [value: " + DEFAULT + "]", v1.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final BooleanProperty v2 = new BooleanPropertyStub(bean, name); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - v2.set(VALUE_1); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); - - final BooleanProperty v3 = new BooleanPropertyStub(bean, NO_NAME_1); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - v3.set(VALUE_1); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); - - final BooleanProperty v4 = new BooleanPropertyStub(bean, NO_NAME_2); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - v4.set(VALUE_1); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); - - final BooleanProperty v5 = new BooleanPropertyStub(NO_BEAN, name); - assertEquals("BooleanProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); - v5.set(VALUE_1); - assertEquals("BooleanProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); - } - - @Test - public void testAsObject() { - final BooleanProperty valueModel = new SimpleBooleanProperty(); - final ObjectProperty exp = valueModel.asObject(); - - assertEquals(Boolean.FALSE, exp.get()); - valueModel.set(true); - assertEquals(Boolean.TRUE, exp.get()); - valueModel.set(false); - assertEquals(Boolean.FALSE, exp.get()); - - exp.set(Boolean.TRUE); - assertEquals(true, valueModel.get()); - } - - @Test - public void testObjectToBoolean() { - final ObjectProperty valueModel = new SimpleObjectProperty(true); - final BooleanProperty exp = BooleanProperty.booleanProperty(valueModel); - - assertEquals(true, exp.get()); - valueModel.set(true); - assertEquals(true, exp.get()); - valueModel.set(false); - assertEquals(false, exp.get()); - - exp.set(true); - assertEquals(true, valueModel.get()); - } - - private class BooleanPropertyStub extends BooleanProperty { - - private final Object bean; - private final String name; - private boolean value; - - private BooleanPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean get() { - return value; - } - - @Override - public void set(boolean value) { - this.value = value; - } - - @Override - public void bind(ObservableValue observable) { - fail("Not in use"); - } - - @Override - public void unbind() { - fail("Not in use"); - } - - @Override - public boolean isBound() { - fail("Not in use"); - return false; - } - - @Override - public void addListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void addListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(InvalidationListener listener) { - fail("Not in use"); - } - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/BooleanPropertyTest.java 2015-08-31 10:23:20.065217557 -0400 @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.InvalidationListener; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import test.com.sun.javafx.binding.ErrorLoggingUtiltity; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleObjectProperty; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class BooleanPropertyTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final boolean VALUE_1 = true; + private static final boolean VALUE_2 = false; + private static final boolean DEFAULT = false; + + private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); + + @BeforeClass + public static void setUpClass() { + log.start(); + } + + @AfterClass + public static void tearDownClass() { + log.stop(); + } + + @Test + public void testSetValue_Null() { + final BooleanProperty p = new SimpleBooleanProperty(VALUE_1); + p.setValue(null); + assertEquals(DEFAULT, p.get()); + log.checkFine(NullPointerException.class); + } + + @Test + public void testBindBidirectional() { + final BooleanProperty p1 = new SimpleBooleanProperty(VALUE_2); + final BooleanProperty p2 = new SimpleBooleanProperty(VALUE_1); + + p1.bindBidirectional(p2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_2, p2.get()); + + p2.set(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.unbindBidirectional(p2); + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_1); + p2.set(VALUE_2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_2, p2.get()); + } + + @Test + public void testToString() { + final BooleanProperty v0 = new BooleanPropertyStub(NO_BEAN, NO_NAME_1); + assertEquals("BooleanProperty [value: " + DEFAULT + "]", v0.toString()); + + final BooleanProperty v1 = new BooleanPropertyStub(NO_BEAN, NO_NAME_2); + assertEquals("BooleanProperty [value: " + DEFAULT + "]", v1.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final BooleanProperty v2 = new BooleanPropertyStub(bean, name); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + v2.set(VALUE_1); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); + + final BooleanProperty v3 = new BooleanPropertyStub(bean, NO_NAME_1); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + v3.set(VALUE_1); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); + + final BooleanProperty v4 = new BooleanPropertyStub(bean, NO_NAME_2); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + v4.set(VALUE_1); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); + + final BooleanProperty v5 = new BooleanPropertyStub(NO_BEAN, name); + assertEquals("BooleanProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); + v5.set(VALUE_1); + assertEquals("BooleanProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); + } + + @Test + public void testAsObject() { + final BooleanProperty valueModel = new SimpleBooleanProperty(); + final ObjectProperty exp = valueModel.asObject(); + + assertEquals(Boolean.FALSE, exp.get()); + valueModel.set(true); + assertEquals(Boolean.TRUE, exp.get()); + valueModel.set(false); + assertEquals(Boolean.FALSE, exp.get()); + + exp.set(Boolean.TRUE); + assertEquals(true, valueModel.get()); + } + + @Test + public void testObjectToBoolean() { + final ObjectProperty valueModel = new SimpleObjectProperty(true); + final BooleanProperty exp = BooleanProperty.booleanProperty(valueModel); + + assertEquals(true, exp.get()); + valueModel.set(true); + assertEquals(true, exp.get()); + valueModel.set(false); + assertEquals(false, exp.get()); + + exp.set(true); + assertEquals(true, valueModel.get()); + } + + private class BooleanPropertyStub extends BooleanProperty { + + private final Object bean; + private final String name; + private boolean value; + + private BooleanPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean get() { + return value; + } + + @Override + public void set(boolean value) { + this.value = value; + } + + @Override + public void bind(ObservableValue observable) { + fail("Not in use"); + } + + @Override + public void unbind() { + fail("Not in use"); + } + + @Override + public boolean isBound() { + fail("Not in use"); + return false; + } + + @Override + public void addListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void addListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(InvalidationListener listener) { + fail("Not in use"); + } + + } +} --- old/modules/base/src/test/java/javafx/beans/property/DoublePropertyBaseTest.java 2015-08-31 10:23:20.873217548 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,550 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableDoubleValueStub; -import javafx.beans.value.ObservableValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class DoublePropertyBaseTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final Double UNDEFINED = Double.MAX_VALUE; - private static final double EPSILON = 1e-12; - - private DoublePropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new DoublePropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - } - - private void attachChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - } - - @Test - public void testConstructor() { - final DoubleProperty p1 = new SimpleDoubleProperty(); - assertEquals(0.0, p1.get(), EPSILON); - assertEquals(Double.valueOf(0.0), p1.getValue(), EPSILON); - assertFalse(property.isBound()); - - final DoubleProperty p2 = new SimpleDoubleProperty(-Math.PI); - assertEquals(-Math.PI, p2.get(), EPSILON); - assertEquals(Double.valueOf(-Math.PI), p2.getValue(), EPSILON); - assertFalse(property.isBound()); - } - - @Test - public void testInvalidationListener() { - attachInvalidationListener(); - property.set(Math.E); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(Math.PI); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - attachChangeListener(); - property.set(Math.E); - changeListener.check(property, 0.0, Math.E, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(Math.PI); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testLazySet() { - attachInvalidationListener(); - - // set value once - property.set(Math.E); - assertEquals(Math.E, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.set(Math.E); - assertEquals(Math.E, property.get(), EPSILON); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.set(Math.PI); - property.set(-Math.PI); - assertEquals(-Math.PI, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSet() { - attachChangeListener(); - - // set value once - property.set(Math.E); - assertEquals(Math.E, property.get(), EPSILON); - property.check(1); - changeListener.check(property, 0.0, Math.E, 1); - - // set same value again - property.set(Math.E); - assertEquals(Math.E, property.get(), EPSILON); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(Math.PI); - property.set(-Math.PI); - assertEquals(-Math.PI, property.get(), EPSILON); - property.check(2); - changeListener.check(property, Math.PI, -Math.PI, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListener(); - - // set value once - property.setValue(Math.E); - assertEquals(Math.E, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.setValue(Math.E); - assertEquals(Math.E, property.get(), EPSILON); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(Math.PI); - property.setValue(-Math.PI); - assertEquals(-Math.PI, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSetValue() { - attachChangeListener(); - - // set value once - property.setValue(Math.E); - assertEquals(Math.E, property.get(), EPSILON); - property.check(1); - changeListener.check(property, 0.0, Math.E, 1); - - // set same value again - property.setValue(Math.E); - assertEquals(Math.E, property.get(), EPSILON); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(Math.PI); - property.setValue(-Math.PI); - assertEquals(-Math.PI, property.get(), EPSILON); - property.check(2); - changeListener.check(property, Math.PI, -Math.PI, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final DoubleProperty v = new SimpleDoubleProperty(Math.PI); - property.bind(v); - property.set(Math.PI); - } - - @Test - public void testLazyBind() { - attachInvalidationListener(); - final ObservableDoubleValueStub v = new ObservableDoubleValueStub(Math.PI); - - property.bind(v); - assertEquals(Math.PI, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(Math.E); - assertEquals(Math.E, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(Math.PI); - v.set(-Math.PI); - assertEquals(-Math.PI, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(Math.PI); - v.set(Math.PI); - assertEquals(Math.PI, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBind() { - attachChangeListener(); - final ObservableDoubleValueStub v = new ObservableDoubleValueStub(Math.PI); - - property.bind(v); - assertEquals(Math.PI, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, 0.0, Math.PI, 1); - - // change binding once - v.set(Math.E); - assertEquals(Math.E, property.get(), EPSILON); - property.check(1); - changeListener.check(property, Math.PI, Math.E, 1); - - // change binding twice without reading - v.set(Math.PI); - v.set(-Math.PI); - assertEquals(-Math.PI, property.get(), EPSILON); - property.check(2); - changeListener.check(property, Math.PI, -Math.PI, 2); - - // change binding twice to same value - v.set(Math.PI); - v.set(Math.PI); - assertEquals(Math.PI, property.get(), EPSILON); - property.check(2); - changeListener.check(property, -Math.PI, Math.PI, 1); - } - - @Test - public void testLazyBindObservableValue() { - final double value1 = Math.PI; - final double value2 = Math.E; - attachInvalidationListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - - property.bind(v); - assertEquals(value1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(value2); - assertEquals(value2, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(value1); - v.set(value2); - assertEquals(value2, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(value1); - v.set(value1); - assertEquals(value1, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // set binding to null - v.set(null); - assertEquals(0.0, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBindObservableValue() { - final double value1 = Math.PI; - final double value2 = Math.E; - attachChangeListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - - property.bind(v); - assertEquals(value1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, 0.0, value1, 1); - - // change binding once - v.set(value2); - assertEquals(value2, property.get(), EPSILON); - property.check(1); - changeListener.check(property, value1, value2, 1); - - // change binding twice without reading - v.set(value1); - v.set(value2); - assertEquals(value2, property.get(), EPSILON); - property.check(2); - changeListener.check(property, value1, value2, 2); - - // change binding twice to same value - v.set(value1); - v.set(value1); - assertEquals(value1, property.get(), EPSILON); - property.check(2); - changeListener.check(property, value2, value1, 1); - - // set binding to null - v.set(null); - assertEquals(0.0, property.get(), EPSILON); - property.check(1); - changeListener.check(property, value1, 0.0, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListener(); - final DoubleProperty v1 = new SimpleDoubleProperty(Math.PI); - final DoubleProperty v2 = new SimpleDoubleProperty(Math.E); - property.bind(v1); - property.get(); - property.reset(); - invalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(Math.E, property.get(), EPSILON); - assertTrue(property.isBound()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // change old binding - v1.set(-Math.PI); - assertEquals(Math.E, property.get(), EPSILON); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // change new binding - v2.set(-Math.E); - assertEquals(-Math.E, property.get(), EPSILON); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(-Math.E, property.get(), EPSILON); - assertTrue(property.isBound()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListener(); - final DoubleProperty v = new SimpleDoubleProperty(Math.PI); - property.bind(v); - property.unbind(); - assertEquals(Math.PI, property.get(), EPSILON); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(Math.E); - assertEquals(Math.PI, property.get(), EPSILON); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(-Math.PI); - assertEquals(-Math.PI, property.get(), EPSILON); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testUnbindObservableValue() { - final double value1 = Math.PI; - final double value2 = Math.E; - - attachInvalidationListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - property.bind(v); - property.unbind(); - assertEquals(value1, property.get(), EPSILON); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(value2); - assertEquals(value1, property.get(), EPSILON); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(value2); - assertEquals(value2, property.get(), EPSILON); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final DoubleProperty v = new SimpleDoubleProperty(Math.PI); - final InvalidationListenerMock listener2 = new InvalidationListenerMock(); - final InvalidationListenerMock listener3 = new InvalidationListenerMock(); - - // setting the property - property.set(Math.PI); - property.addListener(listener2); - listener2.reset(); - property.set(-Math.PI); - listener2.check(property, 1); - - // binding the property - property.bind(v); - v.set(Math.E); - property.addListener(listener3); - v.get(); - listener3.reset(); - v.set(-Math.E); - listener3.check(property, 1); - } - - @Test - public void testToString() { - final double value1 = Math.E; - final double value2 = -Math.PI; - final DoubleProperty v = new SimpleDoubleProperty(value2); - - property.set(value1); - assertEquals("DoubleProperty [value: " + value1 + "]", property.toString()); - - property.bind(v); - assertEquals("DoubleProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("DoubleProperty [bound, value: " + value2 + "]", property.toString()); - v.set(value1); - assertEquals("DoubleProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("DoubleProperty [bound, value: " + value1 + "]", property.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final DoubleProperty v1 = new DoublePropertyMock(bean, name); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + 0.0 + "]", v1.toString()); - v1.set(value1); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); - - final DoubleProperty v2 = new DoublePropertyMock(bean, NO_NAME_1); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + 0.0 + "]", v2.toString()); - v2.set(value1); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); - - final DoubleProperty v3 = new DoublePropertyMock(bean, NO_NAME_2); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + 0.0 + "]", v3.toString()); - v3.set(value1); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); - - final DoubleProperty v4 = new DoublePropertyMock(NO_BEAN, name); - assertEquals("DoubleProperty [name: My name, value: " + 0.0 + "]", v4.toString()); - v4.set(value1); - assertEquals("DoubleProperty [name: My name, value: " + value1 + "]", v4.toString()); - } - - private static class DoublePropertyMock extends DoublePropertyBase { - - private final Object bean; - private final String name; - private int counter; - - private DoublePropertyMock() { - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - private DoublePropertyMock(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - - @Override public Object getBean() { return bean; } - - @Override public String getName() { return name; } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/DoublePropertyBaseTest.java 2015-08-31 10:23:20.741217549 -0400 @@ -0,0 +1,553 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.DoublePropertyBase; +import javafx.beans.property.SimpleDoubleProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableDoubleValueStub; +import javafx.beans.value.ObservableValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class DoublePropertyBaseTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final Double UNDEFINED = Double.MAX_VALUE; + private static final double EPSILON = 1e-12; + + private DoublePropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new DoublePropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + } + + private void attachChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + } + + @Test + public void testConstructor() { + final DoubleProperty p1 = new SimpleDoubleProperty(); + assertEquals(0.0, p1.get(), EPSILON); + assertEquals(Double.valueOf(0.0), p1.getValue(), EPSILON); + assertFalse(property.isBound()); + + final DoubleProperty p2 = new SimpleDoubleProperty(-Math.PI); + assertEquals(-Math.PI, p2.get(), EPSILON); + assertEquals(Double.valueOf(-Math.PI), p2.getValue(), EPSILON); + assertFalse(property.isBound()); + } + + @Test + public void testInvalidationListener() { + attachInvalidationListener(); + property.set(Math.E); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(Math.PI); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + attachChangeListener(); + property.set(Math.E); + changeListener.check(property, 0.0, Math.E, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(Math.PI); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testLazySet() { + attachInvalidationListener(); + + // set value once + property.set(Math.E); + assertEquals(Math.E, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.set(Math.E); + assertEquals(Math.E, property.get(), EPSILON); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.set(Math.PI); + property.set(-Math.PI); + assertEquals(-Math.PI, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSet() { + attachChangeListener(); + + // set value once + property.set(Math.E); + assertEquals(Math.E, property.get(), EPSILON); + property.check(1); + changeListener.check(property, 0.0, Math.E, 1); + + // set same value again + property.set(Math.E); + assertEquals(Math.E, property.get(), EPSILON); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(Math.PI); + property.set(-Math.PI); + assertEquals(-Math.PI, property.get(), EPSILON); + property.check(2); + changeListener.check(property, Math.PI, -Math.PI, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListener(); + + // set value once + property.setValue(Math.E); + assertEquals(Math.E, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.setValue(Math.E); + assertEquals(Math.E, property.get(), EPSILON); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(Math.PI); + property.setValue(-Math.PI); + assertEquals(-Math.PI, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSetValue() { + attachChangeListener(); + + // set value once + property.setValue(Math.E); + assertEquals(Math.E, property.get(), EPSILON); + property.check(1); + changeListener.check(property, 0.0, Math.E, 1); + + // set same value again + property.setValue(Math.E); + assertEquals(Math.E, property.get(), EPSILON); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(Math.PI); + property.setValue(-Math.PI); + assertEquals(-Math.PI, property.get(), EPSILON); + property.check(2); + changeListener.check(property, Math.PI, -Math.PI, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final DoubleProperty v = new SimpleDoubleProperty(Math.PI); + property.bind(v); + property.set(Math.PI); + } + + @Test + public void testLazyBind() { + attachInvalidationListener(); + final ObservableDoubleValueStub v = new ObservableDoubleValueStub(Math.PI); + + property.bind(v); + assertEquals(Math.PI, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(Math.E); + assertEquals(Math.E, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(Math.PI); + v.set(-Math.PI); + assertEquals(-Math.PI, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(Math.PI); + v.set(Math.PI); + assertEquals(Math.PI, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBind() { + attachChangeListener(); + final ObservableDoubleValueStub v = new ObservableDoubleValueStub(Math.PI); + + property.bind(v); + assertEquals(Math.PI, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, 0.0, Math.PI, 1); + + // change binding once + v.set(Math.E); + assertEquals(Math.E, property.get(), EPSILON); + property.check(1); + changeListener.check(property, Math.PI, Math.E, 1); + + // change binding twice without reading + v.set(Math.PI); + v.set(-Math.PI); + assertEquals(-Math.PI, property.get(), EPSILON); + property.check(2); + changeListener.check(property, Math.PI, -Math.PI, 2); + + // change binding twice to same value + v.set(Math.PI); + v.set(Math.PI); + assertEquals(Math.PI, property.get(), EPSILON); + property.check(2); + changeListener.check(property, -Math.PI, Math.PI, 1); + } + + @Test + public void testLazyBindObservableValue() { + final double value1 = Math.PI; + final double value2 = Math.E; + attachInvalidationListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + + property.bind(v); + assertEquals(value1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(value2); + assertEquals(value2, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(value1); + v.set(value2); + assertEquals(value2, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(value1); + v.set(value1); + assertEquals(value1, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // set binding to null + v.set(null); + assertEquals(0.0, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBindObservableValue() { + final double value1 = Math.PI; + final double value2 = Math.E; + attachChangeListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + + property.bind(v); + assertEquals(value1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, 0.0, value1, 1); + + // change binding once + v.set(value2); + assertEquals(value2, property.get(), EPSILON); + property.check(1); + changeListener.check(property, value1, value2, 1); + + // change binding twice without reading + v.set(value1); + v.set(value2); + assertEquals(value2, property.get(), EPSILON); + property.check(2); + changeListener.check(property, value1, value2, 2); + + // change binding twice to same value + v.set(value1); + v.set(value1); + assertEquals(value1, property.get(), EPSILON); + property.check(2); + changeListener.check(property, value2, value1, 1); + + // set binding to null + v.set(null); + assertEquals(0.0, property.get(), EPSILON); + property.check(1); + changeListener.check(property, value1, 0.0, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListener(); + final DoubleProperty v1 = new SimpleDoubleProperty(Math.PI); + final DoubleProperty v2 = new SimpleDoubleProperty(Math.E); + property.bind(v1); + property.get(); + property.reset(); + invalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(Math.E, property.get(), EPSILON); + assertTrue(property.isBound()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // change old binding + v1.set(-Math.PI); + assertEquals(Math.E, property.get(), EPSILON); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // change new binding + v2.set(-Math.E); + assertEquals(-Math.E, property.get(), EPSILON); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(-Math.E, property.get(), EPSILON); + assertTrue(property.isBound()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListener(); + final DoubleProperty v = new SimpleDoubleProperty(Math.PI); + property.bind(v); + property.unbind(); + assertEquals(Math.PI, property.get(), EPSILON); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(Math.E); + assertEquals(Math.PI, property.get(), EPSILON); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(-Math.PI); + assertEquals(-Math.PI, property.get(), EPSILON); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testUnbindObservableValue() { + final double value1 = Math.PI; + final double value2 = Math.E; + + attachInvalidationListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + property.bind(v); + property.unbind(); + assertEquals(value1, property.get(), EPSILON); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(value2); + assertEquals(value1, property.get(), EPSILON); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(value2); + assertEquals(value2, property.get(), EPSILON); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final DoubleProperty v = new SimpleDoubleProperty(Math.PI); + final InvalidationListenerMock listener2 = new InvalidationListenerMock(); + final InvalidationListenerMock listener3 = new InvalidationListenerMock(); + + // setting the property + property.set(Math.PI); + property.addListener(listener2); + listener2.reset(); + property.set(-Math.PI); + listener2.check(property, 1); + + // binding the property + property.bind(v); + v.set(Math.E); + property.addListener(listener3); + v.get(); + listener3.reset(); + v.set(-Math.E); + listener3.check(property, 1); + } + + @Test + public void testToString() { + final double value1 = Math.E; + final double value2 = -Math.PI; + final DoubleProperty v = new SimpleDoubleProperty(value2); + + property.set(value1); + assertEquals("DoubleProperty [value: " + value1 + "]", property.toString()); + + property.bind(v); + assertEquals("DoubleProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("DoubleProperty [bound, value: " + value2 + "]", property.toString()); + v.set(value1); + assertEquals("DoubleProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("DoubleProperty [bound, value: " + value1 + "]", property.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final DoubleProperty v1 = new DoublePropertyMock(bean, name); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + 0.0 + "]", v1.toString()); + v1.set(value1); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); + + final DoubleProperty v2 = new DoublePropertyMock(bean, NO_NAME_1); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + 0.0 + "]", v2.toString()); + v2.set(value1); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); + + final DoubleProperty v3 = new DoublePropertyMock(bean, NO_NAME_2); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + 0.0 + "]", v3.toString()); + v3.set(value1); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); + + final DoubleProperty v4 = new DoublePropertyMock(NO_BEAN, name); + assertEquals("DoubleProperty [name: My name, value: " + 0.0 + "]", v4.toString()); + v4.set(value1); + assertEquals("DoubleProperty [name: My name, value: " + value1 + "]", v4.toString()); + } + + private static class DoublePropertyMock extends DoublePropertyBase { + + private final Object bean; + private final String name; + private int counter; + + private DoublePropertyMock() { + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + private DoublePropertyMock(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + + @Override public Object getBean() { return bean; } + + @Override public String getName() { return name; } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/DoublePropertyTest.java 2015-08-31 10:23:21.477217541 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import com.sun.javafx.binding.ErrorLoggingUtiltity; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class DoublePropertyTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final double VALUE_1 = Math.PI; - private static final double VALUE_2 = -Math.E; - private static final double DEFAULT = 0.0; - private static final double EPSILON = 1e-12; - - private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); - - @BeforeClass - public static void setUpClass() { - log.start(); - } - - @AfterClass - public static void tearDownClass() { - log.stop(); - } - - @Test - public void testSetValue_Null() { - final DoubleProperty p = new SimpleDoubleProperty(VALUE_1); - p.setValue(null); - assertEquals(DEFAULT, p.get(), EPSILON); - log.checkFine(NullPointerException.class); - } - - @Test - public void testBindBidirectional() { - final DoubleProperty p1 = new SimpleDoubleProperty(VALUE_2); - final DoubleProperty p2 = new SimpleDoubleProperty(VALUE_1); - - p1.bindBidirectional(p2); - assertEquals(VALUE_1, p1.get(), EPSILON); - assertEquals(VALUE_1, p2.get(), EPSILON); - - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get(), EPSILON); - assertEquals(VALUE_2, p2.get(), EPSILON); - - p2.set(VALUE_1); - assertEquals(VALUE_1, p1.get(), EPSILON); - assertEquals(VALUE_1, p2.get(), EPSILON); - - p1.unbindBidirectional(p2); - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get(), EPSILON); - assertEquals(VALUE_1, p2.get(), EPSILON); - - p1.set(VALUE_1); - p2.set(VALUE_2); - assertEquals(VALUE_1, p1.get(), EPSILON); - assertEquals(VALUE_2, p2.get(), EPSILON); - } - - @Test - public void testToString() { - final DoubleProperty v0 = new DoublePropertyStub(NO_BEAN, NO_NAME_1); - assertEquals("DoubleProperty [value: " + DEFAULT + "]", v0.toString()); - - final DoubleProperty v1 = new DoublePropertyStub(NO_BEAN, NO_NAME_2); - assertEquals("DoubleProperty [value: " + DEFAULT + "]", v1.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final DoubleProperty v2 = new DoublePropertyStub(bean, name); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - v2.set(VALUE_1); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); - - final DoubleProperty v3 = new DoublePropertyStub(bean, NO_NAME_1); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - v3.set(VALUE_1); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); - - final DoubleProperty v4 = new DoublePropertyStub(bean, NO_NAME_2); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - v4.set(VALUE_1); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); - - final DoubleProperty v5 = new DoublePropertyStub(NO_BEAN, name); - assertEquals("DoubleProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); - v5.set(VALUE_1); - assertEquals("DoubleProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); - } - - @Test - public void testAsObject() { - final DoubleProperty valueModel = new SimpleDoubleProperty(2d); - final ObjectProperty exp = valueModel.asObject(); - - assertEquals(2d, exp.getValue(), EPSILON); - valueModel.set(-4354.3); - assertEquals(-4354.3, exp.getValue(), EPSILON); - valueModel.set(5e11); - assertEquals(5e11, exp.getValue(), EPSILON); - - exp.set(1234.0); - assertEquals(1234.0, valueModel.doubleValue(), EPSILON); - - } - - @Test - public void testObjectToDouble() { - final ObjectProperty valueModel = new SimpleObjectProperty(); - final DoubleProperty exp = DoubleProperty.doubleProperty(valueModel); - - assertEquals(0.0, exp.doubleValue(), EPSILON); - valueModel.set(-4354.3); - assertEquals(-4354.3, exp.doubleValue(), EPSILON); - valueModel.set(5e11); - assertEquals(5e11, exp.doubleValue(), EPSILON); - - exp.set(1234.0); - assertEquals(1234.0, valueModel.getValue(), EPSILON); - } - - private class DoublePropertyStub extends DoubleProperty { - - private final Object bean; - private final String name; - private double value; - - private DoublePropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - - @Override - public double get() { - return value; - } - - @Override - public void set(double value) { - this.value = value; - } - - @Override - public void bind(ObservableValue observable) { - fail("Not in use"); - } - - @Override - public void unbind() { - fail("Not in use"); - } - - @Override - public boolean isBound() { - fail("Not in use"); - return false; - } - - @Override - public void addListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void addListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(InvalidationListener listener) { - fail("Not in use"); - } - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/DoublePropertyTest.java 2015-08-31 10:23:21.341217542 -0400 @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.InvalidationListener; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import test.com.sun.javafx.binding.ErrorLoggingUtiltity; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class DoublePropertyTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final double VALUE_1 = Math.PI; + private static final double VALUE_2 = -Math.E; + private static final double DEFAULT = 0.0; + private static final double EPSILON = 1e-12; + + private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); + + @BeforeClass + public static void setUpClass() { + log.start(); + } + + @AfterClass + public static void tearDownClass() { + log.stop(); + } + + @Test + public void testSetValue_Null() { + final DoubleProperty p = new SimpleDoubleProperty(VALUE_1); + p.setValue(null); + assertEquals(DEFAULT, p.get(), EPSILON); + log.checkFine(NullPointerException.class); + } + + @Test + public void testBindBidirectional() { + final DoubleProperty p1 = new SimpleDoubleProperty(VALUE_2); + final DoubleProperty p2 = new SimpleDoubleProperty(VALUE_1); + + p1.bindBidirectional(p2); + assertEquals(VALUE_1, p1.get(), EPSILON); + assertEquals(VALUE_1, p2.get(), EPSILON); + + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get(), EPSILON); + assertEquals(VALUE_2, p2.get(), EPSILON); + + p2.set(VALUE_1); + assertEquals(VALUE_1, p1.get(), EPSILON); + assertEquals(VALUE_1, p2.get(), EPSILON); + + p1.unbindBidirectional(p2); + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get(), EPSILON); + assertEquals(VALUE_1, p2.get(), EPSILON); + + p1.set(VALUE_1); + p2.set(VALUE_2); + assertEquals(VALUE_1, p1.get(), EPSILON); + assertEquals(VALUE_2, p2.get(), EPSILON); + } + + @Test + public void testToString() { + final DoubleProperty v0 = new DoublePropertyStub(NO_BEAN, NO_NAME_1); + assertEquals("DoubleProperty [value: " + DEFAULT + "]", v0.toString()); + + final DoubleProperty v1 = new DoublePropertyStub(NO_BEAN, NO_NAME_2); + assertEquals("DoubleProperty [value: " + DEFAULT + "]", v1.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final DoubleProperty v2 = new DoublePropertyStub(bean, name); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + v2.set(VALUE_1); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); + + final DoubleProperty v3 = new DoublePropertyStub(bean, NO_NAME_1); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + v3.set(VALUE_1); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); + + final DoubleProperty v4 = new DoublePropertyStub(bean, NO_NAME_2); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + v4.set(VALUE_1); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); + + final DoubleProperty v5 = new DoublePropertyStub(NO_BEAN, name); + assertEquals("DoubleProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); + v5.set(VALUE_1); + assertEquals("DoubleProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); + } + + @Test + public void testAsObject() { + final DoubleProperty valueModel = new SimpleDoubleProperty(2d); + final ObjectProperty exp = valueModel.asObject(); + + assertEquals(2d, exp.getValue(), EPSILON); + valueModel.set(-4354.3); + assertEquals(-4354.3, exp.getValue(), EPSILON); + valueModel.set(5e11); + assertEquals(5e11, exp.getValue(), EPSILON); + + exp.set(1234.0); + assertEquals(1234.0, valueModel.doubleValue(), EPSILON); + + } + + @Test + public void testObjectToDouble() { + final ObjectProperty valueModel = new SimpleObjectProperty(); + final DoubleProperty exp = DoubleProperty.doubleProperty(valueModel); + + assertEquals(0.0, exp.doubleValue(), EPSILON); + valueModel.set(-4354.3); + assertEquals(-4354.3, exp.doubleValue(), EPSILON); + valueModel.set(5e11); + assertEquals(5e11, exp.doubleValue(), EPSILON); + + exp.set(1234.0); + assertEquals(1234.0, valueModel.getValue(), EPSILON); + } + + private class DoublePropertyStub extends DoubleProperty { + + private final Object bean; + private final String name; + private double value; + + private DoublePropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + + @Override + public double get() { + return value; + } + + @Override + public void set(double value) { + this.value = value; + } + + @Override + public void bind(ObservableValue observable) { + fail("Not in use"); + } + + @Override + public void unbind() { + fail("Not in use"); + } + + @Override + public boolean isBound() { + fail("Not in use"); + return false; + } + + @Override + public void addListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void addListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(InvalidationListener listener) { + fail("Not in use"); + } + + } +} --- old/modules/base/src/test/java/javafx/beans/property/FloatPropertyBaseTest.java 2015-08-31 10:23:22.157217533 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,554 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableFloatValueStub; -import javafx.beans.value.ObservableValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class FloatPropertyBaseTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final Float UNDEFINED = Float.MAX_VALUE; - private static final float EPSILON = 1e-6f; - private static final float PI = (float)Math.PI; - private static final float E = (float)Math.E; - - private FloatPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new FloatPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - } - - private void attachChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - } - - @Test - public void testConstructor() { - final FloatProperty p1 = new SimpleFloatProperty(); - assertEquals(0.0f, p1.get(), EPSILON); - assertEquals(Float.valueOf(0.0f), p1.getValue(), EPSILON); - assertFalse(property.isBound()); - - final FloatProperty p2 = new SimpleFloatProperty(-PI); - assertEquals(-PI, p2.get(), EPSILON); - assertEquals(Float.valueOf(-PI), p2.getValue(), EPSILON); - assertFalse(property.isBound()); - } - - @Test - public void testInvalidationListener() { - attachInvalidationListener(); - property.set(E); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(PI); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - attachChangeListener(); - property.set(E); - changeListener.check(property, 0.0f, E, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(PI); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testLazySet() { - attachInvalidationListener(); - - // set value once - property.set(E); - assertEquals(E, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.set(E); - assertEquals(E, property.get(), EPSILON); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.set(PI); - property.set(-PI); - assertEquals(-PI, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSet() { - attachChangeListener(); - - // set value once - property.set(E); - assertEquals(E, property.get(), EPSILON); - property.check(1); - changeListener.check(property, 0.0f, E, 1); - - // set same value again - property.set(E); - assertEquals(E, property.get(), EPSILON); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(PI); - property.set(-PI); - assertEquals(-PI, property.get(), EPSILON); - property.check(2); - changeListener.check(property, PI, -PI, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListener(); - - // set value once - property.setValue(E); - assertEquals(E, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.setValue(E); - assertEquals(E, property.get(), EPSILON); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(PI); - property.setValue(-PI); - assertEquals(-PI, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSetValue() { - attachChangeListener(); - - // set value once - property.setValue(E); - assertEquals(E, property.get(), EPSILON); - property.check(1); - changeListener.check(property, 0.0f, E, 1); - - // set same value again - property.setValue(E); - assertEquals(E, property.get(), EPSILON); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(PI); - property.setValue(-PI); - assertEquals(-PI, property.get(), EPSILON); - property.check(2); - changeListener.check(property, PI, -PI, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final FloatProperty v = new SimpleFloatProperty(PI); - property.bind(v); - property.set(PI); - } - - @Test - public void testLazyBind() { - attachInvalidationListener(); - final FloatProperty v = new SimpleFloatProperty(PI); - property.reset(); - - property.bind(v); - assertEquals(PI, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(E); - assertEquals(E, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(PI); - v.set(-PI); - assertEquals(-PI, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(PI); - v.set(PI); - assertEquals(PI, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBind() { - attachChangeListener(); - final ObservableFloatValueStub v = new ObservableFloatValueStub(PI); - property.reset(); - - property.bind(v); - assertEquals(PI, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, 0.0f, PI, 1); - - // change binding once - v.set(E); - assertEquals(E, property.get(), EPSILON); - property.check(1); - changeListener.check(property, PI, E, 1); - - // change binding twice without reading - v.set(PI); - v.set(-PI); - assertEquals(-PI, property.get(), EPSILON); - property.check(2); - changeListener.check(property, PI, -PI, 2); - - // change binding twice to same value - v.set(PI); - v.set(PI); - assertEquals(PI, property.get(), EPSILON); - property.check(2); - changeListener.check(property, -PI, PI, 1); - } - - @Test - public void testLazyBindObservableValue() { - final float value1 = (float)Math.PI; - final float value2 = (float)Math.E; - attachInvalidationListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - - property.bind(v); - assertEquals(value1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(value2); - assertEquals(value2, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(value1); - v.set(value2); - assertEquals(value2, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(value1); - v.set(value1); - assertEquals(value1, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - - // set binding to null - v.set(null); - assertEquals(0.0f, property.get(), EPSILON); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBindObservableValue() { - final float value1 = (float)Math.PI; - final float value2 = (float)Math.E; - attachChangeListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - - property.bind(v); - assertEquals(value1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, 0.0f, value1, 1); - - // change binding once - v.set(value2); - assertEquals(value2, property.get(), EPSILON); - property.check(1); - changeListener.check(property, value1, value2, 1); - - // change binding twice without reading - v.set(value1); - v.set(value2); - assertEquals(value2, property.get(), EPSILON); - property.check(2); - changeListener.check(property, value1, value2, 2); - - // change binding twice to same value - v.set(value1); - v.set(value1); - assertEquals(value1, property.get(), EPSILON); - property.check(2); - changeListener.check(property, value2, value1, 1); - - // set binding to null - v.set(null); - assertEquals(0.0f, property.get(), EPSILON); - property.check(1); - changeListener.check(property, value1, 0.0f, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListener(); - final FloatProperty v1 = new SimpleFloatProperty(PI); - final FloatProperty v2 = new SimpleFloatProperty(E); - property.bind(v1); - property.get(); - property.reset(); - invalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(E, property.get(), EPSILON); - assertTrue(property.isBound()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // change old binding - v1.set(-PI); - assertEquals(E, property.get(), EPSILON); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // change new binding - v2.set(-E); - assertEquals(-E, property.get(), EPSILON); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(-E, property.get(), EPSILON); - assertTrue(property.isBound()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListener(); - final FloatProperty v = new SimpleFloatProperty(PI); - property.bind(v); - property.unbind(); - assertEquals(PI, property.get(), EPSILON); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(E); - assertEquals(PI, property.get(), EPSILON); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(-PI); - assertEquals(-PI, property.get(), EPSILON); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testUnbindObservableValue() { - final float value1 = (float)Math.PI; - final float value2 = (float)Math.E; - - attachInvalidationListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - property.bind(v); - property.unbind(); - assertEquals(value1, property.get(), EPSILON); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(value2); - assertEquals(value1, property.get(), EPSILON); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(value2); - assertEquals(value2, property.get(), EPSILON); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final FloatProperty v = new SimpleFloatProperty(PI); - final InvalidationListenerMock listener2 = new InvalidationListenerMock(); - final InvalidationListenerMock listener3 = new InvalidationListenerMock(); - - // setting the property - property.set(PI); - property.addListener(listener2); - listener2.reset(); - property.set(-PI); - listener2.check(property, 1); - - // binding the property - property.bind(v); - v.set(E); - property.addListener(listener3); - v.get(); - listener3.reset(); - v.set(-E); - listener3.check(property, 1); - } - - @Test - public void testToString() { - final float value1 = (float)Math.E; - final float value2 = (float)-Math.PI; - final FloatProperty v = new SimpleFloatProperty(value2); - - property.set(value1); - assertEquals("FloatProperty [value: " + value1 + "]", property.toString()); - - property.bind(v); - assertEquals("FloatProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("FloatProperty [bound, value: " + value2 + "]", property.toString()); - v.set(value1); - assertEquals("FloatProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("FloatProperty [bound, value: " + value1 + "]", property.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final FloatProperty v1 = new FloatPropertyMock(bean, name); - assertEquals("FloatProperty [bean: " + bean.toString() + ", name: My name, value: " + 0.0f + "]", v1.toString()); - v1.set(value1); - assertEquals("FloatProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); - - final FloatProperty v2 = new FloatPropertyMock(bean, NO_NAME_1); - assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + 0.0f + "]", v2.toString()); - v2.set(value1); - assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); - - final FloatProperty v3 = new FloatPropertyMock(bean, NO_NAME_2); - assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + 0.0f + "]", v3.toString()); - v3.set(value1); - assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); - - final FloatProperty v4 = new FloatPropertyMock(NO_BEAN, name); - assertEquals("FloatProperty [name: My name, value: " + 0.0f + "]", v4.toString()); - v4.set(value1); - assertEquals("FloatProperty [name: My name, value: " + value1 + "]", v4.toString()); - } - - private static class FloatPropertyMock extends FloatPropertyBase { - - private final Object bean; - private final String name; - private int counter; - - private FloatPropertyMock() { - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - private FloatPropertyMock(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - - @Override public Object getBean() { return bean; } - - @Override public String getName() { return name; } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/FloatPropertyBaseTest.java 2015-08-31 10:23:22.021217535 -0400 @@ -0,0 +1,557 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.FloatProperty; +import javafx.beans.property.FloatPropertyBase; +import javafx.beans.property.SimpleFloatProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableFloatValueStub; +import javafx.beans.value.ObservableValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class FloatPropertyBaseTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final Float UNDEFINED = Float.MAX_VALUE; + private static final float EPSILON = 1e-6f; + private static final float PI = (float)Math.PI; + private static final float E = (float)Math.E; + + private FloatPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new FloatPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + } + + private void attachChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + } + + @Test + public void testConstructor() { + final FloatProperty p1 = new SimpleFloatProperty(); + assertEquals(0.0f, p1.get(), EPSILON); + assertEquals(Float.valueOf(0.0f), p1.getValue(), EPSILON); + assertFalse(property.isBound()); + + final FloatProperty p2 = new SimpleFloatProperty(-PI); + assertEquals(-PI, p2.get(), EPSILON); + assertEquals(Float.valueOf(-PI), p2.getValue(), EPSILON); + assertFalse(property.isBound()); + } + + @Test + public void testInvalidationListener() { + attachInvalidationListener(); + property.set(E); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(PI); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + attachChangeListener(); + property.set(E); + changeListener.check(property, 0.0f, E, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(PI); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testLazySet() { + attachInvalidationListener(); + + // set value once + property.set(E); + assertEquals(E, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.set(E); + assertEquals(E, property.get(), EPSILON); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.set(PI); + property.set(-PI); + assertEquals(-PI, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSet() { + attachChangeListener(); + + // set value once + property.set(E); + assertEquals(E, property.get(), EPSILON); + property.check(1); + changeListener.check(property, 0.0f, E, 1); + + // set same value again + property.set(E); + assertEquals(E, property.get(), EPSILON); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(PI); + property.set(-PI); + assertEquals(-PI, property.get(), EPSILON); + property.check(2); + changeListener.check(property, PI, -PI, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListener(); + + // set value once + property.setValue(E); + assertEquals(E, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.setValue(E); + assertEquals(E, property.get(), EPSILON); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(PI); + property.setValue(-PI); + assertEquals(-PI, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSetValue() { + attachChangeListener(); + + // set value once + property.setValue(E); + assertEquals(E, property.get(), EPSILON); + property.check(1); + changeListener.check(property, 0.0f, E, 1); + + // set same value again + property.setValue(E); + assertEquals(E, property.get(), EPSILON); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(PI); + property.setValue(-PI); + assertEquals(-PI, property.get(), EPSILON); + property.check(2); + changeListener.check(property, PI, -PI, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final FloatProperty v = new SimpleFloatProperty(PI); + property.bind(v); + property.set(PI); + } + + @Test + public void testLazyBind() { + attachInvalidationListener(); + final FloatProperty v = new SimpleFloatProperty(PI); + property.reset(); + + property.bind(v); + assertEquals(PI, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(E); + assertEquals(E, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(PI); + v.set(-PI); + assertEquals(-PI, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(PI); + v.set(PI); + assertEquals(PI, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBind() { + attachChangeListener(); + final ObservableFloatValueStub v = new ObservableFloatValueStub(PI); + property.reset(); + + property.bind(v); + assertEquals(PI, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, 0.0f, PI, 1); + + // change binding once + v.set(E); + assertEquals(E, property.get(), EPSILON); + property.check(1); + changeListener.check(property, PI, E, 1); + + // change binding twice without reading + v.set(PI); + v.set(-PI); + assertEquals(-PI, property.get(), EPSILON); + property.check(2); + changeListener.check(property, PI, -PI, 2); + + // change binding twice to same value + v.set(PI); + v.set(PI); + assertEquals(PI, property.get(), EPSILON); + property.check(2); + changeListener.check(property, -PI, PI, 1); + } + + @Test + public void testLazyBindObservableValue() { + final float value1 = (float)Math.PI; + final float value2 = (float)Math.E; + attachInvalidationListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + + property.bind(v); + assertEquals(value1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(value2); + assertEquals(value2, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(value1); + v.set(value2); + assertEquals(value2, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(value1); + v.set(value1); + assertEquals(value1, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + + // set binding to null + v.set(null); + assertEquals(0.0f, property.get(), EPSILON); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBindObservableValue() { + final float value1 = (float)Math.PI; + final float value2 = (float)Math.E; + attachChangeListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + + property.bind(v); + assertEquals(value1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, 0.0f, value1, 1); + + // change binding once + v.set(value2); + assertEquals(value2, property.get(), EPSILON); + property.check(1); + changeListener.check(property, value1, value2, 1); + + // change binding twice without reading + v.set(value1); + v.set(value2); + assertEquals(value2, property.get(), EPSILON); + property.check(2); + changeListener.check(property, value1, value2, 2); + + // change binding twice to same value + v.set(value1); + v.set(value1); + assertEquals(value1, property.get(), EPSILON); + property.check(2); + changeListener.check(property, value2, value1, 1); + + // set binding to null + v.set(null); + assertEquals(0.0f, property.get(), EPSILON); + property.check(1); + changeListener.check(property, value1, 0.0f, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListener(); + final FloatProperty v1 = new SimpleFloatProperty(PI); + final FloatProperty v2 = new SimpleFloatProperty(E); + property.bind(v1); + property.get(); + property.reset(); + invalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(E, property.get(), EPSILON); + assertTrue(property.isBound()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // change old binding + v1.set(-PI); + assertEquals(E, property.get(), EPSILON); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // change new binding + v2.set(-E); + assertEquals(-E, property.get(), EPSILON); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(-E, property.get(), EPSILON); + assertTrue(property.isBound()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListener(); + final FloatProperty v = new SimpleFloatProperty(PI); + property.bind(v); + property.unbind(); + assertEquals(PI, property.get(), EPSILON); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(E); + assertEquals(PI, property.get(), EPSILON); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(-PI); + assertEquals(-PI, property.get(), EPSILON); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testUnbindObservableValue() { + final float value1 = (float)Math.PI; + final float value2 = (float)Math.E; + + attachInvalidationListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + property.bind(v); + property.unbind(); + assertEquals(value1, property.get(), EPSILON); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(value2); + assertEquals(value1, property.get(), EPSILON); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(value2); + assertEquals(value2, property.get(), EPSILON); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final FloatProperty v = new SimpleFloatProperty(PI); + final InvalidationListenerMock listener2 = new InvalidationListenerMock(); + final InvalidationListenerMock listener3 = new InvalidationListenerMock(); + + // setting the property + property.set(PI); + property.addListener(listener2); + listener2.reset(); + property.set(-PI); + listener2.check(property, 1); + + // binding the property + property.bind(v); + v.set(E); + property.addListener(listener3); + v.get(); + listener3.reset(); + v.set(-E); + listener3.check(property, 1); + } + + @Test + public void testToString() { + final float value1 = (float)Math.E; + final float value2 = (float)-Math.PI; + final FloatProperty v = new SimpleFloatProperty(value2); + + property.set(value1); + assertEquals("FloatProperty [value: " + value1 + "]", property.toString()); + + property.bind(v); + assertEquals("FloatProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("FloatProperty [bound, value: " + value2 + "]", property.toString()); + v.set(value1); + assertEquals("FloatProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("FloatProperty [bound, value: " + value1 + "]", property.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final FloatProperty v1 = new FloatPropertyMock(bean, name); + assertEquals("FloatProperty [bean: " + bean.toString() + ", name: My name, value: " + 0.0f + "]", v1.toString()); + v1.set(value1); + assertEquals("FloatProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); + + final FloatProperty v2 = new FloatPropertyMock(bean, NO_NAME_1); + assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + 0.0f + "]", v2.toString()); + v2.set(value1); + assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); + + final FloatProperty v3 = new FloatPropertyMock(bean, NO_NAME_2); + assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + 0.0f + "]", v3.toString()); + v3.set(value1); + assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); + + final FloatProperty v4 = new FloatPropertyMock(NO_BEAN, name); + assertEquals("FloatProperty [name: My name, value: " + 0.0f + "]", v4.toString()); + v4.set(value1); + assertEquals("FloatProperty [name: My name, value: " + value1 + "]", v4.toString()); + } + + private static class FloatPropertyMock extends FloatPropertyBase { + + private final Object bean; + private final String name; + private int counter; + + private FloatPropertyMock() { + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + private FloatPropertyMock(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + + @Override public Object getBean() { return bean; } + + @Override public String getName() { return name; } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/FloatPropertyTest.java 2015-08-31 10:23:22.757217526 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import com.sun.javafx.binding.ErrorLoggingUtiltity; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class FloatPropertyTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final float VALUE_1 = (float)Math.PI; - private static final float VALUE_2 = (float)-Math.E; - private static final float DEFAULT = 0.0f; - private static final float EPSILON = 1e-6f; - - private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); - - @BeforeClass - public static void setUpClass() { - log.start(); - } - - @AfterClass - public static void tearDownClass() { - log.stop(); - } - - @Test - public void testSetValue_Null() { - final FloatProperty p = new SimpleFloatProperty(VALUE_1); - p.setValue(null); - assertEquals(DEFAULT, p.get(), EPSILON); - log.checkFine(NullPointerException.class); - } - - @Test - public void testBindBidirectional() { - final FloatProperty p1 = new SimpleFloatProperty(VALUE_2); - final FloatProperty p2 = new SimpleFloatProperty(VALUE_1); - - p1.bindBidirectional(p2); - assertEquals(VALUE_1, p1.get(), EPSILON); - assertEquals(VALUE_1, p2.get(), EPSILON); - - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get(), EPSILON); - assertEquals(VALUE_2, p2.get(), EPSILON); - - p2.set(VALUE_1); - assertEquals(VALUE_1, p1.get(), EPSILON); - assertEquals(VALUE_1, p2.get(), EPSILON); - - p1.unbindBidirectional(p2); - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get(), EPSILON); - assertEquals(VALUE_1, p2.get(), EPSILON); - - p1.set(VALUE_1); - p2.set(VALUE_2); - assertEquals(VALUE_1, p1.get(), EPSILON); - assertEquals(VALUE_2, p2.get(), EPSILON); - } - - @Test - public void testToString() { - final FloatProperty v0 = new FloatPropertyStub(NO_BEAN, NO_NAME_1); - assertEquals("FloatProperty [value: " + DEFAULT + "]", v0.toString()); - - final FloatProperty v1 = new FloatPropertyStub(NO_BEAN, NO_NAME_2); - assertEquals("FloatProperty [value: " + DEFAULT + "]", v1.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final FloatProperty v2 = new FloatPropertyStub(bean, name); - assertEquals("FloatProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - v2.set(VALUE_1); - assertEquals("FloatProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); - - final FloatProperty v3 = new FloatPropertyStub(bean, NO_NAME_1); - assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - v3.set(VALUE_1); - assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); - - final FloatProperty v4 = new FloatPropertyStub(bean, NO_NAME_2); - assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - v4.set(VALUE_1); - assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); - - final FloatProperty v5 = new FloatPropertyStub(NO_BEAN, name); - assertEquals("FloatProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); - v5.set(VALUE_1); - assertEquals("FloatProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); - } - - @Test - public void testAsObject() { - final FloatProperty valueModel = new SimpleFloatProperty(); - final ObjectProperty exp = valueModel.asObject(); - - assertEquals(0.0f, exp.getValue(), EPSILON); - valueModel.set(-4354.3f); - assertEquals(-4354.3f, exp.getValue(), EPSILON); - valueModel.set(5e11f); - assertEquals(5e11f, exp.getValue(), EPSILON); - - exp.set(1234.0f); - assertEquals(1234.0f, valueModel.floatValue(), EPSILON); - - } - - @Test - public void testObjectToFloat() { - final ObjectProperty valueModel = new SimpleObjectProperty(2f); - final FloatProperty exp = FloatProperty.floatProperty(valueModel); - - assertEquals(2f, exp.floatValue(), EPSILON); - valueModel.set(-4354.3f); - assertEquals(-4354.3f, exp.floatValue(), EPSILON); - valueModel.set(5e11f); - assertEquals(5e11f, exp.floatValue(), EPSILON); - - exp.set(1234.0f); - assertEquals(1234.0f, valueModel.getValue(), EPSILON); - } - - private class FloatPropertyStub extends FloatProperty { - - private final Object bean; - private final String name; - private float value; - - private FloatPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - - @Override - public float get() { - return value; - } - - @Override - public void set(float value) { - this.value = value; - } - - @Override - public void bind(ObservableValue observable) { - fail("Not in use"); - } - - @Override - public void unbind() { - fail("Not in use"); - } - - @Override - public boolean isBound() { - fail("Not in use"); - return false; - } - - @Override - public void addListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void addListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(InvalidationListener listener) { - fail("Not in use"); - } - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/FloatPropertyTest.java 2015-08-31 10:23:22.621217528 -0400 @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.InvalidationListener; +import javafx.beans.property.FloatProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import test.com.sun.javafx.binding.ErrorLoggingUtiltity; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class FloatPropertyTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final float VALUE_1 = (float)Math.PI; + private static final float VALUE_2 = (float)-Math.E; + private static final float DEFAULT = 0.0f; + private static final float EPSILON = 1e-6f; + + private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); + + @BeforeClass + public static void setUpClass() { + log.start(); + } + + @AfterClass + public static void tearDownClass() { + log.stop(); + } + + @Test + public void testSetValue_Null() { + final FloatProperty p = new SimpleFloatProperty(VALUE_1); + p.setValue(null); + assertEquals(DEFAULT, p.get(), EPSILON); + log.checkFine(NullPointerException.class); + } + + @Test + public void testBindBidirectional() { + final FloatProperty p1 = new SimpleFloatProperty(VALUE_2); + final FloatProperty p2 = new SimpleFloatProperty(VALUE_1); + + p1.bindBidirectional(p2); + assertEquals(VALUE_1, p1.get(), EPSILON); + assertEquals(VALUE_1, p2.get(), EPSILON); + + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get(), EPSILON); + assertEquals(VALUE_2, p2.get(), EPSILON); + + p2.set(VALUE_1); + assertEquals(VALUE_1, p1.get(), EPSILON); + assertEquals(VALUE_1, p2.get(), EPSILON); + + p1.unbindBidirectional(p2); + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get(), EPSILON); + assertEquals(VALUE_1, p2.get(), EPSILON); + + p1.set(VALUE_1); + p2.set(VALUE_2); + assertEquals(VALUE_1, p1.get(), EPSILON); + assertEquals(VALUE_2, p2.get(), EPSILON); + } + + @Test + public void testToString() { + final FloatProperty v0 = new FloatPropertyStub(NO_BEAN, NO_NAME_1); + assertEquals("FloatProperty [value: " + DEFAULT + "]", v0.toString()); + + final FloatProperty v1 = new FloatPropertyStub(NO_BEAN, NO_NAME_2); + assertEquals("FloatProperty [value: " + DEFAULT + "]", v1.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final FloatProperty v2 = new FloatPropertyStub(bean, name); + assertEquals("FloatProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + v2.set(VALUE_1); + assertEquals("FloatProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); + + final FloatProperty v3 = new FloatPropertyStub(bean, NO_NAME_1); + assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + v3.set(VALUE_1); + assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); + + final FloatProperty v4 = new FloatPropertyStub(bean, NO_NAME_2); + assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + v4.set(VALUE_1); + assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); + + final FloatProperty v5 = new FloatPropertyStub(NO_BEAN, name); + assertEquals("FloatProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); + v5.set(VALUE_1); + assertEquals("FloatProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); + } + + @Test + public void testAsObject() { + final FloatProperty valueModel = new SimpleFloatProperty(); + final ObjectProperty exp = valueModel.asObject(); + + assertEquals(0.0f, exp.getValue(), EPSILON); + valueModel.set(-4354.3f); + assertEquals(-4354.3f, exp.getValue(), EPSILON); + valueModel.set(5e11f); + assertEquals(5e11f, exp.getValue(), EPSILON); + + exp.set(1234.0f); + assertEquals(1234.0f, valueModel.floatValue(), EPSILON); + + } + + @Test + public void testObjectToFloat() { + final ObjectProperty valueModel = new SimpleObjectProperty(2f); + final FloatProperty exp = FloatProperty.floatProperty(valueModel); + + assertEquals(2f, exp.floatValue(), EPSILON); + valueModel.set(-4354.3f); + assertEquals(-4354.3f, exp.floatValue(), EPSILON); + valueModel.set(5e11f); + assertEquals(5e11f, exp.floatValue(), EPSILON); + + exp.set(1234.0f); + assertEquals(1234.0f, valueModel.getValue(), EPSILON); + } + + private class FloatPropertyStub extends FloatProperty { + + private final Object bean; + private final String name; + private float value; + + private FloatPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + + @Override + public float get() { + return value; + } + + @Override + public void set(float value) { + this.value = value; + } + + @Override + public void bind(ObservableValue observable) { + fail("Not in use"); + } + + @Override + public void unbind() { + fail("Not in use"); + } + + @Override + public boolean isBound() { + fail("Not in use"); + return false; + } + + @Override + public void addListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void addListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(InvalidationListener listener) { + fail("Not in use"); + } + + } +} --- old/modules/base/src/test/java/javafx/beans/property/IntegerPropertyBaseTest.java 2015-08-31 10:23:23.341217520 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,545 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableIntegerValueStub; -import javafx.beans.value.ObservableValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class IntegerPropertyBaseTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final Integer UNDEFINED = Integer.MAX_VALUE; - private static final int VALUE_1 = 42; - private static final int VALUE_2 = 12345; - - private IntegerPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new IntegerPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - } - - private void attachChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - } - - @Test - public void testConstructor() { - final IntegerProperty p1 = new SimpleIntegerProperty(); - assertEquals(0, p1.get()); - assertEquals(Integer.valueOf(0), p1.getValue()); - assertFalse(property.isBound()); - - final IntegerProperty p2 = new SimpleIntegerProperty(-VALUE_1); - assertEquals(-VALUE_1, p2.get()); - assertEquals(Integer.valueOf(-VALUE_1), p2.getValue()); - assertFalse(property.isBound()); - } - - @Test - public void testInvalidationListener() { - attachInvalidationListener(); - property.set(VALUE_2); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - attachChangeListener(); - property.set(VALUE_2); - changeListener.check(property, 0, VALUE_2, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testLazySet() { - attachInvalidationListener(); - - // set value once - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_1); - property.set(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSet() { - attachChangeListener(); - - // set value once - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - changeListener.check(property, 0, VALUE_2, 1); - - // set same value again - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_1); - property.set(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(2); - changeListener.check(property, VALUE_1, -VALUE_1, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListener(); - - // set value once - property.setValue(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.setValue(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_1); - property.setValue(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSetValue() { - attachChangeListener(); - - // set value once - property.setValue(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - changeListener.check(property, 0, VALUE_2, 1); - - // set same value again - property.setValue(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_1); - property.setValue(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(2); - changeListener.check(property, VALUE_1, -VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind() { - attachInvalidationListener(); - final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBind() { - attachChangeListener(); - final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, 0, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - changeListener.check(property, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(2); - changeListener.check(property, VALUE_1, -VALUE_1, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - changeListener.check(property, -VALUE_1, VALUE_1, 1); - } - - @Test - public void testLazyBindObservableValue() { - final int value1 = 42; - final int value2 = -7; - attachInvalidationListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - - property.bind(v); - assertEquals(value1, property.get()); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(value2); - assertEquals(value2, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(value1); - v.set(value2); - assertEquals(value2, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(value1); - v.set(value1); - assertEquals(value1, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set binding to null - v.set(null); - assertEquals(0, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBindObservableValue() { - final int value1 = 42; - final int value2 = -7; - attachChangeListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - - property.bind(v); - assertEquals(value1, property.get()); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, 0, value1, 1); - - // change binding once - v.set(value2); - assertEquals(value2, property.get()); - property.check(1); - changeListener.check(property, value1, value2, 1); - - // change binding twice without reading - v.set(value1); - v.set(value2); - assertEquals(value2, property.get()); - property.check(2); - changeListener.check(property, value1, value2, 2); - - // change binding twice to same value - v.set(value1); - v.set(value1); - assertEquals(value1, property.get()); - property.check(2); - changeListener.check(property, value2, value1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListener(); - final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1); - final IntegerProperty v2 = new SimpleIntegerProperty(VALUE_2); - property.bind(v1); - property.get(); - property.reset(); - invalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get()); - assertTrue(property.isBound()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // change old binding - v1.set(-VALUE_1); - assertEquals(VALUE_2, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // change new binding - v2.set(-VALUE_2); - assertEquals(-VALUE_2, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(-VALUE_2, property.get()); - assertTrue(property.isBound()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListener(); - final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get()); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testUnbindObservableValue() { - final int value1 = 13; - final int value2 = -42; - - attachInvalidationListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - property.bind(v); - property.unbind(); - assertEquals(value1, property.get()); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(value2); - assertEquals(value1, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(value2); - assertEquals(value2, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); - final InvalidationListenerMock listener2 = new InvalidationListenerMock(); - final InvalidationListenerMock listener3 = new InvalidationListenerMock(); - - // setting the property - property.set(VALUE_1); - property.addListener(listener2); - listener2.reset(); - property.set(-VALUE_1); - listener2.check(property, 1); - - // binding the property - property.bind(v); - v.set(VALUE_2); - property.addListener(listener3); - v.get(); - listener3.reset(); - v.set(-VALUE_2); - listener3.check(property, 1); - } - - @Test - public void testToString() { - final int value1 = 1234567890; - final int value2 = -987654321; - final IntegerProperty v = new SimpleIntegerProperty(value2); - - property.set(value1); - assertEquals("IntegerProperty [value: " + value1 + "]", property.toString()); - - property.bind(v); - assertEquals("IntegerProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("IntegerProperty [bound, value: " + value2 + "]", property.toString()); - v.set(value1); - assertEquals("IntegerProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("IntegerProperty [bound, value: " + value1 + "]", property.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final IntegerProperty v1 = new IntegerPropertyMock(bean, name); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + 0 + "]", v1.toString()); - v1.set(value1); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); - - final IntegerProperty v2 = new IntegerPropertyMock(bean, NO_NAME_1); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + 0 + "]", v2.toString()); - v2.set(value1); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); - - final IntegerProperty v3 = new IntegerPropertyMock(bean, NO_NAME_2); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + 0 + "]", v3.toString()); - v3.set(value1); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); - - final IntegerProperty v4 = new IntegerPropertyMock(NO_BEAN, name); - assertEquals("IntegerProperty [name: My name, value: " + 0 + "]", v4.toString()); - v4.set(value1); - assertEquals("IntegerProperty [name: My name, value: " + value1 + "]", v4.toString()); - } - - private static class IntegerPropertyMock extends IntegerPropertyBase { - - private final Object bean; - private final String name; - private int counter; - - private IntegerPropertyMock() { - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - private IntegerPropertyMock(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - - @Override public Object getBean() { return bean; } - - @Override public String getName() { return name; } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/IntegerPropertyBaseTest.java 2015-08-31 10:23:23.209217521 -0400 @@ -0,0 +1,548 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.IntegerPropertyBase; +import javafx.beans.property.SimpleIntegerProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableIntegerValueStub; +import javafx.beans.value.ObservableValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class IntegerPropertyBaseTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final Integer UNDEFINED = Integer.MAX_VALUE; + private static final int VALUE_1 = 42; + private static final int VALUE_2 = 12345; + + private IntegerPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new IntegerPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + } + + private void attachChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + } + + @Test + public void testConstructor() { + final IntegerProperty p1 = new SimpleIntegerProperty(); + assertEquals(0, p1.get()); + assertEquals(Integer.valueOf(0), p1.getValue()); + assertFalse(property.isBound()); + + final IntegerProperty p2 = new SimpleIntegerProperty(-VALUE_1); + assertEquals(-VALUE_1, p2.get()); + assertEquals(Integer.valueOf(-VALUE_1), p2.getValue()); + assertFalse(property.isBound()); + } + + @Test + public void testInvalidationListener() { + attachInvalidationListener(); + property.set(VALUE_2); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + attachChangeListener(); + property.set(VALUE_2); + changeListener.check(property, 0, VALUE_2, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testLazySet() { + attachInvalidationListener(); + + // set value once + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_1); + property.set(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSet() { + attachChangeListener(); + + // set value once + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + changeListener.check(property, 0, VALUE_2, 1); + + // set same value again + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_1); + property.set(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(2); + changeListener.check(property, VALUE_1, -VALUE_1, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListener(); + + // set value once + property.setValue(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.setValue(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_1); + property.setValue(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSetValue() { + attachChangeListener(); + + // set value once + property.setValue(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + changeListener.check(property, 0, VALUE_2, 1); + + // set same value again + property.setValue(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_1); + property.setValue(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(2); + changeListener.check(property, VALUE_1, -VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind() { + attachInvalidationListener(); + final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBind() { + attachChangeListener(); + final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, 0, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + changeListener.check(property, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(2); + changeListener.check(property, VALUE_1, -VALUE_1, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + changeListener.check(property, -VALUE_1, VALUE_1, 1); + } + + @Test + public void testLazyBindObservableValue() { + final int value1 = 42; + final int value2 = -7; + attachInvalidationListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + + property.bind(v); + assertEquals(value1, property.get()); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(value2); + assertEquals(value2, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(value1); + v.set(value2); + assertEquals(value2, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(value1); + v.set(value1); + assertEquals(value1, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set binding to null + v.set(null); + assertEquals(0, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBindObservableValue() { + final int value1 = 42; + final int value2 = -7; + attachChangeListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + + property.bind(v); + assertEquals(value1, property.get()); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, 0, value1, 1); + + // change binding once + v.set(value2); + assertEquals(value2, property.get()); + property.check(1); + changeListener.check(property, value1, value2, 1); + + // change binding twice without reading + v.set(value1); + v.set(value2); + assertEquals(value2, property.get()); + property.check(2); + changeListener.check(property, value1, value2, 2); + + // change binding twice to same value + v.set(value1); + v.set(value1); + assertEquals(value1, property.get()); + property.check(2); + changeListener.check(property, value2, value1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListener(); + final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1); + final IntegerProperty v2 = new SimpleIntegerProperty(VALUE_2); + property.bind(v1); + property.get(); + property.reset(); + invalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get()); + assertTrue(property.isBound()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // change old binding + v1.set(-VALUE_1); + assertEquals(VALUE_2, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // change new binding + v2.set(-VALUE_2); + assertEquals(-VALUE_2, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(-VALUE_2, property.get()); + assertTrue(property.isBound()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListener(); + final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get()); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testUnbindObservableValue() { + final int value1 = 13; + final int value2 = -42; + + attachInvalidationListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + property.bind(v); + property.unbind(); + assertEquals(value1, property.get()); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(value2); + assertEquals(value1, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(value2); + assertEquals(value2, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); + final InvalidationListenerMock listener2 = new InvalidationListenerMock(); + final InvalidationListenerMock listener3 = new InvalidationListenerMock(); + + // setting the property + property.set(VALUE_1); + property.addListener(listener2); + listener2.reset(); + property.set(-VALUE_1); + listener2.check(property, 1); + + // binding the property + property.bind(v); + v.set(VALUE_2); + property.addListener(listener3); + v.get(); + listener3.reset(); + v.set(-VALUE_2); + listener3.check(property, 1); + } + + @Test + public void testToString() { + final int value1 = 1234567890; + final int value2 = -987654321; + final IntegerProperty v = new SimpleIntegerProperty(value2); + + property.set(value1); + assertEquals("IntegerProperty [value: " + value1 + "]", property.toString()); + + property.bind(v); + assertEquals("IntegerProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("IntegerProperty [bound, value: " + value2 + "]", property.toString()); + v.set(value1); + assertEquals("IntegerProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("IntegerProperty [bound, value: " + value1 + "]", property.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final IntegerProperty v1 = new IntegerPropertyMock(bean, name); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + 0 + "]", v1.toString()); + v1.set(value1); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); + + final IntegerProperty v2 = new IntegerPropertyMock(bean, NO_NAME_1); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + 0 + "]", v2.toString()); + v2.set(value1); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); + + final IntegerProperty v3 = new IntegerPropertyMock(bean, NO_NAME_2); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + 0 + "]", v3.toString()); + v3.set(value1); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); + + final IntegerProperty v4 = new IntegerPropertyMock(NO_BEAN, name); + assertEquals("IntegerProperty [name: My name, value: " + 0 + "]", v4.toString()); + v4.set(value1); + assertEquals("IntegerProperty [name: My name, value: " + value1 + "]", v4.toString()); + } + + private static class IntegerPropertyMock extends IntegerPropertyBase { + + private final Object bean; + private final String name; + private int counter; + + private IntegerPropertyMock() { + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + private IntegerPropertyMock(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + + @Override public Object getBean() { return bean; } + + @Override public String getName() { return name; } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/IntegerPropertyTest.java 2015-08-31 10:23:24.109217511 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import com.sun.javafx.binding.ErrorLoggingUtiltity; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class IntegerPropertyTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final int VALUE_1 = 42; - private static final int VALUE_2 = -13; - private static final int DEFAULT = 0; - - private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); - - @BeforeClass - public static void setUpClass() { - log.start(); - } - - @AfterClass - public static void tearDownClass() { - log.stop(); - } - - @Test - public void testSetValue_Null() { - final IntegerProperty p = new SimpleIntegerProperty(VALUE_1); - p.setValue(null); - assertEquals(DEFAULT, p.get()); - log.checkFine(NullPointerException.class); - } - - @Test - public void testBindBidirectional() { - final IntegerProperty p1 = new SimpleIntegerProperty(VALUE_2); - final IntegerProperty p2 = new SimpleIntegerProperty(VALUE_1); - - p1.bindBidirectional(p2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_2, p2.get()); - - p2.set(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.unbindBidirectional(p2); - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_1); - p2.set(VALUE_2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_2, p2.get()); - } - - @Test - public void testToString() { - final IntegerProperty v0 = new IntegerPropertyStub(NO_BEAN, NO_NAME_1); - assertEquals("IntegerProperty [value: " + DEFAULT + "]", v0.toString()); - - final IntegerProperty v1 = new IntegerPropertyStub(NO_BEAN, NO_NAME_2); - assertEquals("IntegerProperty [value: " + DEFAULT + "]", v1.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final IntegerProperty v2 = new IntegerPropertyStub(bean, name); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - v2.set(VALUE_1); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); - - final IntegerProperty v3 = new IntegerPropertyStub(bean, NO_NAME_1); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - v3.set(VALUE_1); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); - - final IntegerProperty v4 = new IntegerPropertyStub(bean, NO_NAME_2); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - v4.set(VALUE_1); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); - - final IntegerProperty v5 = new IntegerPropertyStub(NO_BEAN, name); - assertEquals("IntegerProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); - v5.set(VALUE_1); - assertEquals("IntegerProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); - } - - @Test - public void testAsObject() { - final IntegerProperty valueModel = new SimpleIntegerProperty(); - final ObjectProperty exp = valueModel.asObject(); - - assertEquals(Integer.valueOf(0), exp.getValue()); - valueModel.set(-4354); - assertEquals(Integer.valueOf(-4354), exp.getValue()); - valueModel.set(5); - assertEquals(Integer.valueOf(5), exp.getValue()); - - exp.set(10); - assertEquals(10, valueModel.intValue()); - - } - - @Test - public void testObjectToInteger() { - final ObjectProperty valueModel = new SimpleObjectProperty(2); - final IntegerProperty exp = IntegerProperty.integerProperty(valueModel); - - assertEquals(2, exp.intValue()); - valueModel.set(-4354); - assertEquals(-4354, exp.intValue()); - valueModel.set(5); - assertEquals(5, exp.intValue()); - - exp.set(10); - assertEquals(Integer.valueOf(10), valueModel.getValue()); - - } - - private class IntegerPropertyStub extends IntegerProperty { - - private final Object bean; - private final String name; - private int value; - - private IntegerPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - - @Override - public int get() { - return value; - } - - @Override - public void set(int value) { - this.value = value; - } - - @Override - public void bind(ObservableValue observable) { - fail("Not in use"); - } - - @Override - public void unbind() { - fail("Not in use"); - } - - @Override - public boolean isBound() { - fail("Not in use"); - return false; - } - - @Override - public void addListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void addListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(InvalidationListener listener) { - fail("Not in use"); - } - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/IntegerPropertyTest.java 2015-08-31 10:23:23.897217514 -0400 @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.InvalidationListener; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import test.com.sun.javafx.binding.ErrorLoggingUtiltity; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class IntegerPropertyTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final int VALUE_1 = 42; + private static final int VALUE_2 = -13; + private static final int DEFAULT = 0; + + private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); + + @BeforeClass + public static void setUpClass() { + log.start(); + } + + @AfterClass + public static void tearDownClass() { + log.stop(); + } + + @Test + public void testSetValue_Null() { + final IntegerProperty p = new SimpleIntegerProperty(VALUE_1); + p.setValue(null); + assertEquals(DEFAULT, p.get()); + log.checkFine(NullPointerException.class); + } + + @Test + public void testBindBidirectional() { + final IntegerProperty p1 = new SimpleIntegerProperty(VALUE_2); + final IntegerProperty p2 = new SimpleIntegerProperty(VALUE_1); + + p1.bindBidirectional(p2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_2, p2.get()); + + p2.set(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.unbindBidirectional(p2); + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_1); + p2.set(VALUE_2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_2, p2.get()); + } + + @Test + public void testToString() { + final IntegerProperty v0 = new IntegerPropertyStub(NO_BEAN, NO_NAME_1); + assertEquals("IntegerProperty [value: " + DEFAULT + "]", v0.toString()); + + final IntegerProperty v1 = new IntegerPropertyStub(NO_BEAN, NO_NAME_2); + assertEquals("IntegerProperty [value: " + DEFAULT + "]", v1.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final IntegerProperty v2 = new IntegerPropertyStub(bean, name); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + v2.set(VALUE_1); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); + + final IntegerProperty v3 = new IntegerPropertyStub(bean, NO_NAME_1); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + v3.set(VALUE_1); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); + + final IntegerProperty v4 = new IntegerPropertyStub(bean, NO_NAME_2); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + v4.set(VALUE_1); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); + + final IntegerProperty v5 = new IntegerPropertyStub(NO_BEAN, name); + assertEquals("IntegerProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); + v5.set(VALUE_1); + assertEquals("IntegerProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); + } + + @Test + public void testAsObject() { + final IntegerProperty valueModel = new SimpleIntegerProperty(); + final ObjectProperty exp = valueModel.asObject(); + + assertEquals(Integer.valueOf(0), exp.getValue()); + valueModel.set(-4354); + assertEquals(Integer.valueOf(-4354), exp.getValue()); + valueModel.set(5); + assertEquals(Integer.valueOf(5), exp.getValue()); + + exp.set(10); + assertEquals(10, valueModel.intValue()); + + } + + @Test + public void testObjectToInteger() { + final ObjectProperty valueModel = new SimpleObjectProperty(2); + final IntegerProperty exp = IntegerProperty.integerProperty(valueModel); + + assertEquals(2, exp.intValue()); + valueModel.set(-4354); + assertEquals(-4354, exp.intValue()); + valueModel.set(5); + assertEquals(5, exp.intValue()); + + exp.set(10); + assertEquals(Integer.valueOf(10), valueModel.getValue()); + + } + + private class IntegerPropertyStub extends IntegerProperty { + + private final Object bean; + private final String name; + private int value; + + private IntegerPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + + @Override + public int get() { + return value; + } + + @Override + public void set(int value) { + this.value = value; + } + + @Override + public void bind(ObservableValue observable) { + fail("Not in use"); + } + + @Override + public void unbind() { + fail("Not in use"); + } + + @Override + public boolean isBound() { + fail("Not in use"); + return false; + } + + @Override + public void addListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void addListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(InvalidationListener listener) { + fail("Not in use"); + } + + } +} --- old/modules/base/src/test/java/javafx/beans/property/ListPropertyBaseTest.java 2015-08-31 10:23:24.745217504 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,825 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import java.util.Arrays; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableObjectValueStub; -import javafx.collections.FXCollections; -import javafx.collections.MockListObserver; -import javafx.collections.ObservableList; -import org.junit.Before; -import org.junit.Test; - -import java.util.Collections; -import java.util.List; -import javafx.beans.Observable; -import javafx.collections.Person; - -import static org.junit.Assert.*; - -public class ListPropertyBaseTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final ObservableList UNDEFINED = FXCollections.observableArrayList(); - private static final ObservableList VALUE_1a = FXCollections.observableArrayList(); - private static final ObservableList VALUE_1b = FXCollections.observableArrayList(new Object()); - private static final ObservableList VALUE_2a = FXCollections.observableArrayList(new Object(), new Object()); - private static final ObservableList VALUE_2b = FXCollections.observableArrayList(new Object(), new Object(), new Object()); - private static final List EMPTY_LIST = Collections.emptyList(); - private ListPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock> changeListener; - private MockListObserver listChangeListener; - - @Before - public void setUp() throws Exception { - property = new ListPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock>(UNDEFINED); - listChangeListener = new MockListObserver(); - } - - private void attachInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - } - - private void attachChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - } - - private void attachListChangeListener() { - property.addListener(listChangeListener); - property.get(); - listChangeListener.clear(); - } - - @Test - public void testConstructor() { - final ListProperty p1 = new SimpleListProperty(); - assertEquals(null, p1.get()); - assertEquals(null, p1.getValue()); - assertFalse(property.isBound()); - - final ListProperty p2 = new SimpleListProperty(VALUE_1b); - assertEquals(VALUE_1b, p2.get()); - assertEquals(VALUE_1b, p2.getValue()); - assertFalse(property.isBound()); - } - - @Test - public void testEmptyProperty() { - assertEquals("empty", property.emptyProperty().getName()); - assertEquals(property, property.emptyProperty().getBean()); - assertTrue(property.emptyProperty().get()); - - property.set(VALUE_2a); - assertFalse(property.emptyProperty().get()); - property.set(VALUE_1a); - assertTrue(property.emptyProperty().get()); - } - - @Test - public void testSizeProperty() { - assertEquals("size", property.sizeProperty().getName()); - assertEquals(property, property.sizeProperty().getBean()); - assertEquals(0, property.sizeProperty().get()); - - property.set(VALUE_2a); - assertEquals(2, property.sizeProperty().get()); - property.set(VALUE_1a); - assertEquals(0, property.sizeProperty().get()); - } - - @Test - public void testInvalidationListener() { - attachInvalidationListener(); - property.set(VALUE_2a); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_1a); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - attachChangeListener(); - property.set(VALUE_2a); - changeListener.check(property, null, VALUE_2a, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_1a); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testListChangeListener() { - attachListChangeListener(); - property.set(VALUE_2a); - listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 2); - property.removeListener(listChangeListener); - listChangeListener.clear(); - property.set(VALUE_1a); - listChangeListener.check0(); - } - - @Test - public void testSourceList_Invalidation() { - final ObservableList source1 = FXCollections.observableArrayList(); - final ObservableList source2 = FXCollections.observableArrayList(); - final Object value1 = new Object(); - final Object value2 = new Object(); - - // constructor - property = new ListPropertyBaseTest.ListPropertyMock(source1); - property.reset(); - attachInvalidationListener(); - - // add element - source1.add(value1); - assertEquals(value1, property.get(0)); - property.check(1); - invalidationListener.check(property, 1); - - // replace element - source1.set(0, value2); - assertEquals(value2, property.get(0)); - property.check(1); - invalidationListener.check(property, 1); - - // remove element - source1.remove(0); - assertTrue(property.isEmpty()); - property.check(1); - invalidationListener.check(property, 1); - - // set - property.set(source2); - property.get(); - property.reset(); - invalidationListener.reset(); - - // add element - source2.add(0, value1); - assertEquals(value1, property.get(0)); - property.check(1); - invalidationListener.check(property, 1); - - // replace element - source2.set(0, value2); - assertEquals(value2, property.get(0)); - property.check(1); - invalidationListener.check(property, 1); - - // remove element - source2.remove(0); - assertTrue(property.isEmpty()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testSourceList_Change() { - final ObservableList source1 = FXCollections.observableArrayList(); - final ObservableList source2 = FXCollections.observableArrayList(); - final Object value1 = new Object(); - final Object value2 = new Object(); - - // constructor - property = new ListPropertyBaseTest.ListPropertyMock(source1); - property.reset(); - attachChangeListener(); - - // add element - source1.add(value1); - assertEquals(value1, property.get(0)); - property.check(1); - changeListener.check(property, source1, source1, 1); - - // replace element - source1.set(0, value2); - assertEquals(value2, property.get(0)); - property.check(1); - changeListener.check(property, source1, source1, 1); - - // remove element - source1.remove(0); - assertTrue(property.isEmpty()); - property.check(1); - changeListener.check(property, source1, source1, 1); - - // set - property.set(source2); - property.get(); - property.reset(); - changeListener.reset(); - - // add element - source2.add(0, value1); - assertEquals(value1, property.get(0)); - property.check(1); - changeListener.check(property, source2, source2, 1); - - // replace element - source2.set(0, value2); - assertEquals(value2, property.get(0)); - property.check(1); - changeListener.check(property, source2, source2, 1); - - // remove element - source2.remove(0); - assertTrue(property.isEmpty()); - property.check(1); - changeListener.check(property, source2, source2, 1); - } - - @Test - public void testSourceList_ListChange() { - final ObservableList source1 = FXCollections.observableArrayList(); - final ObservableList source2 = FXCollections.observableArrayList(); - final Object value1 = new Object(); - final Object value2 = new Object(); - - // constructor - property = new ListPropertyBaseTest.ListPropertyMock(source1); - property.reset(); - attachListChangeListener(); - - // add element - source1.add(value1); - assertEquals(value1, property.get(0)); - property.check(1); - listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 1); - listChangeListener.clear(); - - // replace element - source1.set(0, value2); - assertEquals(value2, property.get(0)); - property.check(1); - listChangeListener.check1AddRemove(property, Arrays.asList(value1), 0, 1); - listChangeListener.clear(); - - // remove element - source1.remove(0); - assertTrue(property.isEmpty()); - property.check(1); - listChangeListener.check1AddRemove(property, Arrays.asList(value2), 0, 0); - listChangeListener.clear(); - - // set - property.set(source2); - property.get(); - property.reset(); - listChangeListener.clear(); - - // add element - source2.add(0, value1); - assertEquals(value1, property.get(0)); - property.check(1); - listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 1); - listChangeListener.clear(); - - // replace element - source2.set(0, value2); - assertEquals(value2, property.get(0)); - property.check(1); - listChangeListener.check1AddRemove(property, Arrays.asList(value1), 0, 1); - listChangeListener.clear(); - - // remove element - source2.remove(0); - assertTrue(property.isEmpty()); - property.check(1); - listChangeListener.check1AddRemove(property, Arrays.asList(value2), 0, 0); - listChangeListener.clear(); - } - - @Test - public void testSet_Invalidation() { - attachInvalidationListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_1a); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testSet_Change() { - attachChangeListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, null, VALUE_2a, 1); - - // set same value again - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_1a); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - } - - @Test - public void testSet_ListChange() { - attachListChangeListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 2); - - // set same value again - listChangeListener.clear(); - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - listChangeListener.check0(); - - // set value twice without reading - property.set(VALUE_1a); - listChangeListener.clear(); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - listChangeListener.check1AddRemove(property, VALUE_1a, 0, 1); - } - - @Test - public void testSetValue_Invalidation() { - attachInvalidationListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_1a); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testSetValue_Change() { - attachChangeListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, null, VALUE_2a, 1); - - // set same value again - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_1a); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - } - - @Test - public void testSetValue_ListChange() { - attachListChangeListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 2); - - // set same value again - listChangeListener.clear(); - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - listChangeListener.check0(); - - // set value twice without reading - property.setValue(VALUE_1a); - listChangeListener.clear(); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - listChangeListener.check1AddRemove(property, VALUE_1a, 0, 1); - } - - @Test(expected = RuntimeException.class) - public void testSetBoundValue() { - final ListProperty v = new SimpleListProperty(VALUE_1a); - property.bind(v); - property.set(VALUE_1a); - } - - @Test - public void testBind_Invalidation() { - attachInvalidationListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableArrayList(VALUE_1a)); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(VALUE_1a); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(VALUE_1a); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testBind_Change() { - attachChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableArrayList(VALUE_1a)); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, null, VALUE_1a, 1); - - // change binding once - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, VALUE_1a, VALUE_2a, 1); - - // change binding twice without reading - v.set(VALUE_1a); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - - // change binding twice to same value - v.set(VALUE_1a); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(2); - changeListener.check(property, VALUE_1b, VALUE_1a, 1); - } - - @Test - public void testBind_ListChange() { - attachListChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableArrayList(VALUE_1a)); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 0); - - // change binding once - listChangeListener.clear(); - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - listChangeListener.check1AddRemove(property, VALUE_1a, 0, 2); - - // change binding twice without reading - v.set(VALUE_1a); - listChangeListener.clear(); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - listChangeListener.check1AddRemove(property, VALUE_1a, 0, 1); - - // change binding twice to same value - v.set(VALUE_1a); - listChangeListener.clear(); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(2); - listChangeListener.check0(); - } - - @Test(expected = NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListener(); - final ListProperty v1 = new SimpleListProperty(VALUE_1a); - final ListProperty v2 = new SimpleListProperty(VALUE_2a); - property.bind(v1); - property.get(); - property.reset(); - invalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2a, property.get()); - assertTrue(property.isBound()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // change old binding - v1.set(VALUE_1b); - assertEquals(VALUE_2a, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // change new binding - v2.set(VALUE_2b); - assertEquals(VALUE_2b, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_2b, property.get()); - assertTrue(property.isBound()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListener(); - final ListProperty v = new SimpleListProperty(VALUE_1a); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1a, property.get()); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(VALUE_2a); - assertEquals(VALUE_1a, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final ListProperty v = new SimpleListProperty(VALUE_1a); - final InvalidationListenerMock listener2 = new InvalidationListenerMock(); - final InvalidationListenerMock listener3 = new InvalidationListenerMock(); - - // setting the property - property.set(VALUE_1a); - property.addListener(listener2); - listener2.reset(); - property.set(VALUE_1b); - listener2.check(property, 1); - - // binding the property - property.bind(v); - v.set(VALUE_2a); - property.addListener(listener3); - v.get(); - listener3.reset(); - v.set(VALUE_2b); - listener3.check(property, 1); - } - - @Test - public void testUpdate() { - ObservableList list = createPersonsList(); - ListProperty property = new SimpleListProperty<>(list); - MockListObserver mlo = new MockListObserver<>(); - property.addListener(mlo); - list.get(3).name.set("zero"); // four -> zero - ObservableList expected = FXCollections.observableArrayList( - new Person("one"), new Person("two"), new Person("three"), - new Person("zero"), new Person("five")); - mlo.check1Update(expected, 3, 4); - } - - @Test - public void testPermutation() { - ObservableList list = createPersonsList(); - ListProperty property = new SimpleListProperty<>(list); - MockListObserver mlo = new MockListObserver<>(); - property.addListener(mlo); - FXCollections.sort(list); - ObservableList expected = FXCollections.observableArrayList( - new Person("five"), new Person("four"), new Person("one"), - new Person("three"), new Person("two")); - mlo.check1Permutation(expected, new int[]{2, 4, 3, 1, 0}); - } - - @Test - public void testPermutationUpdate() { - ObservableList list = createPersonsList(); - ObservableList sorted = list.sorted((o1, o2) -> o1.compareTo(o2)); - ListProperty property = new SimpleListProperty<>(sorted); - MockListObserver mlo = new MockListObserver<>(); - property.addListener(mlo); - // add another listener to test Generic code path instead of SingleChange - property.addListener(new MockListObserver<>()); - list.get(3).name.set("zero"); // four -> zero - ObservableList expected = FXCollections.observableArrayList( - new Person("five"), new Person("one"), new Person("three"), - new Person("two"), new Person("zero")); - mlo.checkPermutation(0, expected, 0, expected.size(), new int[]{0, 4, 1, 2, 3}); - mlo.checkUpdate(1, expected, 4, 5); - } - - private ObservableList createPersonsList() { - ObservableList list = FXCollections.observableArrayList( - (Person p) -> new Observable[]{p.name}); - list.addAll( - new Person("one"), new Person("two"), new Person("three"), - new Person("four"), new Person("five")); - return list; - } - - @Test - public void testToString() { - final ObservableList value0 = null; - final ObservableList value1 = FXCollections.observableArrayList(new Object(), new Object()); - final ObservableList value2 = FXCollections.observableArrayList(); - final ListProperty v = new SimpleListProperty(value2); - - property.set(value1); - assertEquals("ListProperty [value: " + value1 + "]", property.toString()); - - property.bind(v); - assertEquals("ListProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("ListProperty [bound, value: " + value2 + "]", property.toString()); - v.set(value1); - assertEquals("ListProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("ListProperty [bound, value: " + value1 + "]", property.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ListProperty v1 = new ListPropertyMock(bean, name); - assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + null + "]", v1.toString()); - v1.set(value1); - assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); - v1.set(value0); - assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - - final ListProperty v2 = new ListPropertyMock(bean, NO_NAME_1); - assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + null + "]", v2.toString()); - v2.set(value1); - assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); - v1.set(value0); - assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - - final ListProperty v3 = new ListPropertyMock(bean, NO_NAME_2); - assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + null + "]", v3.toString()); - v3.set(value1); - assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); - v1.set(value0); - assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - - final ListProperty v4 = new ListPropertyMock(NO_BEAN, name); - assertEquals("ListProperty [name: My name, value: " + null + "]", v4.toString()); - v4.set(value1); - v1.set(value0); - assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - assertEquals("ListProperty [name: My name, value: " + value1 + "]", v4.toString()); - } - - private static class ListPropertyMock extends ListPropertyBase { - - private final Object bean; - private final String name; - private int counter; - - private ListPropertyMock() { - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - private ListPropertyMock(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - private ListPropertyMock(ObservableList initialValue) { - super(initialValue); - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ListPropertyBaseTest.java 2015-08-31 10:23:24.613217506 -0400 @@ -0,0 +1,828 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import java.util.Arrays; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableObjectValueStub; +import javafx.collections.FXCollections; +import test.javafx.collections.MockListObserver; +import javafx.collections.ObservableList; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import java.util.List; +import javafx.beans.Observable; +import javafx.beans.property.ListProperty; +import javafx.beans.property.ListPropertyBase; +import javafx.beans.property.SimpleListProperty; +import test.javafx.collections.Person; + +import static org.junit.Assert.*; + +public class ListPropertyBaseTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final ObservableList UNDEFINED = FXCollections.observableArrayList(); + private static final ObservableList VALUE_1a = FXCollections.observableArrayList(); + private static final ObservableList VALUE_1b = FXCollections.observableArrayList(new Object()); + private static final ObservableList VALUE_2a = FXCollections.observableArrayList(new Object(), new Object()); + private static final ObservableList VALUE_2b = FXCollections.observableArrayList(new Object(), new Object(), new Object()); + private static final List EMPTY_LIST = Collections.emptyList(); + private ListPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock> changeListener; + private MockListObserver listChangeListener; + + @Before + public void setUp() throws Exception { + property = new ListPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock>(UNDEFINED); + listChangeListener = new MockListObserver(); + } + + private void attachInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + } + + private void attachChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + } + + private void attachListChangeListener() { + property.addListener(listChangeListener); + property.get(); + listChangeListener.clear(); + } + + @Test + public void testConstructor() { + final ListProperty p1 = new SimpleListProperty(); + assertEquals(null, p1.get()); + assertEquals(null, p1.getValue()); + assertFalse(property.isBound()); + + final ListProperty p2 = new SimpleListProperty(VALUE_1b); + assertEquals(VALUE_1b, p2.get()); + assertEquals(VALUE_1b, p2.getValue()); + assertFalse(property.isBound()); + } + + @Test + public void testEmptyProperty() { + assertEquals("empty", property.emptyProperty().getName()); + assertEquals(property, property.emptyProperty().getBean()); + assertTrue(property.emptyProperty().get()); + + property.set(VALUE_2a); + assertFalse(property.emptyProperty().get()); + property.set(VALUE_1a); + assertTrue(property.emptyProperty().get()); + } + + @Test + public void testSizeProperty() { + assertEquals("size", property.sizeProperty().getName()); + assertEquals(property, property.sizeProperty().getBean()); + assertEquals(0, property.sizeProperty().get()); + + property.set(VALUE_2a); + assertEquals(2, property.sizeProperty().get()); + property.set(VALUE_1a); + assertEquals(0, property.sizeProperty().get()); + } + + @Test + public void testInvalidationListener() { + attachInvalidationListener(); + property.set(VALUE_2a); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_1a); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + attachChangeListener(); + property.set(VALUE_2a); + changeListener.check(property, null, VALUE_2a, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_1a); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testListChangeListener() { + attachListChangeListener(); + property.set(VALUE_2a); + listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 2); + property.removeListener(listChangeListener); + listChangeListener.clear(); + property.set(VALUE_1a); + listChangeListener.check0(); + } + + @Test + public void testSourceList_Invalidation() { + final ObservableList source1 = FXCollections.observableArrayList(); + final ObservableList source2 = FXCollections.observableArrayList(); + final Object value1 = new Object(); + final Object value2 = new Object(); + + // constructor + property = new ListPropertyBaseTest.ListPropertyMock(source1); + property.reset(); + attachInvalidationListener(); + + // add element + source1.add(value1); + assertEquals(value1, property.get(0)); + property.check(1); + invalidationListener.check(property, 1); + + // replace element + source1.set(0, value2); + assertEquals(value2, property.get(0)); + property.check(1); + invalidationListener.check(property, 1); + + // remove element + source1.remove(0); + assertTrue(property.isEmpty()); + property.check(1); + invalidationListener.check(property, 1); + + // set + property.set(source2); + property.get(); + property.reset(); + invalidationListener.reset(); + + // add element + source2.add(0, value1); + assertEquals(value1, property.get(0)); + property.check(1); + invalidationListener.check(property, 1); + + // replace element + source2.set(0, value2); + assertEquals(value2, property.get(0)); + property.check(1); + invalidationListener.check(property, 1); + + // remove element + source2.remove(0); + assertTrue(property.isEmpty()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testSourceList_Change() { + final ObservableList source1 = FXCollections.observableArrayList(); + final ObservableList source2 = FXCollections.observableArrayList(); + final Object value1 = new Object(); + final Object value2 = new Object(); + + // constructor + property = new ListPropertyBaseTest.ListPropertyMock(source1); + property.reset(); + attachChangeListener(); + + // add element + source1.add(value1); + assertEquals(value1, property.get(0)); + property.check(1); + changeListener.check(property, source1, source1, 1); + + // replace element + source1.set(0, value2); + assertEquals(value2, property.get(0)); + property.check(1); + changeListener.check(property, source1, source1, 1); + + // remove element + source1.remove(0); + assertTrue(property.isEmpty()); + property.check(1); + changeListener.check(property, source1, source1, 1); + + // set + property.set(source2); + property.get(); + property.reset(); + changeListener.reset(); + + // add element + source2.add(0, value1); + assertEquals(value1, property.get(0)); + property.check(1); + changeListener.check(property, source2, source2, 1); + + // replace element + source2.set(0, value2); + assertEquals(value2, property.get(0)); + property.check(1); + changeListener.check(property, source2, source2, 1); + + // remove element + source2.remove(0); + assertTrue(property.isEmpty()); + property.check(1); + changeListener.check(property, source2, source2, 1); + } + + @Test + public void testSourceList_ListChange() { + final ObservableList source1 = FXCollections.observableArrayList(); + final ObservableList source2 = FXCollections.observableArrayList(); + final Object value1 = new Object(); + final Object value2 = new Object(); + + // constructor + property = new ListPropertyBaseTest.ListPropertyMock(source1); + property.reset(); + attachListChangeListener(); + + // add element + source1.add(value1); + assertEquals(value1, property.get(0)); + property.check(1); + listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 1); + listChangeListener.clear(); + + // replace element + source1.set(0, value2); + assertEquals(value2, property.get(0)); + property.check(1); + listChangeListener.check1AddRemove(property, Arrays.asList(value1), 0, 1); + listChangeListener.clear(); + + // remove element + source1.remove(0); + assertTrue(property.isEmpty()); + property.check(1); + listChangeListener.check1AddRemove(property, Arrays.asList(value2), 0, 0); + listChangeListener.clear(); + + // set + property.set(source2); + property.get(); + property.reset(); + listChangeListener.clear(); + + // add element + source2.add(0, value1); + assertEquals(value1, property.get(0)); + property.check(1); + listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 1); + listChangeListener.clear(); + + // replace element + source2.set(0, value2); + assertEquals(value2, property.get(0)); + property.check(1); + listChangeListener.check1AddRemove(property, Arrays.asList(value1), 0, 1); + listChangeListener.clear(); + + // remove element + source2.remove(0); + assertTrue(property.isEmpty()); + property.check(1); + listChangeListener.check1AddRemove(property, Arrays.asList(value2), 0, 0); + listChangeListener.clear(); + } + + @Test + public void testSet_Invalidation() { + attachInvalidationListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_1a); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testSet_Change() { + attachChangeListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, null, VALUE_2a, 1); + + // set same value again + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_1a); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + } + + @Test + public void testSet_ListChange() { + attachListChangeListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 2); + + // set same value again + listChangeListener.clear(); + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + listChangeListener.check0(); + + // set value twice without reading + property.set(VALUE_1a); + listChangeListener.clear(); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + listChangeListener.check1AddRemove(property, VALUE_1a, 0, 1); + } + + @Test + public void testSetValue_Invalidation() { + attachInvalidationListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_1a); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testSetValue_Change() { + attachChangeListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, null, VALUE_2a, 1); + + // set same value again + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_1a); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + } + + @Test + public void testSetValue_ListChange() { + attachListChangeListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 2); + + // set same value again + listChangeListener.clear(); + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + listChangeListener.check0(); + + // set value twice without reading + property.setValue(VALUE_1a); + listChangeListener.clear(); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + listChangeListener.check1AddRemove(property, VALUE_1a, 0, 1); + } + + @Test(expected = RuntimeException.class) + public void testSetBoundValue() { + final ListProperty v = new SimpleListProperty(VALUE_1a); + property.bind(v); + property.set(VALUE_1a); + } + + @Test + public void testBind_Invalidation() { + attachInvalidationListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableArrayList(VALUE_1a)); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(VALUE_1a); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(VALUE_1a); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testBind_Change() { + attachChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableArrayList(VALUE_1a)); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, null, VALUE_1a, 1); + + // change binding once + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, VALUE_1a, VALUE_2a, 1); + + // change binding twice without reading + v.set(VALUE_1a); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + + // change binding twice to same value + v.set(VALUE_1a); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(2); + changeListener.check(property, VALUE_1b, VALUE_1a, 1); + } + + @Test + public void testBind_ListChange() { + attachListChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableArrayList(VALUE_1a)); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + listChangeListener.check1AddRemove(property, EMPTY_LIST, 0, 0); + + // change binding once + listChangeListener.clear(); + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + listChangeListener.check1AddRemove(property, VALUE_1a, 0, 2); + + // change binding twice without reading + v.set(VALUE_1a); + listChangeListener.clear(); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + listChangeListener.check1AddRemove(property, VALUE_1a, 0, 1); + + // change binding twice to same value + v.set(VALUE_1a); + listChangeListener.clear(); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(2); + listChangeListener.check0(); + } + + @Test(expected = NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListener(); + final ListProperty v1 = new SimpleListProperty(VALUE_1a); + final ListProperty v2 = new SimpleListProperty(VALUE_2a); + property.bind(v1); + property.get(); + property.reset(); + invalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2a, property.get()); + assertTrue(property.isBound()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // change old binding + v1.set(VALUE_1b); + assertEquals(VALUE_2a, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // change new binding + v2.set(VALUE_2b); + assertEquals(VALUE_2b, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_2b, property.get()); + assertTrue(property.isBound()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListener(); + final ListProperty v = new SimpleListProperty(VALUE_1a); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1a, property.get()); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(VALUE_2a); + assertEquals(VALUE_1a, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final ListProperty v = new SimpleListProperty(VALUE_1a); + final InvalidationListenerMock listener2 = new InvalidationListenerMock(); + final InvalidationListenerMock listener3 = new InvalidationListenerMock(); + + // setting the property + property.set(VALUE_1a); + property.addListener(listener2); + listener2.reset(); + property.set(VALUE_1b); + listener2.check(property, 1); + + // binding the property + property.bind(v); + v.set(VALUE_2a); + property.addListener(listener3); + v.get(); + listener3.reset(); + v.set(VALUE_2b); + listener3.check(property, 1); + } + + @Test + public void testUpdate() { + ObservableList list = createPersonsList(); + ListProperty property = new SimpleListProperty<>(list); + MockListObserver mlo = new MockListObserver<>(); + property.addListener(mlo); + list.get(3).name.set("zero"); // four -> zero + ObservableList expected = FXCollections.observableArrayList( + new Person("one"), new Person("two"), new Person("three"), + new Person("zero"), new Person("five")); + mlo.check1Update(expected, 3, 4); + } + + @Test + public void testPermutation() { + ObservableList list = createPersonsList(); + ListProperty property = new SimpleListProperty<>(list); + MockListObserver mlo = new MockListObserver<>(); + property.addListener(mlo); + FXCollections.sort(list); + ObservableList expected = FXCollections.observableArrayList( + new Person("five"), new Person("four"), new Person("one"), + new Person("three"), new Person("two")); + mlo.check1Permutation(expected, new int[]{2, 4, 3, 1, 0}); + } + + @Test + public void testPermutationUpdate() { + ObservableList list = createPersonsList(); + ObservableList sorted = list.sorted((o1, o2) -> o1.compareTo(o2)); + ListProperty property = new SimpleListProperty<>(sorted); + MockListObserver mlo = new MockListObserver<>(); + property.addListener(mlo); + // add another listener to test Generic code path instead of SingleChange + property.addListener(new MockListObserver<>()); + list.get(3).name.set("zero"); // four -> zero + ObservableList expected = FXCollections.observableArrayList( + new Person("five"), new Person("one"), new Person("three"), + new Person("two"), new Person("zero")); + mlo.checkPermutation(0, expected, 0, expected.size(), new int[]{0, 4, 1, 2, 3}); + mlo.checkUpdate(1, expected, 4, 5); + } + + private ObservableList createPersonsList() { + ObservableList list = FXCollections.observableArrayList( + (Person p) -> new Observable[]{p.name}); + list.addAll( + new Person("one"), new Person("two"), new Person("three"), + new Person("four"), new Person("five")); + return list; + } + + @Test + public void testToString() { + final ObservableList value0 = null; + final ObservableList value1 = FXCollections.observableArrayList(new Object(), new Object()); + final ObservableList value2 = FXCollections.observableArrayList(); + final ListProperty v = new SimpleListProperty(value2); + + property.set(value1); + assertEquals("ListProperty [value: " + value1 + "]", property.toString()); + + property.bind(v); + assertEquals("ListProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("ListProperty [bound, value: " + value2 + "]", property.toString()); + v.set(value1); + assertEquals("ListProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("ListProperty [bound, value: " + value1 + "]", property.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ListProperty v1 = new ListPropertyMock(bean, name); + assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + null + "]", v1.toString()); + v1.set(value1); + assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); + v1.set(value0); + assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + + final ListProperty v2 = new ListPropertyMock(bean, NO_NAME_1); + assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + null + "]", v2.toString()); + v2.set(value1); + assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); + v1.set(value0); + assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + + final ListProperty v3 = new ListPropertyMock(bean, NO_NAME_2); + assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + null + "]", v3.toString()); + v3.set(value1); + assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); + v1.set(value0); + assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + + final ListProperty v4 = new ListPropertyMock(NO_BEAN, name); + assertEquals("ListProperty [name: My name, value: " + null + "]", v4.toString()); + v4.set(value1); + v1.set(value0); + assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + assertEquals("ListProperty [name: My name, value: " + value1 + "]", v4.toString()); + } + + private static class ListPropertyMock extends ListPropertyBase { + + private final Object bean; + private final String name; + private int counter; + + private ListPropertyMock() { + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + private ListPropertyMock(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + private ListPropertyMock(ObservableList initialValue) { + super(initialValue); + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/ListPropertyTest.java 2015-08-31 10:23:25.421217496 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -public class ListPropertyTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final ObservableList VALUE_1 = FXCollections.emptyObservableList(); - private static final ObservableList VALUE_2 = FXCollections.singletonObservableList(new Object()); - private static final Object DEFAULT = null; - - @Test - public void testBindBidirectional() { - final ListProperty p1 = new SimpleListProperty(VALUE_2); - final ListProperty p2 = new SimpleListProperty(VALUE_1); - - p1.bindBidirectional(p2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_2, p2.get()); - - p2.set(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.unbindBidirectional(p2); - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_1); - p2.set(VALUE_2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_2, p2.get()); - } - - @Test - public void testToString() { - final ListProperty v0 = new ListPropertyStub(NO_BEAN, NO_NAME_1); - assertEquals("ListProperty [value: " + DEFAULT + "]", v0.toString()); - - final ListProperty v1 = new ListPropertyStub(NO_BEAN, NO_NAME_2); - assertEquals("ListProperty [value: " + DEFAULT + "]", v1.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ListProperty v2 = new ListPropertyStub(bean, name); - assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - v2.set(VALUE_1); - assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); - - final ListProperty v3 = new ListPropertyStub(bean, NO_NAME_1); - assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - v3.set(VALUE_1); - assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); - - final ListProperty v4 = new ListPropertyStub(bean, NO_NAME_2); - assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - v4.set(VALUE_1); - assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); - - final ListProperty v5 = new ListPropertyStub(NO_BEAN, name); - assertEquals("ListProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); - v5.set(VALUE_1); - assertEquals("ListProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); - } - - private class ListPropertyStub extends ListProperty { - - private final Object bean; - private final String name; - private ObservableList value; - - private ListPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - - @Override - public ObservableList get() { - return value; - } - - @Override - public void set(ObservableList value) { - this.value = value; - } - - @Override - public void bind(ObservableValue> observable) { - fail("Not in use"); - } - - @Override - public void unbind() { - fail("Not in use"); - } - - @Override - public boolean isBound() { - fail("Not in use"); - return false; - } - - @Override - public void addListener(ChangeListener> listener) { - fail("Not in use"); - } - - @Override - public void removeListener(ChangeListener> listener) { - fail("Not in use"); - } - - @Override - public void addListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void addListener(ListChangeListener listChangeListener) { - fail("Not in use"); - } - - @Override - public void removeListener(ListChangeListener listChangeListener) { - fail("Not in use"); - } - - @Override - public ReadOnlyIntegerProperty sizeProperty() { - fail("Not in use"); - return null; - } - - @Override - public ReadOnlyBooleanProperty emptyProperty() { - fail("Not in use"); - return null; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ListPropertyTest.java 2015-08-31 10:23:25.213217499 -0400 @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.InvalidationListener; +import javafx.beans.property.ListProperty; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class ListPropertyTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final ObservableList VALUE_1 = FXCollections.emptyObservableList(); + private static final ObservableList VALUE_2 = FXCollections.singletonObservableList(new Object()); + private static final Object DEFAULT = null; + + @Test + public void testBindBidirectional() { + final ListProperty p1 = new SimpleListProperty(VALUE_2); + final ListProperty p2 = new SimpleListProperty(VALUE_1); + + p1.bindBidirectional(p2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_2, p2.get()); + + p2.set(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.unbindBidirectional(p2); + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_1); + p2.set(VALUE_2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_2, p2.get()); + } + + @Test + public void testToString() { + final ListProperty v0 = new ListPropertyStub(NO_BEAN, NO_NAME_1); + assertEquals("ListProperty [value: " + DEFAULT + "]", v0.toString()); + + final ListProperty v1 = new ListPropertyStub(NO_BEAN, NO_NAME_2); + assertEquals("ListProperty [value: " + DEFAULT + "]", v1.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ListProperty v2 = new ListPropertyStub(bean, name); + assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + v2.set(VALUE_1); + assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); + + final ListProperty v3 = new ListPropertyStub(bean, NO_NAME_1); + assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + v3.set(VALUE_1); + assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); + + final ListProperty v4 = new ListPropertyStub(bean, NO_NAME_2); + assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + v4.set(VALUE_1); + assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); + + final ListProperty v5 = new ListPropertyStub(NO_BEAN, name); + assertEquals("ListProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); + v5.set(VALUE_1); + assertEquals("ListProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); + } + + private class ListPropertyStub extends ListProperty { + + private final Object bean; + private final String name; + private ObservableList value; + + private ListPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + + @Override + public ObservableList get() { + return value; + } + + @Override + public void set(ObservableList value) { + this.value = value; + } + + @Override + public void bind(ObservableValue> observable) { + fail("Not in use"); + } + + @Override + public void unbind() { + fail("Not in use"); + } + + @Override + public boolean isBound() { + fail("Not in use"); + return false; + } + + @Override + public void addListener(ChangeListener> listener) { + fail("Not in use"); + } + + @Override + public void removeListener(ChangeListener> listener) { + fail("Not in use"); + } + + @Override + public void addListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void addListener(ListChangeListener listChangeListener) { + fail("Not in use"); + } + + @Override + public void removeListener(ListChangeListener listChangeListener) { + fail("Not in use"); + } + + @Override + public ReadOnlyIntegerProperty sizeProperty() { + fail("Not in use"); + return null; + } + + @Override + public ReadOnlyBooleanProperty emptyProperty() { + fail("Not in use"); + return null; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/LongPropertyBaseTest.java 2015-08-31 10:23:26.101217489 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,545 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableLongValueStub; -import javafx.beans.value.ObservableValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class LongPropertyBaseTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final Long UNDEFINED = Long.MAX_VALUE; - private static final long VALUE_1 = 42; - private static final long VALUE_2 = 12345; - - private LongPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new LongPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - } - - private void attachChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - } - - @Test - public void testConstructor() { - final LongProperty p1 = new SimpleLongProperty(); - assertEquals(0, p1.get()); - assertEquals(Long.valueOf(0), p1.getValue()); - assertFalse(property.isBound()); - - final LongProperty p2 = new SimpleLongProperty(-VALUE_1); - assertEquals(-VALUE_1, p2.get()); - assertEquals(Long.valueOf(-VALUE_1), p2.getValue()); - assertFalse(property.isBound()); - } - - @Test - public void testInvalidationListener() { - attachInvalidationListener(); - property.set(VALUE_2); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - attachChangeListener(); - property.set(VALUE_2); - changeListener.check(property, 0L, VALUE_2, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testLazySet() { - attachInvalidationListener(); - - // set value once - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_1); - property.set(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSet() { - attachChangeListener(); - - // set value once - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - changeListener.check(property, 0L, VALUE_2, 1); - - // set same value again - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_1); - property.set(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(2); - changeListener.check(property, VALUE_1, -VALUE_1, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListener(); - - // set value once - property.setValue(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.setValue(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_1); - property.setValue(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSetValue() { - attachChangeListener(); - - // set value once - property.setValue(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - changeListener.check(property, 0L, VALUE_2, 1); - - // set same value again - property.setValue(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_1); - property.setValue(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(2); - changeListener.check(property, VALUE_1, -VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final LongProperty v = new SimpleLongProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind() { - attachInvalidationListener(); - final ObservableLongValueStub v = new ObservableLongValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBind() { - attachChangeListener(); - final ObservableLongValueStub v = new ObservableLongValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, 0L, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - changeListener.check(property, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - property.check(2); - changeListener.check(property, VALUE_1, -VALUE_1, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - changeListener.check(property, -VALUE_1, VALUE_1, 1); - } - - @Test - public void testLazyBindObservableValue() { - final long value1 = 9876543212345L; - final long value2 = -123456789098765L; - attachInvalidationListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - - property.bind(v); - assertEquals(value1, property.get()); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(value2); - assertEquals(value2, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(value1); - v.set(value2); - assertEquals(value2, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(value1); - v.set(value1); - assertEquals(value1, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set binding to null - v.set(null); - assertEquals(0L, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBindObservableValue() { - final long value1 = 9876543212345L; - final long value2 = -123456789098765L; - attachChangeListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - - property.bind(v); - assertEquals(value1, property.get()); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, 0L, value1, 1); - - // change binding once - v.set(value2); - assertEquals(value2, property.get()); - property.check(1); - changeListener.check(property, value1, value2, 1); - - // change binding twice without reading - v.set(value1); - v.set(value2); - assertEquals(value2, property.get()); - property.check(2); - changeListener.check(property, value1, value2, 2); - - // change binding twice to same value - v.set(value1); - v.set(value1); - assertEquals(value1, property.get()); - property.check(2); - changeListener.check(property, value2, value1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListener(); - final LongProperty v1 = new SimpleLongProperty(VALUE_1); - final LongProperty v2 = new SimpleLongProperty(VALUE_2); - property.bind(v1); - property.get(); - property.reset(); - invalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get()); - assertTrue(property.isBound()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // change old binding - v1.set(-VALUE_1); - assertEquals(VALUE_2, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // change new binding - v2.set(-VALUE_2); - assertEquals(-VALUE_2, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(-VALUE_2, property.get()); - assertTrue(property.isBound()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListener(); - final LongProperty v = new SimpleLongProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get()); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(-VALUE_1); - assertEquals(-VALUE_1, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testUnbindObservableValue() { - final long value1 = 9876543212345L; - final long value2 = -123456789098765L; - - attachInvalidationListener(); - final ObservableValueStub v = new ObservableValueStub(value1); - property.bind(v); - property.unbind(); - assertEquals(value1, property.get()); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(value2); - assertEquals(value1, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(value2); - assertEquals(value2, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final LongProperty v = new SimpleLongProperty(VALUE_1); - final InvalidationListenerMock listener2 = new InvalidationListenerMock(); - final InvalidationListenerMock listener3 = new InvalidationListenerMock(); - - // setting the property - property.set(VALUE_1); - property.addListener(listener2); - listener2.reset(); - property.set(-VALUE_1); - listener2.check(property, 1); - - // binding the property - property.bind(v); - v.set(VALUE_2); - property.addListener(listener3); - v.get(); - listener3.reset(); - v.set(-VALUE_2); - listener3.check(property, 1); - } - - @Test - public void testToString() { - final long value1 = 1234567890987654321L; - final long value2 = -987654321012345678L; - final LongProperty v = new SimpleLongProperty(value2); - - property.set(value1); - assertEquals("LongProperty [value: " + value1 + "]", property.toString()); - - property.bind(v); - assertEquals("LongProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("LongProperty [bound, value: " + value2 + "]", property.toString()); - v.set(value1); - assertEquals("LongProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("LongProperty [bound, value: " + value1 + "]", property.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final LongProperty v1 = new LongPropertyMock(bean, name); - assertEquals("LongProperty [bean: " + bean.toString() + ", name: My name, value: " + 0L + "]", v1.toString()); - v1.set(value1); - assertEquals("LongProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); - - final LongProperty v2 = new LongPropertyMock(bean, NO_NAME_1); - assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + 0L + "]", v2.toString()); - v2.set(value1); - assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); - - final LongProperty v3 = new LongPropertyMock(bean, NO_NAME_2); - assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + 0L + "]", v3.toString()); - v3.set(value1); - assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); - - final LongProperty v4 = new LongPropertyMock(NO_BEAN, name); - assertEquals("LongProperty [name: My name, value: " + 0L + "]", v4.toString()); - v4.set(value1); - assertEquals("LongProperty [name: My name, value: " + value1 + "]", v4.toString()); - } - - private static class LongPropertyMock extends LongPropertyBase { - - private final Object bean; - private final String name; - private int counter; - - private LongPropertyMock() { - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - private LongPropertyMock(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - - @Override public Object getBean() { return bean; } - - @Override public String getName() { return name; } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/LongPropertyBaseTest.java 2015-08-31 10:23:25.965217490 -0400 @@ -0,0 +1,548 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.LongProperty; +import javafx.beans.property.LongPropertyBase; +import javafx.beans.property.SimpleLongProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableLongValueStub; +import javafx.beans.value.ObservableValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class LongPropertyBaseTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final Long UNDEFINED = Long.MAX_VALUE; + private static final long VALUE_1 = 42; + private static final long VALUE_2 = 12345; + + private LongPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new LongPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + } + + private void attachChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + } + + @Test + public void testConstructor() { + final LongProperty p1 = new SimpleLongProperty(); + assertEquals(0, p1.get()); + assertEquals(Long.valueOf(0), p1.getValue()); + assertFalse(property.isBound()); + + final LongProperty p2 = new SimpleLongProperty(-VALUE_1); + assertEquals(-VALUE_1, p2.get()); + assertEquals(Long.valueOf(-VALUE_1), p2.getValue()); + assertFalse(property.isBound()); + } + + @Test + public void testInvalidationListener() { + attachInvalidationListener(); + property.set(VALUE_2); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + attachChangeListener(); + property.set(VALUE_2); + changeListener.check(property, 0L, VALUE_2, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testLazySet() { + attachInvalidationListener(); + + // set value once + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_1); + property.set(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSet() { + attachChangeListener(); + + // set value once + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + changeListener.check(property, 0L, VALUE_2, 1); + + // set same value again + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_1); + property.set(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(2); + changeListener.check(property, VALUE_1, -VALUE_1, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListener(); + + // set value once + property.setValue(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.setValue(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_1); + property.setValue(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSetValue() { + attachChangeListener(); + + // set value once + property.setValue(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + changeListener.check(property, 0L, VALUE_2, 1); + + // set same value again + property.setValue(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_1); + property.setValue(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(2); + changeListener.check(property, VALUE_1, -VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final LongProperty v = new SimpleLongProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind() { + attachInvalidationListener(); + final ObservableLongValueStub v = new ObservableLongValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBind() { + attachChangeListener(); + final ObservableLongValueStub v = new ObservableLongValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, 0L, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + changeListener.check(property, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + property.check(2); + changeListener.check(property, VALUE_1, -VALUE_1, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + changeListener.check(property, -VALUE_1, VALUE_1, 1); + } + + @Test + public void testLazyBindObservableValue() { + final long value1 = 9876543212345L; + final long value2 = -123456789098765L; + attachInvalidationListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + + property.bind(v); + assertEquals(value1, property.get()); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(value2); + assertEquals(value2, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(value1); + v.set(value2); + assertEquals(value2, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(value1); + v.set(value1); + assertEquals(value1, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set binding to null + v.set(null); + assertEquals(0L, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBindObservableValue() { + final long value1 = 9876543212345L; + final long value2 = -123456789098765L; + attachChangeListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + + property.bind(v); + assertEquals(value1, property.get()); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, 0L, value1, 1); + + // change binding once + v.set(value2); + assertEquals(value2, property.get()); + property.check(1); + changeListener.check(property, value1, value2, 1); + + // change binding twice without reading + v.set(value1); + v.set(value2); + assertEquals(value2, property.get()); + property.check(2); + changeListener.check(property, value1, value2, 2); + + // change binding twice to same value + v.set(value1); + v.set(value1); + assertEquals(value1, property.get()); + property.check(2); + changeListener.check(property, value2, value1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListener(); + final LongProperty v1 = new SimpleLongProperty(VALUE_1); + final LongProperty v2 = new SimpleLongProperty(VALUE_2); + property.bind(v1); + property.get(); + property.reset(); + invalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get()); + assertTrue(property.isBound()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // change old binding + v1.set(-VALUE_1); + assertEquals(VALUE_2, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // change new binding + v2.set(-VALUE_2); + assertEquals(-VALUE_2, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(-VALUE_2, property.get()); + assertTrue(property.isBound()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListener(); + final LongProperty v = new SimpleLongProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get()); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(-VALUE_1); + assertEquals(-VALUE_1, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testUnbindObservableValue() { + final long value1 = 9876543212345L; + final long value2 = -123456789098765L; + + attachInvalidationListener(); + final ObservableValueStub v = new ObservableValueStub(value1); + property.bind(v); + property.unbind(); + assertEquals(value1, property.get()); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(value2); + assertEquals(value1, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(value2); + assertEquals(value2, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final LongProperty v = new SimpleLongProperty(VALUE_1); + final InvalidationListenerMock listener2 = new InvalidationListenerMock(); + final InvalidationListenerMock listener3 = new InvalidationListenerMock(); + + // setting the property + property.set(VALUE_1); + property.addListener(listener2); + listener2.reset(); + property.set(-VALUE_1); + listener2.check(property, 1); + + // binding the property + property.bind(v); + v.set(VALUE_2); + property.addListener(listener3); + v.get(); + listener3.reset(); + v.set(-VALUE_2); + listener3.check(property, 1); + } + + @Test + public void testToString() { + final long value1 = 1234567890987654321L; + final long value2 = -987654321012345678L; + final LongProperty v = new SimpleLongProperty(value2); + + property.set(value1); + assertEquals("LongProperty [value: " + value1 + "]", property.toString()); + + property.bind(v); + assertEquals("LongProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("LongProperty [bound, value: " + value2 + "]", property.toString()); + v.set(value1); + assertEquals("LongProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("LongProperty [bound, value: " + value1 + "]", property.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final LongProperty v1 = new LongPropertyMock(bean, name); + assertEquals("LongProperty [bean: " + bean.toString() + ", name: My name, value: " + 0L + "]", v1.toString()); + v1.set(value1); + assertEquals("LongProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); + + final LongProperty v2 = new LongPropertyMock(bean, NO_NAME_1); + assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + 0L + "]", v2.toString()); + v2.set(value1); + assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); + + final LongProperty v3 = new LongPropertyMock(bean, NO_NAME_2); + assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + 0L + "]", v3.toString()); + v3.set(value1); + assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); + + final LongProperty v4 = new LongPropertyMock(NO_BEAN, name); + assertEquals("LongProperty [name: My name, value: " + 0L + "]", v4.toString()); + v4.set(value1); + assertEquals("LongProperty [name: My name, value: " + value1 + "]", v4.toString()); + } + + private static class LongPropertyMock extends LongPropertyBase { + + private final Object bean; + private final String name; + private int counter; + + private LongPropertyMock() { + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + private LongPropertyMock(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + + @Override public Object getBean() { return bean; } + + @Override public String getName() { return name; } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/LongPropertyTest.java 2015-08-31 10:23:26.893217480 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,225 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import com.sun.javafx.binding.ErrorLoggingUtiltity; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class LongPropertyTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final long VALUE_1 = 1234567890L; - private static final long VALUE_2 = -987654321L; - private static final long DEFAULT = 0L; - - private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); - - @BeforeClass - public static void setUpClass() { - log.start(); - } - - @AfterClass - public static void tearDownClass() { - log.stop(); - } - - @Test - public void testSetValue_Null() { - final LongProperty p = new SimpleLongProperty(VALUE_1); - p.setValue(null); - assertEquals(DEFAULT, p.get()); - log.checkFine(NullPointerException.class); - } - - @Test - public void testBindBidirectional() { - final LongProperty p1 = new SimpleLongProperty(VALUE_2); - final LongProperty p2 = new SimpleLongProperty(VALUE_1); - - p1.bindBidirectional(p2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_2, p2.get()); - - p2.set(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.unbindBidirectional(p2); - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_1); - p2.set(VALUE_2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_2, p2.get()); - } - - @Test - public void testToString() { - final LongProperty v0 = new LongPropertyStub(NO_BEAN, NO_NAME_1); - assertEquals("LongProperty [value: " + DEFAULT + "]", v0.toString()); - - final LongProperty v1 = new LongPropertyStub(NO_BEAN, NO_NAME_2); - assertEquals("LongProperty [value: " + DEFAULT + "]", v1.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final LongProperty v2 = new LongPropertyStub(bean, name); - assertEquals("LongProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - v2.set(VALUE_1); - assertEquals("LongProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); - - final LongProperty v3 = new LongPropertyStub(bean, NO_NAME_1); - assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - v3.set(VALUE_1); - assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); - - final LongProperty v4 = new LongPropertyStub(bean, NO_NAME_2); - assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - v4.set(VALUE_1); - assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); - - final LongProperty v5 = new LongPropertyStub(NO_BEAN, name); - assertEquals("LongProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); - v5.set(VALUE_1); - assertEquals("LongProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); - } - - @Test - public void testAsObject() { - final LongProperty valueModel = new SimpleLongProperty(); - final ObjectProperty exp = valueModel.asObject(); - - assertEquals(Long.valueOf(0L), exp.getValue()); - valueModel.set(-4354L); - assertEquals(Long.valueOf(-4354L), exp.getValue()); - valueModel.set(5L); - assertEquals(Long.valueOf(5L), exp.getValue()); - - exp.set(10L); - assertEquals(10L, valueModel.longValue()); - } - - @Test - public void testObjectToLong() { - final ObjectProperty valueModel = new SimpleObjectProperty(2L); - final LongProperty exp = LongProperty.longProperty(valueModel); - - assertEquals(2L, exp.longValue()); - valueModel.set(-4354L); - assertEquals(-4354L, exp.longValue()); - valueModel.set(5L); - assertEquals(5L, exp.longValue()); - - exp.set(10L); - assertEquals(Long.valueOf(10L), valueModel.getValue()); - } - - private class LongPropertyStub extends LongProperty { - - private final Object bean; - private final String name; - private long value; - - private LongPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - - @Override - public long get() { - return value; - } - - @Override - public void set(long value) { - this.value = value; - } - - @Override - public void bind(ObservableValue observable) { - fail("Not in use"); - } - - @Override - public void unbind() { - fail("Not in use"); - } - - @Override - public boolean isBound() { - fail("Not in use"); - return false; - } - - @Override - public void addListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void addListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(InvalidationListener listener) { - fail("Not in use"); - } - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/LongPropertyTest.java 2015-08-31 10:23:26.681217482 -0400 @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.InvalidationListener; +import javafx.beans.property.LongProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import test.com.sun.javafx.binding.ErrorLoggingUtiltity; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class LongPropertyTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final long VALUE_1 = 1234567890L; + private static final long VALUE_2 = -987654321L; + private static final long DEFAULT = 0L; + + private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); + + @BeforeClass + public static void setUpClass() { + log.start(); + } + + @AfterClass + public static void tearDownClass() { + log.stop(); + } + + @Test + public void testSetValue_Null() { + final LongProperty p = new SimpleLongProperty(VALUE_1); + p.setValue(null); + assertEquals(DEFAULT, p.get()); + log.checkFine(NullPointerException.class); + } + + @Test + public void testBindBidirectional() { + final LongProperty p1 = new SimpleLongProperty(VALUE_2); + final LongProperty p2 = new SimpleLongProperty(VALUE_1); + + p1.bindBidirectional(p2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_2, p2.get()); + + p2.set(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.unbindBidirectional(p2); + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_1); + p2.set(VALUE_2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_2, p2.get()); + } + + @Test + public void testToString() { + final LongProperty v0 = new LongPropertyStub(NO_BEAN, NO_NAME_1); + assertEquals("LongProperty [value: " + DEFAULT + "]", v0.toString()); + + final LongProperty v1 = new LongPropertyStub(NO_BEAN, NO_NAME_2); + assertEquals("LongProperty [value: " + DEFAULT + "]", v1.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final LongProperty v2 = new LongPropertyStub(bean, name); + assertEquals("LongProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + v2.set(VALUE_1); + assertEquals("LongProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); + + final LongProperty v3 = new LongPropertyStub(bean, NO_NAME_1); + assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + v3.set(VALUE_1); + assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); + + final LongProperty v4 = new LongPropertyStub(bean, NO_NAME_2); + assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + v4.set(VALUE_1); + assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); + + final LongProperty v5 = new LongPropertyStub(NO_BEAN, name); + assertEquals("LongProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); + v5.set(VALUE_1); + assertEquals("LongProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); + } + + @Test + public void testAsObject() { + final LongProperty valueModel = new SimpleLongProperty(); + final ObjectProperty exp = valueModel.asObject(); + + assertEquals(Long.valueOf(0L), exp.getValue()); + valueModel.set(-4354L); + assertEquals(Long.valueOf(-4354L), exp.getValue()); + valueModel.set(5L); + assertEquals(Long.valueOf(5L), exp.getValue()); + + exp.set(10L); + assertEquals(10L, valueModel.longValue()); + } + + @Test + public void testObjectToLong() { + final ObjectProperty valueModel = new SimpleObjectProperty(2L); + final LongProperty exp = LongProperty.longProperty(valueModel); + + assertEquals(2L, exp.longValue()); + valueModel.set(-4354L); + assertEquals(-4354L, exp.longValue()); + valueModel.set(5L); + assertEquals(5L, exp.longValue()); + + exp.set(10L); + assertEquals(Long.valueOf(10L), valueModel.getValue()); + } + + private class LongPropertyStub extends LongProperty { + + private final Object bean; + private final String name; + private long value; + + private LongPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + + @Override + public long get() { + return value; + } + + @Override + public void set(long value) { + this.value = value; + } + + @Override + public void bind(ObservableValue observable) { + fail("Not in use"); + } + + @Override + public void unbind() { + fail("Not in use"); + } + + @Override + public boolean isBound() { + fail("Not in use"); + return false; + } + + @Override + public void addListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void addListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(InvalidationListener listener) { + fail("Not in use"); + } + + } +} --- old/modules/base/src/test/java/javafx/beans/property/MapPropertyBaseTest.java 2015-08-31 10:23:27.505217473 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,796 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableObjectValueStub; -import javafx.collections.FXCollections; -import javafx.collections.MockMapObserver; -import javafx.collections.ObservableMap; -import org.junit.Before; -import org.junit.Test; - -import java.util.Collections; -import java.util.HashMap; - -import static javafx.collections.MockMapObserver.Call; -import static org.junit.Assert.*; - -public class MapPropertyBaseTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final Object KEY_1b = new Object(); - private static final Object DATA_1b = new Object(); - private static final Object KEY_2a_0 = new Object(); - private static final Object DATA_2a_0 = new Object(); - private static final Object KEY_2a_1 = new Object(); - private static final Object DATA_2a_1 = new Object(); - private static final Object KEY_2b_0 = new Object(); - private static final Object DATA_2b_0 = new Object(); - private static final Object KEY_2b_1 = new Object(); - private static final Object DATA_2b_1 = new Object(); - private static final Object KEY_2b_2 = new Object(); - private static final Object DATA_2b_2 = new Object(); - private static final ObservableMap UNDEFINED = FXCollections.observableMap(Collections.emptyMap()); - private static final ObservableMap VALUE_1a = FXCollections.observableMap(Collections.emptyMap()); - private static final ObservableMap VALUE_1b = FXCollections.observableMap(Collections.singletonMap(KEY_1b, DATA_1b)); - private static final ObservableMap VALUE_2a = FXCollections.observableMap(new HashMap()); - - static { - VALUE_2a.put(KEY_2a_0, DATA_2a_0); - VALUE_2a.put(KEY_2a_1, DATA_2a_1); - } - private static final ObservableMap VALUE_2b = FXCollections.observableMap(new HashMap()); - - static { - VALUE_2b.put(KEY_2b_0, DATA_2b_0); - VALUE_2b.put(KEY_2b_1, DATA_2b_1); - VALUE_2b.put(KEY_2b_2, DATA_2b_2); - } - private MapPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock> changeListener; - private MockMapObserver mapChangeListener; - - @Before - public void setUp() throws Exception { - property = new MapPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock>(UNDEFINED); - mapChangeListener = new MockMapObserver(); - } - - private void attachInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - } - - private void attachChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - } - - private void attachMapChangeListener() { - property.addListener(mapChangeListener); - property.get(); - mapChangeListener.clear(); - } - - @Test - public void testConstructor() { - final MapProperty p1 = new SimpleMapProperty(); - assertEquals(null, p1.get()); - assertEquals(null, p1.getValue()); - assertFalse(property.isBound()); - - final MapProperty p2 = new SimpleMapProperty(VALUE_1b); - assertEquals(VALUE_1b, p2.get()); - assertEquals(VALUE_1b, p2.getValue()); - assertFalse(property.isBound()); - } - - @Test - public void testEmptyProperty() { - assertEquals("empty", property.emptyProperty().getName()); - assertEquals(property, property.emptyProperty().getBean()); - assertTrue(property.emptyProperty().get()); - - property.set(VALUE_2a); - assertFalse(property.emptyProperty().get()); - property.set(VALUE_1a); - assertTrue(property.emptyProperty().get()); - } - - @Test - public void testSizeProperty() { - assertEquals("size", property.sizeProperty().getName()); - assertEquals(property, property.sizeProperty().getBean()); - assertEquals(0, property.sizeProperty().get()); - - property.set(VALUE_2a); - assertEquals(2, property.sizeProperty().get()); - property.set(VALUE_1a); - assertEquals(0, property.sizeProperty().get()); - } - - @Test - public void testInvalidationListener() { - attachInvalidationListener(); - property.set(VALUE_2a); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_1a); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - attachChangeListener(); - property.set(VALUE_2a); - changeListener.check(property, null, VALUE_2a, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_1a); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testMapChangeListener() { - attachMapChangeListener(); - property.set(VALUE_2a); - mapChangeListener.assertMultipleCalls(new Call[]{new Call(KEY_2a_0, null, DATA_2a_0), new Call(KEY_2a_1, null, DATA_2a_1)}); - property.removeListener(mapChangeListener); - mapChangeListener.clear(); - property.set(VALUE_1a); - assertEquals(0, mapChangeListener.getCallsNumber()); - } - - @Test - public void testSourceMap_Invalidation() { - final ObservableMap source1 = FXCollections.observableMap(new HashMap()); - final ObservableMap source2 = FXCollections.observableMap(new HashMap()); - final Object key = new Object(); - final Object value1 = new Object(); - final Object value2 = new Object(); - - // constructor - property = new MapPropertyMock(source1); - property.reset(); - attachInvalidationListener(); - - // add element - source1.put(key, value1); - assertEquals(value1, property.get(key)); - property.check(1); - invalidationListener.check(property, 1); - - // replace element - source1.put(key, value2); - assertEquals(value2, property.get(key)); - property.check(1); - invalidationListener.check(property, 1); - - // remove element - source1.remove(key); - assertNull(property.get(key)); - property.check(1); - invalidationListener.check(property, 1); - - // set - property.set(source2); - property.get(); - property.reset(); - invalidationListener.reset(); - - // add element - source2.put(key, value1); - assertEquals(value1, property.get(key)); - property.check(1); - invalidationListener.check(property, 1); - - // replace element - source2.put(key, value2); - assertEquals(value2, property.get(key)); - property.check(1); - invalidationListener.check(property, 1); - - // remove element - source2.remove(key); - assertNull(property.get(key)); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testSourceMap_Change() { - final ObservableMap source1 = FXCollections.observableMap(new HashMap()); - final ObservableMap source2 = FXCollections.observableMap(new HashMap()); - final Object key = new Object(); - final Object value1 = new Object(); - final Object value2 = new Object(); - - // constructor - property = new MapPropertyMock(source1); - property.reset(); - attachChangeListener(); - - // add element - source1.put(key, value1); - assertEquals(value1, property.get(key)); - property.check(1); - changeListener.check(property, source1, source1, 1); - - // replace element - source1.put(key, value2); - assertEquals(value2, property.get(key)); - property.check(1); - changeListener.check(property, source1, source1, 1); - - // remove element - source1.remove(key); - assertNull(property.get(key)); - property.check(1); - changeListener.check(property, source1, source1, 1); - - // set - property.set(source2); - property.get(); - property.reset(); - changeListener.reset(); - - // add element - source2.put(key, value1); - assertEquals(value1, property.get(key)); - property.check(1); - changeListener.check(property, source2, source2, 1); - - // replace element - source2.put(key, value2); - assertEquals(value2, property.get(key)); - property.check(1); - changeListener.check(property, source2, source2, 1); - - // remove element - source2.remove(key); - assertNull(property.get(key)); - property.check(1); - changeListener.check(property, source2, source2, 1); - } - - @Test - public void testSourceMap_MapChange() { - final ObservableMap source1 = FXCollections.observableMap(new HashMap()); - final ObservableMap source2 = FXCollections.observableMap(new HashMap()); - final Object key = new Object(); - final Object value1 = new Object(); - final Object value2 = new Object(); - - // constructor - property = new MapPropertyMock(source1); - property.reset(); - attachMapChangeListener(); - - // add element - source1.put(key, value1); - assertEquals(value1, property.get(key)); - property.check(1); - mapChangeListener.assertAdded(MockMapObserver.Tuple.tup(key, value1)); - mapChangeListener.clear(); - - // replace element - source1.put(key, value2); - assertEquals(value2, property.get(key)); - property.check(1); - mapChangeListener.assertMultipleCalls(new Call(key, value1, value2)); - mapChangeListener.clear(); - - // remove element - source1.remove(key); - assertNull(property.get(key)); - property.check(1); - mapChangeListener.assertRemoved(MockMapObserver.Tuple.tup(key, value2)); - mapChangeListener.clear(); - - // set - property.set(source2); - property.get(); - property.reset(); - mapChangeListener.clear(); - - // add element - source2.put(key, value1); - assertEquals(value1, property.get(key)); - property.check(1); - mapChangeListener.assertAdded(MockMapObserver.Tuple.tup(key, value1)); - mapChangeListener.clear(); - - // replace element - source2.put(key, value2); - assertEquals(value2, property.get(key)); - property.check(1); - mapChangeListener.assertMultipleCalls(new Call(key, value1, value2)); - mapChangeListener.clear(); - - // remove element - source2.remove(key); - assertNull(property.get(key)); - property.check(1); - mapChangeListener.assertRemoved(MockMapObserver.Tuple.tup(key, value2)); - mapChangeListener.clear(); - } - - @Test - public void testMap_Invalidation() { - attachInvalidationListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_1a); - property.set(VALUE_2b); - assertEquals(VALUE_2b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testMap_Change() { - attachChangeListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, null, VALUE_2a, 1); - - // set same value again - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_1a); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - } - - @Test - public void testMap_MapChange() { - attachMapChangeListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - mapChangeListener.assertMultipleCalls(new Call[]{new Call(KEY_2a_0, null, DATA_2a_0), new Call(KEY_2a_1, null, DATA_2a_1)}); - - // set same value again - mapChangeListener.clear(); - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - assertEquals(0, mapChangeListener.getCallsNumber()); - - // set value twice without reading - property.set(VALUE_1a); - mapChangeListener.clear(); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - mapChangeListener.assertAdded(MockMapObserver.Tuple.tup(KEY_1b, DATA_1b)); - } - - @Test - public void testMapValue_Invalidation() { - attachInvalidationListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_1a); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testMapValue_Change() { - attachChangeListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, null, VALUE_2a, 1); - - // set same value again - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_1a); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - } - - @Test - public void testMapValue_MapChange() { - attachMapChangeListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - mapChangeListener.assertMultipleCalls(new Call[]{new Call(KEY_2a_0, null, DATA_2a_0), new Call(KEY_2a_1, null, DATA_2a_1)}); - - // set same value again - mapChangeListener.clear(); - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - assertEquals(0, mapChangeListener.getCallsNumber()); - - // set value twice without reading - property.setValue(VALUE_1a); - mapChangeListener.clear(); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - mapChangeListener.assertAdded(MockMapObserver.Tuple.tup(KEY_1b, DATA_1b)); - } - - @Test(expected = RuntimeException.class) - public void testMapBoundValue() { - final MapProperty v = new SimpleMapProperty(VALUE_1a); - property.bind(v); - property.set(VALUE_1a); - } - - @Test - public void testBind_Invalidation() { - attachInvalidationListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableMap(VALUE_1a)); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(VALUE_1a); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(VALUE_1a); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testBind_Change() { - attachChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableMap(VALUE_1a)); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, null, VALUE_1a, 1); - - // change binding once - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, VALUE_1a, VALUE_2a, 1); - - // change binding twice without reading - v.set(VALUE_1a); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - - // change binding twice to same value - v.set(VALUE_1a); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(2); - changeListener.check(property, VALUE_1b, VALUE_1a, 1); - } - - @Test - public void testBind_MapChange() { - attachMapChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableMap(VALUE_1a)); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(0, mapChangeListener.getCallsNumber()); - - // change binding once - mapChangeListener.clear(); - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - mapChangeListener.assertMultipleCalls(new Call[]{new Call(KEY_2a_0, null, DATA_2a_0), new Call(KEY_2a_1, null, DATA_2a_1)}); - - // change binding twice without reading - v.set(VALUE_1a); - mapChangeListener.clear(); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - mapChangeListener.assertAdded(MockMapObserver.Tuple.tup(KEY_1b, DATA_1b)); - - // change binding twice to same value - v.set(VALUE_1a); - mapChangeListener.clear(); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(2); - assertEquals(0, mapChangeListener.getCallsNumber()); - } - - @Test(expected = NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListener(); - final MapProperty v1 = new SimpleMapProperty(VALUE_1a); - final MapProperty v2 = new SimpleMapProperty(VALUE_2a); - property.bind(v1); - property.get(); - property.reset(); - invalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2a, property.get()); - assertTrue(property.isBound()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // change old binding - v1.set(VALUE_1b); - assertEquals(VALUE_2a, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // change new binding - v2.set(VALUE_2b); - assertEquals(VALUE_2b, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_2b, property.get()); - assertTrue(property.isBound()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListener(); - final MapProperty v = new SimpleMapProperty(VALUE_1a); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1a, property.get()); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(VALUE_2a); - assertEquals(VALUE_1a, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final MapProperty v = new SimpleMapProperty(VALUE_1a); - final InvalidationListenerMock listener2 = new InvalidationListenerMock(); - final InvalidationListenerMock listener3 = new InvalidationListenerMock(); - - // setting the property - property.set(VALUE_1a); - property.addListener(listener2); - listener2.reset(); - property.set(VALUE_1b); - listener2.check(property, 1); - - // binding the property - property.bind(v); - v.set(VALUE_2a); - property.addListener(listener3); - v.get(); - listener3.reset(); - v.set(VALUE_2b); - listener3.check(property, 1); - } - - @Test - public void testToString() { - final ObservableMap value0 = null; - final ObservableMap value1 = FXCollections.observableMap(new HashMap()); - value1.put(new Object(), new Object()); - value1.put(new Object(), new Object()); - final ObservableMap value2 = FXCollections.observableMap(new HashMap()); - final MapProperty v = new SimpleMapProperty(value2); - - property.set(value1); - assertEquals("MapProperty [value: " + value1 + "]", property.toString()); - - property.bind(v); - assertEquals("MapProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("MapProperty [bound, value: " + value2 + "]", property.toString()); - v.set(value1); - assertEquals("MapProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("MapProperty [bound, value: " + value1 + "]", property.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final MapProperty v1 = new MapPropertyMock(bean, name); - assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + null + "]", v1.toString()); - v1.set(value1); - assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); - v1.set(value0); - assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - - final MapProperty v2 = new MapPropertyMock(bean, NO_NAME_1); - assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + null + "]", v2.toString()); - v2.set(value1); - assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); - v1.set(value0); - assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - - final MapProperty v3 = new MapPropertyMock(bean, NO_NAME_2); - assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + null + "]", v3.toString()); - v3.set(value1); - assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); - v1.set(value0); - assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - - final MapProperty v4 = new MapPropertyMock(NO_BEAN, name); - assertEquals("MapProperty [name: My name, value: " + null + "]", v4.toString()); - v4.set(value1); - v1.set(value0); - assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - assertEquals("MapProperty [name: My name, value: " + value1 + "]", v4.toString()); - } - - private static class MapPropertyMock extends MapPropertyBase { - - private final Object bean; - private final String name; - private int counter; - - private MapPropertyMock() { - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - private MapPropertyMock(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - private MapPropertyMock(ObservableMap initialValue) { - super(initialValue); - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/MapPropertyBaseTest.java 2015-08-31 10:23:27.369217475 -0400 @@ -0,0 +1,799 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableObjectValueStub; +import javafx.collections.FXCollections; +import test.javafx.collections.MockMapObserver; +import javafx.collections.ObservableMap; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import javafx.beans.property.MapProperty; +import javafx.beans.property.MapPropertyBase; +import javafx.beans.property.SimpleMapProperty; + +import static test.javafx.collections.MockMapObserver.Call; +import static org.junit.Assert.*; + +public class MapPropertyBaseTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final Object KEY_1b = new Object(); + private static final Object DATA_1b = new Object(); + private static final Object KEY_2a_0 = new Object(); + private static final Object DATA_2a_0 = new Object(); + private static final Object KEY_2a_1 = new Object(); + private static final Object DATA_2a_1 = new Object(); + private static final Object KEY_2b_0 = new Object(); + private static final Object DATA_2b_0 = new Object(); + private static final Object KEY_2b_1 = new Object(); + private static final Object DATA_2b_1 = new Object(); + private static final Object KEY_2b_2 = new Object(); + private static final Object DATA_2b_2 = new Object(); + private static final ObservableMap UNDEFINED = FXCollections.observableMap(Collections.emptyMap()); + private static final ObservableMap VALUE_1a = FXCollections.observableMap(Collections.emptyMap()); + private static final ObservableMap VALUE_1b = FXCollections.observableMap(Collections.singletonMap(KEY_1b, DATA_1b)); + private static final ObservableMap VALUE_2a = FXCollections.observableMap(new HashMap()); + + static { + VALUE_2a.put(KEY_2a_0, DATA_2a_0); + VALUE_2a.put(KEY_2a_1, DATA_2a_1); + } + private static final ObservableMap VALUE_2b = FXCollections.observableMap(new HashMap()); + + static { + VALUE_2b.put(KEY_2b_0, DATA_2b_0); + VALUE_2b.put(KEY_2b_1, DATA_2b_1); + VALUE_2b.put(KEY_2b_2, DATA_2b_2); + } + private MapPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock> changeListener; + private MockMapObserver mapChangeListener; + + @Before + public void setUp() throws Exception { + property = new MapPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock>(UNDEFINED); + mapChangeListener = new MockMapObserver(); + } + + private void attachInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + } + + private void attachChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + } + + private void attachMapChangeListener() { + property.addListener(mapChangeListener); + property.get(); + mapChangeListener.clear(); + } + + @Test + public void testConstructor() { + final MapProperty p1 = new SimpleMapProperty(); + assertEquals(null, p1.get()); + assertEquals(null, p1.getValue()); + assertFalse(property.isBound()); + + final MapProperty p2 = new SimpleMapProperty(VALUE_1b); + assertEquals(VALUE_1b, p2.get()); + assertEquals(VALUE_1b, p2.getValue()); + assertFalse(property.isBound()); + } + + @Test + public void testEmptyProperty() { + assertEquals("empty", property.emptyProperty().getName()); + assertEquals(property, property.emptyProperty().getBean()); + assertTrue(property.emptyProperty().get()); + + property.set(VALUE_2a); + assertFalse(property.emptyProperty().get()); + property.set(VALUE_1a); + assertTrue(property.emptyProperty().get()); + } + + @Test + public void testSizeProperty() { + assertEquals("size", property.sizeProperty().getName()); + assertEquals(property, property.sizeProperty().getBean()); + assertEquals(0, property.sizeProperty().get()); + + property.set(VALUE_2a); + assertEquals(2, property.sizeProperty().get()); + property.set(VALUE_1a); + assertEquals(0, property.sizeProperty().get()); + } + + @Test + public void testInvalidationListener() { + attachInvalidationListener(); + property.set(VALUE_2a); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_1a); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + attachChangeListener(); + property.set(VALUE_2a); + changeListener.check(property, null, VALUE_2a, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_1a); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testMapChangeListener() { + attachMapChangeListener(); + property.set(VALUE_2a); + mapChangeListener.assertMultipleCalls(new Call[]{new Call(KEY_2a_0, null, DATA_2a_0), new Call(KEY_2a_1, null, DATA_2a_1)}); + property.removeListener(mapChangeListener); + mapChangeListener.clear(); + property.set(VALUE_1a); + assertEquals(0, mapChangeListener.getCallsNumber()); + } + + @Test + public void testSourceMap_Invalidation() { + final ObservableMap source1 = FXCollections.observableMap(new HashMap()); + final ObservableMap source2 = FXCollections.observableMap(new HashMap()); + final Object key = new Object(); + final Object value1 = new Object(); + final Object value2 = new Object(); + + // constructor + property = new MapPropertyMock(source1); + property.reset(); + attachInvalidationListener(); + + // add element + source1.put(key, value1); + assertEquals(value1, property.get(key)); + property.check(1); + invalidationListener.check(property, 1); + + // replace element + source1.put(key, value2); + assertEquals(value2, property.get(key)); + property.check(1); + invalidationListener.check(property, 1); + + // remove element + source1.remove(key); + assertNull(property.get(key)); + property.check(1); + invalidationListener.check(property, 1); + + // set + property.set(source2); + property.get(); + property.reset(); + invalidationListener.reset(); + + // add element + source2.put(key, value1); + assertEquals(value1, property.get(key)); + property.check(1); + invalidationListener.check(property, 1); + + // replace element + source2.put(key, value2); + assertEquals(value2, property.get(key)); + property.check(1); + invalidationListener.check(property, 1); + + // remove element + source2.remove(key); + assertNull(property.get(key)); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testSourceMap_Change() { + final ObservableMap source1 = FXCollections.observableMap(new HashMap()); + final ObservableMap source2 = FXCollections.observableMap(new HashMap()); + final Object key = new Object(); + final Object value1 = new Object(); + final Object value2 = new Object(); + + // constructor + property = new MapPropertyMock(source1); + property.reset(); + attachChangeListener(); + + // add element + source1.put(key, value1); + assertEquals(value1, property.get(key)); + property.check(1); + changeListener.check(property, source1, source1, 1); + + // replace element + source1.put(key, value2); + assertEquals(value2, property.get(key)); + property.check(1); + changeListener.check(property, source1, source1, 1); + + // remove element + source1.remove(key); + assertNull(property.get(key)); + property.check(1); + changeListener.check(property, source1, source1, 1); + + // set + property.set(source2); + property.get(); + property.reset(); + changeListener.reset(); + + // add element + source2.put(key, value1); + assertEquals(value1, property.get(key)); + property.check(1); + changeListener.check(property, source2, source2, 1); + + // replace element + source2.put(key, value2); + assertEquals(value2, property.get(key)); + property.check(1); + changeListener.check(property, source2, source2, 1); + + // remove element + source2.remove(key); + assertNull(property.get(key)); + property.check(1); + changeListener.check(property, source2, source2, 1); + } + + @Test + public void testSourceMap_MapChange() { + final ObservableMap source1 = FXCollections.observableMap(new HashMap()); + final ObservableMap source2 = FXCollections.observableMap(new HashMap()); + final Object key = new Object(); + final Object value1 = new Object(); + final Object value2 = new Object(); + + // constructor + property = new MapPropertyMock(source1); + property.reset(); + attachMapChangeListener(); + + // add element + source1.put(key, value1); + assertEquals(value1, property.get(key)); + property.check(1); + mapChangeListener.assertAdded(MockMapObserver.Tuple.tup(key, value1)); + mapChangeListener.clear(); + + // replace element + source1.put(key, value2); + assertEquals(value2, property.get(key)); + property.check(1); + mapChangeListener.assertMultipleCalls(new Call(key, value1, value2)); + mapChangeListener.clear(); + + // remove element + source1.remove(key); + assertNull(property.get(key)); + property.check(1); + mapChangeListener.assertRemoved(MockMapObserver.Tuple.tup(key, value2)); + mapChangeListener.clear(); + + // set + property.set(source2); + property.get(); + property.reset(); + mapChangeListener.clear(); + + // add element + source2.put(key, value1); + assertEquals(value1, property.get(key)); + property.check(1); + mapChangeListener.assertAdded(MockMapObserver.Tuple.tup(key, value1)); + mapChangeListener.clear(); + + // replace element + source2.put(key, value2); + assertEquals(value2, property.get(key)); + property.check(1); + mapChangeListener.assertMultipleCalls(new Call(key, value1, value2)); + mapChangeListener.clear(); + + // remove element + source2.remove(key); + assertNull(property.get(key)); + property.check(1); + mapChangeListener.assertRemoved(MockMapObserver.Tuple.tup(key, value2)); + mapChangeListener.clear(); + } + + @Test + public void testMap_Invalidation() { + attachInvalidationListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_1a); + property.set(VALUE_2b); + assertEquals(VALUE_2b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testMap_Change() { + attachChangeListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, null, VALUE_2a, 1); + + // set same value again + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_1a); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + } + + @Test + public void testMap_MapChange() { + attachMapChangeListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + mapChangeListener.assertMultipleCalls(new Call[]{new Call(KEY_2a_0, null, DATA_2a_0), new Call(KEY_2a_1, null, DATA_2a_1)}); + + // set same value again + mapChangeListener.clear(); + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + assertEquals(0, mapChangeListener.getCallsNumber()); + + // set value twice without reading + property.set(VALUE_1a); + mapChangeListener.clear(); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + mapChangeListener.assertAdded(MockMapObserver.Tuple.tup(KEY_1b, DATA_1b)); + } + + @Test + public void testMapValue_Invalidation() { + attachInvalidationListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_1a); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testMapValue_Change() { + attachChangeListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, null, VALUE_2a, 1); + + // set same value again + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_1a); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + } + + @Test + public void testMapValue_MapChange() { + attachMapChangeListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + mapChangeListener.assertMultipleCalls(new Call[]{new Call(KEY_2a_0, null, DATA_2a_0), new Call(KEY_2a_1, null, DATA_2a_1)}); + + // set same value again + mapChangeListener.clear(); + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + assertEquals(0, mapChangeListener.getCallsNumber()); + + // set value twice without reading + property.setValue(VALUE_1a); + mapChangeListener.clear(); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + mapChangeListener.assertAdded(MockMapObserver.Tuple.tup(KEY_1b, DATA_1b)); + } + + @Test(expected = RuntimeException.class) + public void testMapBoundValue() { + final MapProperty v = new SimpleMapProperty(VALUE_1a); + property.bind(v); + property.set(VALUE_1a); + } + + @Test + public void testBind_Invalidation() { + attachInvalidationListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableMap(VALUE_1a)); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(VALUE_1a); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(VALUE_1a); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testBind_Change() { + attachChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableMap(VALUE_1a)); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, null, VALUE_1a, 1); + + // change binding once + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, VALUE_1a, VALUE_2a, 1); + + // change binding twice without reading + v.set(VALUE_1a); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + + // change binding twice to same value + v.set(VALUE_1a); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(2); + changeListener.check(property, VALUE_1b, VALUE_1a, 1); + } + + @Test + public void testBind_MapChange() { + attachMapChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableMap(VALUE_1a)); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(0, mapChangeListener.getCallsNumber()); + + // change binding once + mapChangeListener.clear(); + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + mapChangeListener.assertMultipleCalls(new Call[]{new Call(KEY_2a_0, null, DATA_2a_0), new Call(KEY_2a_1, null, DATA_2a_1)}); + + // change binding twice without reading + v.set(VALUE_1a); + mapChangeListener.clear(); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + mapChangeListener.assertAdded(MockMapObserver.Tuple.tup(KEY_1b, DATA_1b)); + + // change binding twice to same value + v.set(VALUE_1a); + mapChangeListener.clear(); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(2); + assertEquals(0, mapChangeListener.getCallsNumber()); + } + + @Test(expected = NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListener(); + final MapProperty v1 = new SimpleMapProperty(VALUE_1a); + final MapProperty v2 = new SimpleMapProperty(VALUE_2a); + property.bind(v1); + property.get(); + property.reset(); + invalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2a, property.get()); + assertTrue(property.isBound()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // change old binding + v1.set(VALUE_1b); + assertEquals(VALUE_2a, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // change new binding + v2.set(VALUE_2b); + assertEquals(VALUE_2b, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_2b, property.get()); + assertTrue(property.isBound()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListener(); + final MapProperty v = new SimpleMapProperty(VALUE_1a); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1a, property.get()); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(VALUE_2a); + assertEquals(VALUE_1a, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final MapProperty v = new SimpleMapProperty(VALUE_1a); + final InvalidationListenerMock listener2 = new InvalidationListenerMock(); + final InvalidationListenerMock listener3 = new InvalidationListenerMock(); + + // setting the property + property.set(VALUE_1a); + property.addListener(listener2); + listener2.reset(); + property.set(VALUE_1b); + listener2.check(property, 1); + + // binding the property + property.bind(v); + v.set(VALUE_2a); + property.addListener(listener3); + v.get(); + listener3.reset(); + v.set(VALUE_2b); + listener3.check(property, 1); + } + + @Test + public void testToString() { + final ObservableMap value0 = null; + final ObservableMap value1 = FXCollections.observableMap(new HashMap()); + value1.put(new Object(), new Object()); + value1.put(new Object(), new Object()); + final ObservableMap value2 = FXCollections.observableMap(new HashMap()); + final MapProperty v = new SimpleMapProperty(value2); + + property.set(value1); + assertEquals("MapProperty [value: " + value1 + "]", property.toString()); + + property.bind(v); + assertEquals("MapProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("MapProperty [bound, value: " + value2 + "]", property.toString()); + v.set(value1); + assertEquals("MapProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("MapProperty [bound, value: " + value1 + "]", property.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final MapProperty v1 = new MapPropertyMock(bean, name); + assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + null + "]", v1.toString()); + v1.set(value1); + assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); + v1.set(value0); + assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + + final MapProperty v2 = new MapPropertyMock(bean, NO_NAME_1); + assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + null + "]", v2.toString()); + v2.set(value1); + assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); + v1.set(value0); + assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + + final MapProperty v3 = new MapPropertyMock(bean, NO_NAME_2); + assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + null + "]", v3.toString()); + v3.set(value1); + assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); + v1.set(value0); + assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + + final MapProperty v4 = new MapPropertyMock(NO_BEAN, name); + assertEquals("MapProperty [name: My name, value: " + null + "]", v4.toString()); + v4.set(value1); + v1.set(value0); + assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + assertEquals("MapProperty [name: My name, value: " + value1 + "]", v4.toString()); + } + + private static class MapPropertyMock extends MapPropertyBase { + + private final Object bean; + private final String name; + private int counter; + + private MapPropertyMock() { + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + private MapPropertyMock(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + private MapPropertyMock(ObservableMap initialValue) { + super(initialValue); + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/MapPropertyTest.java 2015-08-31 10:23:28.181217465 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,200 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.collections.FXCollections; -import javafx.collections.ObservableMap; -import javafx.collections.MapChangeListener; -import org.junit.Test; - -import java.util.Collections; -import java.util.HashMap; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -public class MapPropertyTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final ObservableMap VALUE_1 = FXCollections.observableMap(Collections.emptyMap()); - private static final ObservableMap VALUE_2 = FXCollections.observableMap(Collections.singletonMap(new Object(), new Object())); - private static final Object DEFAULT = null; - - @Test - public void testBindBidirectional() { - final MapProperty p1 = new SimpleMapProperty(VALUE_2); - final MapProperty p2 = new SimpleMapProperty(VALUE_1); - - p1.bindBidirectional(p2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_2, p2.get()); - - p2.set(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.unbindBidirectional(p2); - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_1); - p2.set(VALUE_2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_2, p2.get()); - } - - @Test - public void testToString() { - final MapProperty v0 = new MapPropertyStub(NO_BEAN, NO_NAME_1); - assertEquals("MapProperty [value: " + DEFAULT + "]", v0.toString()); - - final MapProperty v1 = new MapPropertyStub(NO_BEAN, NO_NAME_2); - assertEquals("MapProperty [value: " + DEFAULT + "]", v1.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final MapProperty v2 = new MapPropertyStub(bean, name); - assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - v2.set(VALUE_1); - assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); - - final MapProperty v3 = new MapPropertyStub(bean, NO_NAME_1); - assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - v3.set(VALUE_1); - assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); - - final MapProperty v4 = new MapPropertyStub(bean, NO_NAME_2); - assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - v4.set(VALUE_1); - assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); - - final MapProperty v5 = new MapPropertyStub(NO_BEAN, name); - assertEquals("MapProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); - v5.set(VALUE_1); - assertEquals("MapProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); - } - - private class MapPropertyStub extends MapProperty { - - private final Object bean; - private final String name; - private ObservableMap value; - - private MapPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - - @Override - public ObservableMap get() { - return value; - } - - @Override - public void set(ObservableMap value) { - this.value = value; - } - - @Override - public void bind(ObservableValue> observable) { - fail("Not in use"); - } - - @Override - public void unbind() { - fail("Not in use"); - } - - @Override - public boolean isBound() { - fail("Not in use"); - return false; - } - - @Override - public void addListener(ChangeListener> listener) { - fail("Not in use"); - } - - @Override - public void removeListener(ChangeListener> listener) { - fail("Not in use"); - } - - @Override - public void addListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void addListener(MapChangeListener listChangeListener) { - fail("Not in use"); - } - - @Override - public void removeListener(MapChangeListener listChangeListener) { - fail("Not in use"); - } - - @Override - public ReadOnlyIntegerProperty sizeProperty() { - fail("Not in use"); - return null; - } - - @Override - public ReadOnlyBooleanProperty emptyProperty() { - fail("Not in use"); - return null; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/MapPropertyTest.java 2015-08-31 10:23:28.045217467 -0400 @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.InvalidationListener; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ObservableMap; +import javafx.collections.MapChangeListener; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import javafx.beans.property.MapProperty; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.SimpleMapProperty; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class MapPropertyTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final ObservableMap VALUE_1 = FXCollections.observableMap(Collections.emptyMap()); + private static final ObservableMap VALUE_2 = FXCollections.observableMap(Collections.singletonMap(new Object(), new Object())); + private static final Object DEFAULT = null; + + @Test + public void testBindBidirectional() { + final MapProperty p1 = new SimpleMapProperty(VALUE_2); + final MapProperty p2 = new SimpleMapProperty(VALUE_1); + + p1.bindBidirectional(p2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_2, p2.get()); + + p2.set(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.unbindBidirectional(p2); + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_1); + p2.set(VALUE_2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_2, p2.get()); + } + + @Test + public void testToString() { + final MapProperty v0 = new MapPropertyStub(NO_BEAN, NO_NAME_1); + assertEquals("MapProperty [value: " + DEFAULT + "]", v0.toString()); + + final MapProperty v1 = new MapPropertyStub(NO_BEAN, NO_NAME_2); + assertEquals("MapProperty [value: " + DEFAULT + "]", v1.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final MapProperty v2 = new MapPropertyStub(bean, name); + assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + v2.set(VALUE_1); + assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); + + final MapProperty v3 = new MapPropertyStub(bean, NO_NAME_1); + assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + v3.set(VALUE_1); + assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); + + final MapProperty v4 = new MapPropertyStub(bean, NO_NAME_2); + assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + v4.set(VALUE_1); + assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); + + final MapProperty v5 = new MapPropertyStub(NO_BEAN, name); + assertEquals("MapProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); + v5.set(VALUE_1); + assertEquals("MapProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); + } + + private class MapPropertyStub extends MapProperty { + + private final Object bean; + private final String name; + private ObservableMap value; + + private MapPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + + @Override + public ObservableMap get() { + return value; + } + + @Override + public void set(ObservableMap value) { + this.value = value; + } + + @Override + public void bind(ObservableValue> observable) { + fail("Not in use"); + } + + @Override + public void unbind() { + fail("Not in use"); + } + + @Override + public boolean isBound() { + fail("Not in use"); + return false; + } + + @Override + public void addListener(ChangeListener> listener) { + fail("Not in use"); + } + + @Override + public void removeListener(ChangeListener> listener) { + fail("Not in use"); + } + + @Override + public void addListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void addListener(MapChangeListener listChangeListener) { + fail("Not in use"); + } + + @Override + public void removeListener(MapChangeListener listChangeListener) { + fail("Not in use"); + } + + @Override + public ReadOnlyIntegerProperty sizeProperty() { + fail("Not in use"); + return null; + } + + @Override + public ReadOnlyBooleanProperty emptyProperty() { + fail("Not in use"); + return null; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/ObjectPropertyBaseTest.java 2015-08-31 10:23:28.937217457 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,444 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableObjectValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class ObjectPropertyBaseTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final Object UNDEFINED = new Object(); - private static final Object VALUE_1a = new Object(); - private static final Object VALUE_1b = new Object(); - private static final Object VALUE_2a = new Object(); - private static final Object VALUE_2b = new Object(); - - private ObjectPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new ObjectPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - } - - private void attachChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - } - - @Test - public void testConstructor() { - final ObjectProperty p1 = new SimpleObjectProperty(); - assertEquals(null, p1.get()); - assertEquals(null, p1.getValue()); - assertFalse(property.isBound()); - - final ObjectProperty p2 = new SimpleObjectProperty(VALUE_1b); - assertEquals(VALUE_1b, p2.get()); - assertEquals(VALUE_1b, p2.getValue()); - assertFalse(property.isBound()); - } - - @Test - public void testInvalidationListener() { - attachInvalidationListener(); - property.set(VALUE_2a); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_1a); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - attachChangeListener(); - property.set(VALUE_2a); - changeListener.check(property, null, VALUE_2a, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_1a); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testLazySet() { - attachInvalidationListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_1a); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSet() { - attachChangeListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, null, VALUE_2a, 1); - - // set same value again - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_1a); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_1a); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSetValue() { - attachChangeListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, null, VALUE_2a, 1); - - // set same value again - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_1a); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final ObjectProperty v = new SimpleObjectProperty(VALUE_1a); - property.bind(v); - property.set(VALUE_1a); - } - - @Test - public void testLazyBind() { - attachInvalidationListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1a); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(VALUE_1a); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(VALUE_1a); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBind() { - attachChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1a); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, null, VALUE_1a, 1); - - // change binding once - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, VALUE_1a, VALUE_2a, 1); - - // change binding twice without reading - v.set(VALUE_1a); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - - // change binding twice to same value - v.set(VALUE_1a); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(2); - changeListener.check(property, VALUE_1b, VALUE_1a, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListener(); - final ObjectProperty v1 = new SimpleObjectProperty(VALUE_1a); - final ObjectProperty v2 = new SimpleObjectProperty(VALUE_2a); - property.bind(v1); - property.get(); - property.reset(); - invalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2a, property.get()); - assertTrue(property.isBound()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // change old binding - v1.set(VALUE_1b); - assertEquals(VALUE_2a, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // change new binding - v2.set(VALUE_2b); - assertEquals(VALUE_2b, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_2b, property.get()); - assertTrue(property.isBound()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListener(); - final ObjectProperty v = new SimpleObjectProperty(VALUE_1a); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1a, property.get()); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(VALUE_2a); - assertEquals(VALUE_1a, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final ObjectProperty v = new SimpleObjectProperty(VALUE_1a); - final InvalidationListenerMock listener2 = new InvalidationListenerMock(); - final InvalidationListenerMock listener3 = new InvalidationListenerMock(); - - // setting the property - property.set(VALUE_1a); - property.addListener(listener2); - listener2.reset(); - property.set(VALUE_1b); - listener2.check(property, 1); - - // binding the property - property.bind(v); - v.set(VALUE_2a); - property.addListener(listener3); - v.get(); - listener3.reset(); - v.set(VALUE_2b); - listener3.check(property, 1); - } - - @Test - public void testToString() { - final Object value1 = new Object(); - final Object value2 = new Object(); - final ObjectProperty v = new SimpleObjectProperty(value2); - - property.set(value1); - assertEquals("ObjectProperty [value: " + value1 + "]", property.toString()); - - property.bind(v); - assertEquals("ObjectProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("ObjectProperty [bound, value: " + value2 + "]", property.toString()); - v.set(value1); - assertEquals("ObjectProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("ObjectProperty [bound, value: " + value1 + "]", property.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ObjectProperty v1 = new ObjectPropertyMock(bean, name); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + null + "]", v1.toString()); - v1.set(value1); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); - - final ObjectProperty v2 = new ObjectPropertyMock(bean, NO_NAME_1); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + null + "]", v2.toString()); - v2.set(value1); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); - - final ObjectProperty v3 = new ObjectPropertyMock(bean, NO_NAME_2); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + null + "]", v3.toString()); - v3.set(value1); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); - - final ObjectProperty v4 = new ObjectPropertyMock(NO_BEAN, name); - assertEquals("ObjectProperty [name: My name, value: " + null + "]", v4.toString()); - v4.set(value1); - assertEquals("ObjectProperty [name: My name, value: " + value1 + "]", v4.toString()); - } - - private static class ObjectPropertyMock extends ObjectPropertyBase { - - private final Object bean; - private final String name; - private int counter; - - private ObjectPropertyMock() { - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - private ObjectPropertyMock(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - - @Override public Object getBean() { return bean; } - - @Override public String getName() { return name; } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ObjectPropertyBaseTest.java 2015-08-31 10:23:28.797217459 -0400 @@ -0,0 +1,447 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ObjectPropertyBase; +import javafx.beans.property.SimpleObjectProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableObjectValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class ObjectPropertyBaseTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final Object UNDEFINED = new Object(); + private static final Object VALUE_1a = new Object(); + private static final Object VALUE_1b = new Object(); + private static final Object VALUE_2a = new Object(); + private static final Object VALUE_2b = new Object(); + + private ObjectPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new ObjectPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + } + + private void attachChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + } + + @Test + public void testConstructor() { + final ObjectProperty p1 = new SimpleObjectProperty(); + assertEquals(null, p1.get()); + assertEquals(null, p1.getValue()); + assertFalse(property.isBound()); + + final ObjectProperty p2 = new SimpleObjectProperty(VALUE_1b); + assertEquals(VALUE_1b, p2.get()); + assertEquals(VALUE_1b, p2.getValue()); + assertFalse(property.isBound()); + } + + @Test + public void testInvalidationListener() { + attachInvalidationListener(); + property.set(VALUE_2a); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_1a); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + attachChangeListener(); + property.set(VALUE_2a); + changeListener.check(property, null, VALUE_2a, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_1a); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testLazySet() { + attachInvalidationListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_1a); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSet() { + attachChangeListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, null, VALUE_2a, 1); + + // set same value again + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_1a); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_1a); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSetValue() { + attachChangeListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, null, VALUE_2a, 1); + + // set same value again + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_1a); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final ObjectProperty v = new SimpleObjectProperty(VALUE_1a); + property.bind(v); + property.set(VALUE_1a); + } + + @Test + public void testLazyBind() { + attachInvalidationListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1a); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(VALUE_1a); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(VALUE_1a); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBind() { + attachChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1a); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, null, VALUE_1a, 1); + + // change binding once + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, VALUE_1a, VALUE_2a, 1); + + // change binding twice without reading + v.set(VALUE_1a); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + + // change binding twice to same value + v.set(VALUE_1a); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(2); + changeListener.check(property, VALUE_1b, VALUE_1a, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListener(); + final ObjectProperty v1 = new SimpleObjectProperty(VALUE_1a); + final ObjectProperty v2 = new SimpleObjectProperty(VALUE_2a); + property.bind(v1); + property.get(); + property.reset(); + invalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2a, property.get()); + assertTrue(property.isBound()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // change old binding + v1.set(VALUE_1b); + assertEquals(VALUE_2a, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // change new binding + v2.set(VALUE_2b); + assertEquals(VALUE_2b, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_2b, property.get()); + assertTrue(property.isBound()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListener(); + final ObjectProperty v = new SimpleObjectProperty(VALUE_1a); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1a, property.get()); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(VALUE_2a); + assertEquals(VALUE_1a, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final ObjectProperty v = new SimpleObjectProperty(VALUE_1a); + final InvalidationListenerMock listener2 = new InvalidationListenerMock(); + final InvalidationListenerMock listener3 = new InvalidationListenerMock(); + + // setting the property + property.set(VALUE_1a); + property.addListener(listener2); + listener2.reset(); + property.set(VALUE_1b); + listener2.check(property, 1); + + // binding the property + property.bind(v); + v.set(VALUE_2a); + property.addListener(listener3); + v.get(); + listener3.reset(); + v.set(VALUE_2b); + listener3.check(property, 1); + } + + @Test + public void testToString() { + final Object value1 = new Object(); + final Object value2 = new Object(); + final ObjectProperty v = new SimpleObjectProperty(value2); + + property.set(value1); + assertEquals("ObjectProperty [value: " + value1 + "]", property.toString()); + + property.bind(v); + assertEquals("ObjectProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("ObjectProperty [bound, value: " + value2 + "]", property.toString()); + v.set(value1); + assertEquals("ObjectProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("ObjectProperty [bound, value: " + value1 + "]", property.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ObjectProperty v1 = new ObjectPropertyMock(bean, name); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + null + "]", v1.toString()); + v1.set(value1); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); + + final ObjectProperty v2 = new ObjectPropertyMock(bean, NO_NAME_1); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + null + "]", v2.toString()); + v2.set(value1); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); + + final ObjectProperty v3 = new ObjectPropertyMock(bean, NO_NAME_2); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + null + "]", v3.toString()); + v3.set(value1); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); + + final ObjectProperty v4 = new ObjectPropertyMock(NO_BEAN, name); + assertEquals("ObjectProperty [name: My name, value: " + null + "]", v4.toString()); + v4.set(value1); + assertEquals("ObjectProperty [name: My name, value: " + value1 + "]", v4.toString()); + } + + private static class ObjectPropertyMock extends ObjectPropertyBase { + + private final Object bean; + private final String name; + private int counter; + + private ObjectPropertyMock() { + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + private ObjectPropertyMock(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + + @Override public Object getBean() { return bean; } + + @Override public String getName() { return name; } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ObjectPropertyTest.java 2015-08-31 10:23:29.529217450 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; - -import org.junit.Test; - -public class ObjectPropertyTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final Object VALUE_1 = new Object(); - private static final Object VALUE_2 = new Object(); - private static final Object DEFAULT = null; - - @Test - public void testBindBidirectional() { - final ObjectProperty p1 = new SimpleObjectProperty(VALUE_2); - final ObjectProperty p2 = new SimpleObjectProperty(VALUE_1); - - p1.bindBidirectional(p2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_2, p2.get()); - - p2.set(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.unbindBidirectional(p2); - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_1); - p2.set(VALUE_2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_2, p2.get()); - } - - @Test - public void testToString() { - final ObjectProperty v0 = new ObjectPropertyStub(NO_BEAN, NO_NAME_1); - assertEquals("ObjectProperty [value: " + DEFAULT + "]", v0.toString()); - - final ObjectProperty v1 = new ObjectPropertyStub(NO_BEAN, NO_NAME_2); - assertEquals("ObjectProperty [value: " + DEFAULT + "]", v1.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ObjectProperty v2 = new ObjectPropertyStub(bean, name); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - v2.set(VALUE_1); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); - - final ObjectProperty v3 = new ObjectPropertyStub(bean, NO_NAME_1); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - v3.set(VALUE_1); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); - - final ObjectProperty v4 = new ObjectPropertyStub(bean, NO_NAME_2); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - v4.set(VALUE_1); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); - - final ObjectProperty v5 = new ObjectPropertyStub(NO_BEAN, name); - assertEquals("ObjectProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); - v5.set(VALUE_1); - assertEquals("ObjectProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); - } - - private class ObjectPropertyStub extends ObjectProperty { - - private final Object bean; - private final String name; - private Object value; - - private ObjectPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - - @Override - public Object get() { - return value; - } - - @Override - public void set(Object value) { - this.value = value; - } - - @Override - public void bind(ObservableValue observable) { - fail("Not in use"); - } - - @Override - public void unbind() { - fail("Not in use"); - } - - @Override - public boolean isBound() { - fail("Not in use"); - return false; - } - - @Override - public void addListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void addListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(InvalidationListener listener) { - fail("Not in use"); - } - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ObjectPropertyTest.java 2015-08-31 10:23:29.393217452 -0400 @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import javafx.beans.InvalidationListener; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; + +import org.junit.Test; + +public class ObjectPropertyTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final Object VALUE_1 = new Object(); + private static final Object VALUE_2 = new Object(); + private static final Object DEFAULT = null; + + @Test + public void testBindBidirectional() { + final ObjectProperty p1 = new SimpleObjectProperty(VALUE_2); + final ObjectProperty p2 = new SimpleObjectProperty(VALUE_1); + + p1.bindBidirectional(p2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_2, p2.get()); + + p2.set(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.unbindBidirectional(p2); + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_1); + p2.set(VALUE_2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_2, p2.get()); + } + + @Test + public void testToString() { + final ObjectProperty v0 = new ObjectPropertyStub(NO_BEAN, NO_NAME_1); + assertEquals("ObjectProperty [value: " + DEFAULT + "]", v0.toString()); + + final ObjectProperty v1 = new ObjectPropertyStub(NO_BEAN, NO_NAME_2); + assertEquals("ObjectProperty [value: " + DEFAULT + "]", v1.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ObjectProperty v2 = new ObjectPropertyStub(bean, name); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + v2.set(VALUE_1); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); + + final ObjectProperty v3 = new ObjectPropertyStub(bean, NO_NAME_1); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + v3.set(VALUE_1); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); + + final ObjectProperty v4 = new ObjectPropertyStub(bean, NO_NAME_2); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + v4.set(VALUE_1); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); + + final ObjectProperty v5 = new ObjectPropertyStub(NO_BEAN, name); + assertEquals("ObjectProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); + v5.set(VALUE_1); + assertEquals("ObjectProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); + } + + private class ObjectPropertyStub extends ObjectProperty { + + private final Object bean; + private final String name; + private Object value; + + private ObjectPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + + @Override + public Object get() { + return value; + } + + @Override + public void set(Object value) { + this.value = value; + } + + @Override + public void bind(ObservableValue observable) { + fail("Not in use"); + } + + @Override + public void unbind() { + fail("Not in use"); + } + + @Override + public boolean isBound() { + fail("Not in use"); + return false; + } + + @Override + public void addListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void addListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(InvalidationListener listener) { + fail("Not in use"); + } + + } +} --- old/modules/base/src/test/java/javafx/beans/property/PropertiesTest.java 2015-08-31 10:23:30.177217443 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -//package javafx.beans.property; -// -//import static org.junit.Assert.assertEquals; -//import javafx.binding.expression.BooleanExpression; -//import javafx.binding.expression.DoubleExpression; -//import javafx.binding.expression.FloatExpression; -//import javafx.binding.expression.IntegerExpression; -//import javafx.binding.expression.LongExpression; -//import javafx.binding.expression.ObjectExpression; -//import javafx.binding.expression.StringExpression; -// -//import org.junit.Before; -//import org.junit.Test; -// -//public class PropertiesTest { -// -// private static final double EPSILON_DOUBLE = 1e-12; -// private static final float EPSILON_FLOAT = 1e-6f; -// -// @Before -// public void setUp() throws Exception { -// } -// -// @Test -// public void testUnmodifiablePropertyBooleanProperty() { -// final boolean value1 = true; -// final boolean value2 = false; -// final BooleanProperty source = new SimpleBooleanProperty(value1); -// final BooleanExpression target = Properties.unmodifiableProperty(source); -// -// assertEquals(value1, target.get()); -// source.set(value2); -// assertEquals(value2, target.get()); -// source.set(value1); -// -// assertEquals(value1, target.getValue()); -// source.set(value2); -// assertEquals(value2, target.getValue()); -// source.set(value1); -// } -// -// @Test -// public void testUnmodifiablePropertyDoubleProperty() { -// final double value1 = Math.PI; -// final double value2 = -Math.E; -// final DoubleProperty source = new SimpleDoubleProperty(value1); -// final DoubleExpression target = Properties.unmodifiableProperty(source); -// -// assertEquals(value1, target.get(), EPSILON_DOUBLE); -// source.set(value2); -// assertEquals(value2, target.get(), EPSILON_DOUBLE); -// source.set(value1); -// -// assertEquals(value1, target.getValue(), EPSILON_DOUBLE); -// source.set(value2); -// assertEquals(value2, target.getValue(), EPSILON_DOUBLE); -// source.set(value1); -// } -// -// @Test -// public void testUnmodifiablePropertyFloatProperty() { -// final float value1 = (float)Math.PI; -// final float value2 = (float)-Math.E; -// final FloatProperty source = new SimpleFloatProperty(value1); -// final FloatExpression target = Properties.unmodifiableProperty(source); -// -// assertEquals(value1, target.get(), EPSILON_FLOAT); -// source.set(value2); -// assertEquals(value2, target.get(), EPSILON_FLOAT); -// source.set(value1); -// -// assertEquals(value1, target.getValue(), EPSILON_FLOAT); -// source.set(value2); -// assertEquals(value2, target.getValue(), EPSILON_FLOAT); -// source.set(value1); -// } -// -// @Test -// public void testUnmodifiablePropertyIntegerProperty() { -// final int value1 = 42; -// final int value2 = 12345; -// final IntegerProperty source = new SimpleIntegerProperty(value1); -// final IntegerExpression target = Properties.unmodifiableProperty(source); -// -// assertEquals(value1, target.get()); -// source.set(value2); -// assertEquals(value2, target.get()); -// source.set(value1); -// -// assertEquals(Integer.valueOf(value1), target.getValue()); -// source.set(value2); -// assertEquals(Integer.valueOf(value2), target.getValue()); -// source.set(value1); -// } -// -// @Test -// public void testUnmodifiablePropertyLongProperty() { -// final long value1 = 98765432123456789L; -// final long value2 = -1234567890987654321L; -// final LongProperty source = new SimpleLongProperty(value1); -// final LongExpression target = Properties.unmodifiableProperty(source); -// -// assertEquals(value1, target.get()); -// source.set(value2); -// assertEquals(value2, target.get()); -// source.set(value1); -// -// assertEquals(Long.valueOf(value1), target.getValue()); -// source.set(value2); -// assertEquals(Long.valueOf(value2), target.getValue()); -// source.set(value1); -// } -// -// @Test -// public void testUnmodifiablePropertyObjectPropertyOfT() { -// final Object value1 = new Object(); -// final Object value2 = new Object(); -// final ObjectProperty source = new SimpleObjectProperty(value1); -// final ObjectExpression target = Properties.unmodifiableProperty(source); -// -// assertEquals(value1, target.get()); -// source.set(value2); -// assertEquals(value2, target.get()); -// source.set(value1); -// -// assertEquals(value1, target.getValue()); -// source.set(value2); -// assertEquals(value2, target.getValue()); -// source.set(value1); -// } -// -// @Test -// public void testUnmodifiablePropertyStringProperty() { -// final String value1 = "Hello World"; -// final String value2 = "Goodbye"; -// final StringProperty source = new SimpleStringProperty(value1); -// final StringExpression target = Properties.unmodifiableProperty(source); -// -// assertEquals(value1, target.get()); -// source.set(value2); -// assertEquals(value2, target.get()); -// source.set(value1); -// -// assertEquals(value1, target.getValue()); -// source.set(value2); -// assertEquals(value2, target.getValue()); -// source.set(value1); -// } -// -//} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/PropertiesTest.java 2015-08-31 10:23:30.041217445 -0400 @@ -0,0 +1,177 @@ +package test.javafx.beans.property; + +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +//package javafx.beans.property; +// +//import static org.junit.Assert.assertEquals; +//import javafx.binding.expression.BooleanExpression; +//import javafx.binding.expression.DoubleExpression; +//import javafx.binding.expression.FloatExpression; +//import javafx.binding.expression.IntegerExpression; +//import javafx.binding.expression.LongExpression; +//import javafx.binding.expression.ObjectExpression; +//import javafx.binding.expression.StringExpression; +// +//import org.junit.Before; +//import org.junit.Test; +// +//public class PropertiesTest { +// +// private static final double EPSILON_DOUBLE = 1e-12; +// private static final float EPSILON_FLOAT = 1e-6f; +// +// @Before +// public void setUp() throws Exception { +// } +// +// @Test +// public void testUnmodifiablePropertyBooleanProperty() { +// final boolean value1 = true; +// final boolean value2 = false; +// final BooleanProperty source = new SimpleBooleanProperty(value1); +// final BooleanExpression target = Properties.unmodifiableProperty(source); +// +// assertEquals(value1, target.get()); +// source.set(value2); +// assertEquals(value2, target.get()); +// source.set(value1); +// +// assertEquals(value1, target.getValue()); +// source.set(value2); +// assertEquals(value2, target.getValue()); +// source.set(value1); +// } +// +// @Test +// public void testUnmodifiablePropertyDoubleProperty() { +// final double value1 = Math.PI; +// final double value2 = -Math.E; +// final DoubleProperty source = new SimpleDoubleProperty(value1); +// final DoubleExpression target = Properties.unmodifiableProperty(source); +// +// assertEquals(value1, target.get(), EPSILON_DOUBLE); +// source.set(value2); +// assertEquals(value2, target.get(), EPSILON_DOUBLE); +// source.set(value1); +// +// assertEquals(value1, target.getValue(), EPSILON_DOUBLE); +// source.set(value2); +// assertEquals(value2, target.getValue(), EPSILON_DOUBLE); +// source.set(value1); +// } +// +// @Test +// public void testUnmodifiablePropertyFloatProperty() { +// final float value1 = (float)Math.PI; +// final float value2 = (float)-Math.E; +// final FloatProperty source = new SimpleFloatProperty(value1); +// final FloatExpression target = Properties.unmodifiableProperty(source); +// +// assertEquals(value1, target.get(), EPSILON_FLOAT); +// source.set(value2); +// assertEquals(value2, target.get(), EPSILON_FLOAT); +// source.set(value1); +// +// assertEquals(value1, target.getValue(), EPSILON_FLOAT); +// source.set(value2); +// assertEquals(value2, target.getValue(), EPSILON_FLOAT); +// source.set(value1); +// } +// +// @Test +// public void testUnmodifiablePropertyIntegerProperty() { +// final int value1 = 42; +// final int value2 = 12345; +// final IntegerProperty source = new SimpleIntegerProperty(value1); +// final IntegerExpression target = Properties.unmodifiableProperty(source); +// +// assertEquals(value1, target.get()); +// source.set(value2); +// assertEquals(value2, target.get()); +// source.set(value1); +// +// assertEquals(Integer.valueOf(value1), target.getValue()); +// source.set(value2); +// assertEquals(Integer.valueOf(value2), target.getValue()); +// source.set(value1); +// } +// +// @Test +// public void testUnmodifiablePropertyLongProperty() { +// final long value1 = 98765432123456789L; +// final long value2 = -1234567890987654321L; +// final LongProperty source = new SimpleLongProperty(value1); +// final LongExpression target = Properties.unmodifiableProperty(source); +// +// assertEquals(value1, target.get()); +// source.set(value2); +// assertEquals(value2, target.get()); +// source.set(value1); +// +// assertEquals(Long.valueOf(value1), target.getValue()); +// source.set(value2); +// assertEquals(Long.valueOf(value2), target.getValue()); +// source.set(value1); +// } +// +// @Test +// public void testUnmodifiablePropertyObjectPropertyOfT() { +// final Object value1 = new Object(); +// final Object value2 = new Object(); +// final ObjectProperty source = new SimpleObjectProperty(value1); +// final ObjectExpression target = Properties.unmodifiableProperty(source); +// +// assertEquals(value1, target.get()); +// source.set(value2); +// assertEquals(value2, target.get()); +// source.set(value1); +// +// assertEquals(value1, target.getValue()); +// source.set(value2); +// assertEquals(value2, target.getValue()); +// source.set(value1); +// } +// +// @Test +// public void testUnmodifiablePropertyStringProperty() { +// final String value1 = "Hello World"; +// final String value2 = "Goodbye"; +// final StringProperty source = new SimpleStringProperty(value1); +// final StringExpression target = Properties.unmodifiableProperty(source); +// +// assertEquals(value1, target.get()); +// source.set(value2); +// assertEquals(value2, target.get()); +// source.set(value1); +// +// assertEquals(value1, target.getValue()); +// source.set(value2); +// assertEquals(value2, target.getValue()); +// source.set(value1); +// } +// +//} --- old/modules/base/src/test/java/javafx/beans/property/PropertyBaseTest.java 2015-08-31 10:23:30.985217434 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import com.sun.javafx.binding.ExpressionHelperUtility; -import java.util.Arrays; -import java.util.List; -import javafx.beans.value.ObservableNumberValue; -import javafx.beans.value.ObservableValue; -import javafx.beans.value.ObservableValueBase; -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -@RunWith(Parameterized.class) -public class PropertyBaseTest { - - @FunctionalInterface - public interface PropertyFactory { - public Property createProperty(); - } - - public static class Factory { - - private PropertyFactory propertyFactory; - private PropertyFactory observableFactory; - private T value; - - public Factory(PropertyFactory propertyFactory, - PropertyFactory observableFactory, T value) - { - this.propertyFactory = propertyFactory; - this.observableFactory = observableFactory; - this.value = value; - } - - public Property createProperty() { - return propertyFactory.createProperty(); - } - - public Property createObservable() { - return observableFactory.createProperty(); - } - - public T getValue() { - return value; - } - } - - private static class NumberPropertyMock extends ObservableValueBase - implements ObservableNumberValue, Property - { - private Number value = 0; - - @Override public int intValue() { return value.intValue(); } - @Override public long longValue() { return value.longValue(); } - @Override public float floatValue() { return value.floatValue(); } - @Override public double doubleValue() { return value.doubleValue(); } - @Override public Number getValue() { return value; } - @Override public void setValue(Number value) { - this.value = value; - fireValueChangedEvent(); - } - - @Override public void bind(ObservableValue observable) {} - @Override public void unbind() {} - @Override public boolean isBound() { return false; } - @Override public void bindBidirectional(Property other) {} - @Override public void unbindBidirectional(Property other) {} - - @Override public Object getBean() { return null; } - @Override public String getName() { return ""; } - } - - @Parameterized.Parameters - public static List data() { - return Arrays.asList(new Object[][] { - // primitive binding - // Property->Listener->Value - { new Factory(() -> new SimpleBooleanProperty(), () -> new SimpleBooleanProperty(), true) }, - { new Factory(() -> new SimpleDoubleProperty(), () -> new SimpleDoubleProperty(), 1.0) }, - { new Factory(() -> new SimpleFloatProperty(), () -> new SimpleFloatProperty(), 1.0f) }, - { new Factory(() -> new SimpleIntegerProperty(), () -> new SimpleIntegerProperty(), 1) }, - { new Factory(() -> new SimpleLongProperty(), () -> new SimpleLongProperty(), 1L) }, - // generic with wrapper - // Property->Listener->Binding->BindingHelperObserver->Value - { new Factory(() -> new SimpleBooleanProperty(), () -> new SimpleObjectProperty<>(), true) }, - { new Factory(() -> new SimpleDoubleProperty(), () -> new SimpleObjectProperty<>(), 1.0) }, - { new Factory(() -> new SimpleDoubleProperty(), () -> new NumberPropertyMock(), 1.0) }, - { new Factory(() -> new SimpleFloatProperty(), () -> new SimpleObjectProperty<>(), 1.0f) }, - { new Factory(() -> new SimpleFloatProperty(), () -> new NumberPropertyMock(), 1.0f) }, - { new Factory(() -> new SimpleIntegerProperty(), () -> new SimpleObjectProperty<>(), 1) }, - { new Factory(() -> new SimpleIntegerProperty(), () -> new NumberPropertyMock(), 1) }, - { new Factory(() -> new SimpleLongProperty(), () -> new SimpleObjectProperty<>(), 1L) }, - { new Factory(() -> new SimpleLongProperty(), () -> new NumberPropertyMock(), 1L) }, - // generic - // Property->Listener->Value - { new Factory(() -> new SimpleObjectProperty(), () -> new SimpleObjectProperty<>(), new Object()) }, - { new Factory(() -> new SimpleStringProperty(), () -> new SimpleObjectProperty<>(), "1") }, - // the same as generic - { new Factory(() -> new SimpleStringProperty(), () -> new SimpleStringProperty(), "1") }, - }); - } - - public PropertyBaseTest(Factory factory) { - this.factory = factory; - } - - @Before - public void setUp() { - property = factory.createProperty(); - observable = factory.createObservable(); - value = factory.getValue(); - } - - private Factory factory; - private Property property; - private Property observable; - private T value; - - @Test - public void testUnbindAfterInvalidation() { - property.bind(observable); - assertEquals(1, ExpressionHelperUtility.getInvalidationListeners(observable).size()); - - property = null; - System.gc(); - - observable.setValue(value); - assertEquals(0, ExpressionHelperUtility.getInvalidationListeners(observable).size()); - } - - @Test - public void testTrimAfterGC() { - Property p1 = factory.createProperty(); - Property p2 = factory.createProperty(); - p1.bind(observable); // creates SingleInvalidation - p2.bind(observable); // creates Generic with 2 listeners - assertEquals(2, ExpressionHelperUtility.getInvalidationListeners(observable).size()); - - p1 = null; - p2 = null; - System.gc(); - - property.bind(observable); // calls trim - assertEquals(1, ExpressionHelperUtility.getInvalidationListeners(observable).size()); - } - - @Test - public void testUnbindGenericWrapper() { - property.bind(observable); - assertEquals(1, ExpressionHelperUtility.getInvalidationListeners(observable).size()); - - property.unbind(); // should unbind wrapper from observable - assertEquals(0, ExpressionHelperUtility.getInvalidationListeners(observable).size()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/PropertyBaseTest.java 2015-08-31 10:23:30.781217436 -0400 @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import test.com.sun.javafx.binding.ExpressionHelperUtility; +import java.util.Arrays; +import java.util.List; +import javafx.beans.property.Property; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.value.ObservableNumberValue; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.ObservableValueBase; +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class PropertyBaseTest { + + @FunctionalInterface + public interface PropertyFactory { + public Property createProperty(); + } + + public static class Factory { + + private PropertyFactory propertyFactory; + private PropertyFactory observableFactory; + private T value; + + public Factory(PropertyFactory propertyFactory, + PropertyFactory observableFactory, T value) + { + this.propertyFactory = propertyFactory; + this.observableFactory = observableFactory; + this.value = value; + } + + public Property createProperty() { + return propertyFactory.createProperty(); + } + + public Property createObservable() { + return observableFactory.createProperty(); + } + + public T getValue() { + return value; + } + } + + private static class NumberPropertyMock extends ObservableValueBase + implements ObservableNumberValue, Property + { + private Number value = 0; + + @Override public int intValue() { return value.intValue(); } + @Override public long longValue() { return value.longValue(); } + @Override public float floatValue() { return value.floatValue(); } + @Override public double doubleValue() { return value.doubleValue(); } + @Override public Number getValue() { return value; } + @Override public void setValue(Number value) { + this.value = value; + fireValueChangedEvent(); + } + + @Override public void bind(ObservableValue observable) {} + @Override public void unbind() {} + @Override public boolean isBound() { return false; } + @Override public void bindBidirectional(Property other) {} + @Override public void unbindBidirectional(Property other) {} + + @Override public Object getBean() { return null; } + @Override public String getName() { return ""; } + } + + @Parameterized.Parameters + public static List data() { + return Arrays.asList(new Object[][] { + // primitive binding + // Property->Listener->Value + { new Factory(() -> new SimpleBooleanProperty(), () -> new SimpleBooleanProperty(), true) }, + { new Factory(() -> new SimpleDoubleProperty(), () -> new SimpleDoubleProperty(), 1.0) }, + { new Factory(() -> new SimpleFloatProperty(), () -> new SimpleFloatProperty(), 1.0f) }, + { new Factory(() -> new SimpleIntegerProperty(), () -> new SimpleIntegerProperty(), 1) }, + { new Factory(() -> new SimpleLongProperty(), () -> new SimpleLongProperty(), 1L) }, + // generic with wrapper + // Property->Listener->Binding->BindingHelperObserver->Value + { new Factory(() -> new SimpleBooleanProperty(), () -> new SimpleObjectProperty<>(), true) }, + { new Factory(() -> new SimpleDoubleProperty(), () -> new SimpleObjectProperty<>(), 1.0) }, + { new Factory(() -> new SimpleDoubleProperty(), () -> new NumberPropertyMock(), 1.0) }, + { new Factory(() -> new SimpleFloatProperty(), () -> new SimpleObjectProperty<>(), 1.0f) }, + { new Factory(() -> new SimpleFloatProperty(), () -> new NumberPropertyMock(), 1.0f) }, + { new Factory(() -> new SimpleIntegerProperty(), () -> new SimpleObjectProperty<>(), 1) }, + { new Factory(() -> new SimpleIntegerProperty(), () -> new NumberPropertyMock(), 1) }, + { new Factory(() -> new SimpleLongProperty(), () -> new SimpleObjectProperty<>(), 1L) }, + { new Factory(() -> new SimpleLongProperty(), () -> new NumberPropertyMock(), 1L) }, + // generic + // Property->Listener->Value + { new Factory(() -> new SimpleObjectProperty(), () -> new SimpleObjectProperty<>(), new Object()) }, + { new Factory(() -> new SimpleStringProperty(), () -> new SimpleObjectProperty<>(), "1") }, + // the same as generic + { new Factory(() -> new SimpleStringProperty(), () -> new SimpleStringProperty(), "1") }, + }); + } + + public PropertyBaseTest(Factory factory) { + this.factory = factory; + } + + @Before + public void setUp() { + property = factory.createProperty(); + observable = factory.createObservable(); + value = factory.getValue(); + } + + private Factory factory; + private Property property; + private Property observable; + private T value; + + @Test + public void testUnbindAfterInvalidation() { + property.bind(observable); + assertEquals(1, ExpressionHelperUtility.getInvalidationListeners(observable).size()); + + property = null; + System.gc(); + + observable.setValue(value); + assertEquals(0, ExpressionHelperUtility.getInvalidationListeners(observable).size()); + } + + @Test + public void testTrimAfterGC() { + Property p1 = factory.createProperty(); + Property p2 = factory.createProperty(); + p1.bind(observable); // creates SingleInvalidation + p2.bind(observable); // creates Generic with 2 listeners + assertEquals(2, ExpressionHelperUtility.getInvalidationListeners(observable).size()); + + p1 = null; + p2 = null; + System.gc(); + + property.bind(observable); // calls trim + assertEquals(1, ExpressionHelperUtility.getInvalidationListeners(observable).size()); + } + + @Test + public void testUnbindGenericWrapper() { + property.bind(observable); + assertEquals(1, ExpressionHelperUtility.getInvalidationListeners(observable).size()); + + property.unbind(); // should unbind wrapper from observable + assertEquals(0, ExpressionHelperUtility.getInvalidationListeners(observable).size()); + } +} --- old/modules/base/src/test/java/javafx/beans/property/PropertyReferenceTest.java 2015-08-31 10:23:31.593217427 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.*; -import javafx.beans.Person; - -import org.junit.Before; -import org.junit.Test; - -import com.sun.javafx.property.PropertyReference; - -public class PropertyReferenceTest { - - private Person person; - - @Before - public void setUp() { - person = new Person(); - } - - @Test - public void testInteger() { - final PropertyReference property = new PropertyReference(Person.class, "age"); - assertTrue(property.isReadable()); - assertTrue(property.isWritable()); - assertTrue((int.class.equals(property.getType())) || (Integer.class.equals(property.getType()))); - assertEquals(person.ageProperty(), property.getProperty(person)); - - assertEquals(0, person.getAge()); - assertEquals(Integer.valueOf(0), property.get(person)); - - property.set(person, 42); - assertEquals(42, person.getAge()); - assertEquals(Integer.valueOf(42), property.get(person)); - } - - @Test - public void testNoRead() { - final PropertyReference property = new PropertyReference(Person.class, "noRead"); - assertFalse(property.isReadable()); - assertTrue(property.isWritable()); - assertTrue((int.class.equals(property.getType())) || (Integer.class.equals(property.getType()))); - - assertEquals(0, person.noRead.get()); - property.set(person, -311); - assertEquals(-311, person.noRead.get()); - } - - @Test(expected=IllegalStateException.class) - public void testNoRead_IllegalRead() { - Person.NO_READ.get(person); - } - - @Test(expected=IllegalStateException.class) - public void testNoRead_IllegalReadProperty() { - Person.NO_READ.getProperty(person); - } - - @Test - public void testNoWrite() { - final PropertyReference property = new PropertyReference(Person.class, "noWrite"); - assertTrue(property.isReadable()); - assertFalse(property.isWritable()); - assertTrue((int.class.equals(property.getType())) || (Integer.class.equals(property.getType()))); - assertEquals(person.noWriteProperty(), property.getProperty(person)); - - assertEquals(0, person.getNoWrite()); - assertEquals(Integer.valueOf(0), property.get(person)); - - person.noWrite.set(5125); - assertEquals(5125, person.getNoWrite()); - assertEquals(Integer.valueOf(5125), property.get(person)); - } - - @Test(expected=IllegalStateException.class) - public void testNoWrite_IllegalWrite() { - Person.NO_WRITE.set(person, 1); - } - - @Test - public void testNoReadWrite() { - final PropertyReference property = new PropertyReference(Person.class, "noReadWrite"); - assertFalse(property.isReadable()); - assertFalse(property.isWritable()); - } - - @Test(expected=IllegalStateException.class) - public void testNoReadWrite_IllegalRead() { - Person.NO_READ_WRITE.get(person); - } - - @Test(expected=IllegalStateException.class) - public void testNoReadWrite_IllegalWrite() { - Person.NO_READ_WRITE.set(person, 1); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/PropertyReferenceTest.java 2015-08-31 10:23:31.461217429 -0400 @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import static org.junit.Assert.*; +import test.javafx.beans.Person; + +import org.junit.Before; +import org.junit.Test; + +import com.sun.javafx.property.PropertyReference; + +public class PropertyReferenceTest { + + private Person person; + + @Before + public void setUp() { + person = new Person(); + } + + @Test + public void testInteger() { + final PropertyReference property = new PropertyReference(Person.class, "age"); + assertTrue(property.isReadable()); + assertTrue(property.isWritable()); + assertTrue((int.class.equals(property.getType())) || (Integer.class.equals(property.getType()))); + assertEquals(person.ageProperty(), property.getProperty(person)); + + assertEquals(0, person.getAge()); + assertEquals(Integer.valueOf(0), property.get(person)); + + property.set(person, 42); + assertEquals(42, person.getAge()); + assertEquals(Integer.valueOf(42), property.get(person)); + } + + @Test + public void testNoRead() { + final PropertyReference property = new PropertyReference(Person.class, "noRead"); + assertFalse(property.isReadable()); + assertTrue(property.isWritable()); + assertTrue((int.class.equals(property.getType())) || (Integer.class.equals(property.getType()))); + + assertEquals(0, person.noRead.get()); + property.set(person, -311); + assertEquals(-311, person.noRead.get()); + } + + @Test(expected=IllegalStateException.class) + public void testNoRead_IllegalRead() { + Person.NO_READ.get(person); + } + + @Test(expected=IllegalStateException.class) + public void testNoRead_IllegalReadProperty() { + Person.NO_READ.getProperty(person); + } + + @Test + public void testNoWrite() { + final PropertyReference property = new PropertyReference(Person.class, "noWrite"); + assertTrue(property.isReadable()); + assertFalse(property.isWritable()); + assertTrue((int.class.equals(property.getType())) || (Integer.class.equals(property.getType()))); + assertEquals(person.noWriteProperty(), property.getProperty(person)); + + assertEquals(0, person.getNoWrite()); + assertEquals(Integer.valueOf(0), property.get(person)); + + person.noWrite.set(5125); + assertEquals(5125, person.getNoWrite()); + assertEquals(Integer.valueOf(5125), property.get(person)); + } + + @Test(expected=IllegalStateException.class) + public void testNoWrite_IllegalWrite() { + Person.NO_WRITE.set(person, 1); + } + + @Test + public void testNoReadWrite() { + final PropertyReference property = new PropertyReference(Person.class, "noReadWrite"); + assertFalse(property.isReadable()); + assertFalse(property.isWritable()); + } + + @Test(expected=IllegalStateException.class) + public void testNoReadWrite_IllegalRead() { + Person.NO_READ_WRITE.get(person); + } + + @Test(expected=IllegalStateException.class) + public void testNoReadWrite_IllegalWrite() { + Person.NO_READ_WRITE.set(person, 1); + } + +} --- old/modules/base/src/test/java/javafx/beans/property/PropertyReferenceWithInterfacesTest.java 2015-08-31 10:23:32.333217419 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.property.StringProperty; - -import org.junit.Before; -import org.junit.Test; - -import com.sun.javafx.property.PropertyReference; - -import static org.junit.Assert.*; - -/** - * - */ -public class PropertyReferenceWithInterfacesTest { - - @Before public void setUp() { - - } - - @Test public void shouldBeAbleToReadPropertyValueFromPropertyReferenceDeclaredOnInterface() { - NamedBean test = new NamedBean(); - test.setName("A"); - assertEquals("A", test.getName()); - assertEquals("A", Named.NAME.get(test)); - } - - public interface Named { - public static final PropertyReference NAME = new PropertyReference(Named.class, "name"); - public String getName(); - } - - public static class NamedBean implements Named { - private final StringProperty name = new SimpleStringProperty(); - @Override public final String getName() {return name.get();} - public final void setName(String value) {name.set(value);} - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/PropertyReferenceWithInterfacesTest.java 2015-08-31 10:23:32.141217421 -0400 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.StringProperty; + +import org.junit.Before; +import org.junit.Test; + +import com.sun.javafx.property.PropertyReference; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +import static org.junit.Assert.*; + +/** + * + */ +public class PropertyReferenceWithInterfacesTest { + + @Before public void setUp() { + + } + + @Test public void shouldBeAbleToReadPropertyValueFromPropertyReferenceDeclaredOnInterface() { + NamedBean test = new NamedBean(); + test.setName("A"); + assertEquals("A", test.getName()); + assertEquals("A", Named.NAME.get(test)); + } + + public interface Named { + public static final PropertyReference NAME = new PropertyReference(Named.class, "name"); + public String getName(); + } + + public static class NamedBean implements Named { + private final StringProperty name = new SimpleStringProperty(); + @Override public final String getName() {return name.get();} + public final void setName(String value) {name.set(value);} + } +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyBooleanPropertyBaseTest.java 2015-08-31 10:23:32.937217412 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyBooleanPropertyBaseTest { - - private static final Boolean UNDEFINED = null; - private static final boolean DEFAULT = false; - private static final boolean VALUE_1 = true; - private static final boolean VALUE_2 = false; - - private ReadOnlyPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - @Test - public void testInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_2); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(property, DEFAULT, VALUE_1, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_2); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - private static class ReadOnlyPropertyMock extends ReadOnlyBooleanPropertyBase { - - private boolean value; - - @Override - public Object getBean() { - // not used - return null; - } - - @Override - public String getName() { - // not used - return null; - } - - private void set(boolean value) { - this.value = value; - fireValueChangedEvent(); - } - - @Override - public boolean get() { - return value; - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyBooleanPropertyBaseTest.java 2015-08-31 10:23:32.801217414 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.ReadOnlyBooleanPropertyBase; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyBooleanPropertyBaseTest { + + private static final Boolean UNDEFINED = null; + private static final boolean DEFAULT = false; + private static final boolean VALUE_1 = true; + private static final boolean VALUE_2 = false; + + private ReadOnlyPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + @Test + public void testInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_2); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(property, DEFAULT, VALUE_1, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_2); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + private static class ReadOnlyPropertyMock extends ReadOnlyBooleanPropertyBase { + + private boolean value; + + @Override + public Object getBean() { + // not used + return null; + } + + @Override + public String getName() { + // not used + return null; + } + + private void set(boolean value) { + this.value = value; + fireValueChangedEvent(); + } + + @Override + public boolean get() { + return value; + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyBooleanPropertyTest.java 2015-08-31 10:23:33.765217403 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import javafx.beans.InvalidationListener; -import javafx.beans.binding.BooleanBinding; -import javafx.beans.binding.BooleanExpression; -import javafx.beans.binding.ObjectExpression; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.beans.value.ObservableValueStub; -import javafx.collections.FXCollections; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyBooleanPropertyTest { - - private static final boolean DEFAULT = false; - - @Before - public void setUp() throws Exception { - } - - @Test - public void testToString() { - final ReadOnlyBooleanProperty v1 = new ReadOnlyBooleanPropertyStub(null, ""); - assertEquals("ReadOnlyBooleanProperty [value: " + DEFAULT + "]", v1.toString()); - - final ReadOnlyBooleanProperty v2 = new ReadOnlyBooleanPropertyStub(null, null); - assertEquals("ReadOnlyBooleanProperty [value: " + DEFAULT + "]", v2.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyBooleanProperty v3 = new ReadOnlyBooleanPropertyStub(bean, name); - assertEquals("ReadOnlyBooleanProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); - - final ReadOnlyBooleanProperty v4 = new ReadOnlyBooleanPropertyStub(bean, ""); - assertEquals("ReadOnlyBooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - - final ReadOnlyBooleanProperty v5 = new ReadOnlyBooleanPropertyStub(bean, null); - assertEquals("ReadOnlyBooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); - - final ReadOnlyBooleanProperty v6 = new ReadOnlyBooleanPropertyStub(null, name); - assertEquals("ReadOnlyBooleanProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); - - } - - @Test - public void testAsObject() { - final ReadOnlyBooleanWrapper valueModel = new ReadOnlyBooleanWrapper(); - final ReadOnlyObjectProperty exp = valueModel.getReadOnlyProperty().asObject(); - - assertEquals(Boolean.FALSE, exp.get()); - valueModel.set(true); - assertEquals(Boolean.TRUE, exp.get()); - valueModel.set(false); - assertEquals(Boolean.FALSE, exp.get()); - } - - @Test - public void testObjectToBoolean() { - final ReadOnlyObjectWrapper valueModel = new ReadOnlyObjectWrapper(); - final ReadOnlyBooleanProperty exp = ReadOnlyBooleanProperty.readOnlyBooleanProperty(valueModel.getReadOnlyProperty()); - - - assertEquals(false, exp.get()); - valueModel.set(true); - assertEquals(true, exp.get()); - valueModel.set(false); - assertEquals(false, exp.get()); - } - - - private static class ReadOnlyBooleanPropertyStub extends ReadOnlyBooleanProperty { - - private final Object bean; - private final String name; - - private ReadOnlyBooleanPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override public Object getBean() { return bean; } - @Override public String getName() { return name; } - @Override public boolean get() { return false; } - - @Override - public void addListener(ChangeListener listener) { - } - - @Override - public void removeListener(ChangeListener listener) { - } - - @Override - public void addListener(InvalidationListener listener) { - } - - @Override - public void removeListener(InvalidationListener listener) { - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyBooleanPropertyTest.java 2015-08-31 10:23:33.561217405 -0400 @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import javafx.beans.InvalidationListener; +import javafx.beans.binding.BooleanBinding; +import javafx.beans.binding.BooleanExpression; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyBooleanWrapper; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.ObservableValueStub; +import javafx.collections.FXCollections; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyBooleanPropertyTest { + + private static final boolean DEFAULT = false; + + @Before + public void setUp() throws Exception { + } + + @Test + public void testToString() { + final ReadOnlyBooleanProperty v1 = new ReadOnlyBooleanPropertyStub(null, ""); + assertEquals("ReadOnlyBooleanProperty [value: " + DEFAULT + "]", v1.toString()); + + final ReadOnlyBooleanProperty v2 = new ReadOnlyBooleanPropertyStub(null, null); + assertEquals("ReadOnlyBooleanProperty [value: " + DEFAULT + "]", v2.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyBooleanProperty v3 = new ReadOnlyBooleanPropertyStub(bean, name); + assertEquals("ReadOnlyBooleanProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); + + final ReadOnlyBooleanProperty v4 = new ReadOnlyBooleanPropertyStub(bean, ""); + assertEquals("ReadOnlyBooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + + final ReadOnlyBooleanProperty v5 = new ReadOnlyBooleanPropertyStub(bean, null); + assertEquals("ReadOnlyBooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); + + final ReadOnlyBooleanProperty v6 = new ReadOnlyBooleanPropertyStub(null, name); + assertEquals("ReadOnlyBooleanProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); + + } + + @Test + public void testAsObject() { + final ReadOnlyBooleanWrapper valueModel = new ReadOnlyBooleanWrapper(); + final ReadOnlyObjectProperty exp = valueModel.getReadOnlyProperty().asObject(); + + assertEquals(Boolean.FALSE, exp.get()); + valueModel.set(true); + assertEquals(Boolean.TRUE, exp.get()); + valueModel.set(false); + assertEquals(Boolean.FALSE, exp.get()); + } + + @Test + public void testObjectToBoolean() { + final ReadOnlyObjectWrapper valueModel = new ReadOnlyObjectWrapper(); + final ReadOnlyBooleanProperty exp = ReadOnlyBooleanProperty.readOnlyBooleanProperty(valueModel.getReadOnlyProperty()); + + + assertEquals(false, exp.get()); + valueModel.set(true); + assertEquals(true, exp.get()); + valueModel.set(false); + assertEquals(false, exp.get()); + } + + + private static class ReadOnlyBooleanPropertyStub extends ReadOnlyBooleanProperty { + + private final Object bean; + private final String name; + + private ReadOnlyBooleanPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override public Object getBean() { return bean; } + @Override public String getName() { return name; } + @Override public boolean get() { return false; } + + @Override + public void addListener(ChangeListener listener) { + } + + @Override + public void removeListener(ChangeListener listener) { + } + + @Override + public void addListener(InvalidationListener listener) { + } + + @Override + public void removeListener(InvalidationListener listener) { + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyBooleanWrapperTest.java 2015-08-31 10:23:34.445217395 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,758 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableBooleanValueStub; -import javafx.beans.value.ObservableObjectValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyBooleanWrapperTest { - - private static final Boolean UNDEFINED = null; - private static final boolean DEFAULT = false; - private static final boolean VALUE_1 = true; - private static final boolean VALUE_2 = false; - - private ReadOnlyBooleanWrapperMock property; - private ReadOnlyBooleanProperty readOnlyProperty; - private InvalidationListenerMock internalInvalidationListener; - private InvalidationListenerMock publicInvalidationListener; - private ChangeListenerMock internalChangeListener; - private ChangeListenerMock publicChangeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyBooleanWrapperMock(); - readOnlyProperty = property.getReadOnlyProperty(); - internalInvalidationListener = new InvalidationListenerMock(); - publicInvalidationListener = new InvalidationListenerMock(); - internalChangeListener = new ChangeListenerMock(UNDEFINED); - publicChangeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListeners() { - property.addListener(internalInvalidationListener); - readOnlyProperty.addListener(publicInvalidationListener); - property.get(); - readOnlyProperty.get(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - } - - private void attachInternalChangeListener() { - property.addListener(internalChangeListener); - property.get(); - internalChangeListener.reset(); - } - - private void attachPublicChangeListener() { - readOnlyProperty.addListener(publicChangeListener); - readOnlyProperty.get(); - publicChangeListener.reset(); - } - - @Test - public void testConstructor_NoArguments() { - final ReadOnlyBooleanWrapper p1 = new ReadOnlyBooleanWrapper(); - assertEquals(DEFAULT, p1.get()); - assertEquals((Boolean)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyBooleanProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Boolean)DEFAULT, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_InitialValue() { - final ReadOnlyBooleanWrapper p1 = new ReadOnlyBooleanWrapper(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Boolean)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyBooleanProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Boolean)VALUE_1, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyBooleanWrapper p1 = new ReadOnlyBooleanWrapper(bean, name); - assertEquals(DEFAULT, p1.get()); - assertEquals((Boolean)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyBooleanProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Boolean)DEFAULT, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyBooleanWrapper p1 = new ReadOnlyBooleanWrapper(bean, name, VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Boolean)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyBooleanProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Boolean)VALUE_1, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testLazySet() { - attachInvalidationListeners(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSet() { - attachInternalChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSet() { - attachPublicChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListeners(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSetValue() { - attachInternalChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSetValue() { - attachPublicChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final BooleanProperty v = new SimpleBooleanProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind_primitive() { - attachInvalidationListeners(); - final ObservableBooleanValueStub v = new ObservableBooleanValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_primitive() { - attachInternalChangeListener(); - final ObservableBooleanValueStub v = new ObservableBooleanValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_primitive() { - attachPublicChangeListener(); - final ObservableBooleanValueStub v = new ObservableBooleanValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test - public void testLazyBind_generic() { - attachInvalidationListeners(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_generic() { - attachInternalChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_generic() { - attachPublicChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListeners(); - final BooleanProperty v1 = new SimpleBooleanProperty(VALUE_1); - final BooleanProperty v2 = new SimpleBooleanProperty(VALUE_2); - property.bind(v1); - property.get(); - readOnlyProperty.get(); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change new binding - v2.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change old binding - v1.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListeners(); - final BooleanProperty v = new SimpleBooleanProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get()); - assertFalse(property.isBound()); - assertEquals(VALUE_1, readOnlyProperty.get()); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final BooleanProperty v = new SimpleBooleanProperty(VALUE_1); - final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); - - // setting the property,checking internal - property.set(VALUE_1); - property.addListener(internalListener2); - internalListener2.reset(); - property.set(VALUE_2); - internalListener2.check(property, 1); - - // setting the property, checking public - property.set(VALUE_1); - readOnlyProperty.addListener(publicListener2); - publicListener2.reset(); - property.set(VALUE_2); - publicListener2.check(readOnlyProperty, 1); - - // binding the property, checking internal - property.bind(v); - v.set(VALUE_2); - property.addListener(internalListener3); - v.get(); - internalListener3.reset(); - v.set(VALUE_1); - internalListener3.check(property, 1); - - // binding the property, checking public - property.bind(v); - v.set(VALUE_2); - readOnlyProperty.addListener(publicListener3); - v.get(); - publicListener3.reset(); - v.set(VALUE_1); - publicListener3.check(readOnlyProperty, 1); - } - - @Test - public void testRemoveListeners() { - attachInvalidationListeners(); - attachInternalChangeListener(); - property.removeListener(internalInvalidationListener); - property.removeListener(internalChangeListener); - property.get(); - internalInvalidationListener.reset(); - internalChangeListener.reset(); - - property.set(VALUE_1); - internalInvalidationListener.check(null, 0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // no read only property created => no-op - final ReadOnlyBooleanWrapper v1 = new ReadOnlyBooleanWrapper(); - v1.removeListener(internalInvalidationListener); - v1.removeListener(internalChangeListener); - } - - @Test - public void testNoReadOnlyPropertyCreated() { - final BooleanProperty v1 = new SimpleBooleanProperty(VALUE_1); - final ReadOnlyBooleanWrapper p1 = new ReadOnlyBooleanWrapper(); - - p1.set(VALUE_1); - p1.bind(v1); - assertEquals(VALUE_1, p1.get()); - v1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - } - - @Test - public void testToString() { - final BooleanProperty v1 = new SimpleBooleanProperty(VALUE_1); - - property.set(VALUE_1); - assertEquals("BooleanProperty [value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyBooleanProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - - property.bind(v1); - assertEquals("BooleanProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyBooleanProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("BooleanProperty [bound, value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyBooleanProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - v1.set(VALUE_2); - assertEquals("BooleanProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyBooleanProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("BooleanProperty [bound, value: " + VALUE_2 + "]", property.toString()); - assertEquals("ReadOnlyBooleanProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyBooleanWrapper v2 = new ReadOnlyBooleanWrapper(bean, name); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - assertEquals("ReadOnlyBooleanProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); - - final ReadOnlyBooleanWrapper v3 = new ReadOnlyBooleanWrapper(bean, ""); - assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - assertEquals("ReadOnlyBooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); - - final ReadOnlyBooleanWrapper v4 = new ReadOnlyBooleanWrapper(null, name); - assertEquals("BooleanProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); - assertEquals("ReadOnlyBooleanProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); - } - - private static class ReadOnlyBooleanWrapperMock extends ReadOnlyBooleanWrapper { - - private int counter; - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyBooleanWrapperTest.java 2015-08-31 10:23:34.309217397 -0400 @@ -0,0 +1,762 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyBooleanWrapper; +import javafx.beans.property.SimpleBooleanProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableBooleanValueStub; +import javafx.beans.value.ObservableObjectValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyBooleanWrapperTest { + + private static final Boolean UNDEFINED = null; + private static final boolean DEFAULT = false; + private static final boolean VALUE_1 = true; + private static final boolean VALUE_2 = false; + + private ReadOnlyBooleanWrapperMock property; + private ReadOnlyBooleanProperty readOnlyProperty; + private InvalidationListenerMock internalInvalidationListener; + private InvalidationListenerMock publicInvalidationListener; + private ChangeListenerMock internalChangeListener; + private ChangeListenerMock publicChangeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyBooleanWrapperMock(); + readOnlyProperty = property.getReadOnlyProperty(); + internalInvalidationListener = new InvalidationListenerMock(); + publicInvalidationListener = new InvalidationListenerMock(); + internalChangeListener = new ChangeListenerMock(UNDEFINED); + publicChangeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListeners() { + property.addListener(internalInvalidationListener); + readOnlyProperty.addListener(publicInvalidationListener); + property.get(); + readOnlyProperty.get(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + } + + private void attachInternalChangeListener() { + property.addListener(internalChangeListener); + property.get(); + internalChangeListener.reset(); + } + + private void attachPublicChangeListener() { + readOnlyProperty.addListener(publicChangeListener); + readOnlyProperty.get(); + publicChangeListener.reset(); + } + + @Test + public void testConstructor_NoArguments() { + final ReadOnlyBooleanWrapper p1 = new ReadOnlyBooleanWrapper(); + assertEquals(DEFAULT, p1.get()); + assertEquals((Boolean)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyBooleanProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Boolean)DEFAULT, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_InitialValue() { + final ReadOnlyBooleanWrapper p1 = new ReadOnlyBooleanWrapper(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Boolean)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyBooleanProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Boolean)VALUE_1, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyBooleanWrapper p1 = new ReadOnlyBooleanWrapper(bean, name); + assertEquals(DEFAULT, p1.get()); + assertEquals((Boolean)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyBooleanProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Boolean)DEFAULT, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyBooleanWrapper p1 = new ReadOnlyBooleanWrapper(bean, name, VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Boolean)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyBooleanProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Boolean)VALUE_1, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testLazySet() { + attachInvalidationListeners(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSet() { + attachInternalChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSet() { + attachPublicChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListeners(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSetValue() { + attachInternalChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSetValue() { + attachPublicChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final BooleanProperty v = new SimpleBooleanProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind_primitive() { + attachInvalidationListeners(); + final ObservableBooleanValueStub v = new ObservableBooleanValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_primitive() { + attachInternalChangeListener(); + final ObservableBooleanValueStub v = new ObservableBooleanValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_primitive() { + attachPublicChangeListener(); + final ObservableBooleanValueStub v = new ObservableBooleanValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test + public void testLazyBind_generic() { + attachInvalidationListeners(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_generic() { + attachInternalChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_generic() { + attachPublicChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListeners(); + final BooleanProperty v1 = new SimpleBooleanProperty(VALUE_1); + final BooleanProperty v2 = new SimpleBooleanProperty(VALUE_2); + property.bind(v1); + property.get(); + readOnlyProperty.get(); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change new binding + v2.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change old binding + v1.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListeners(); + final BooleanProperty v = new SimpleBooleanProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get()); + assertFalse(property.isBound()); + assertEquals(VALUE_1, readOnlyProperty.get()); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final BooleanProperty v = new SimpleBooleanProperty(VALUE_1); + final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); + + // setting the property,checking internal + property.set(VALUE_1); + property.addListener(internalListener2); + internalListener2.reset(); + property.set(VALUE_2); + internalListener2.check(property, 1); + + // setting the property, checking public + property.set(VALUE_1); + readOnlyProperty.addListener(publicListener2); + publicListener2.reset(); + property.set(VALUE_2); + publicListener2.check(readOnlyProperty, 1); + + // binding the property, checking internal + property.bind(v); + v.set(VALUE_2); + property.addListener(internalListener3); + v.get(); + internalListener3.reset(); + v.set(VALUE_1); + internalListener3.check(property, 1); + + // binding the property, checking public + property.bind(v); + v.set(VALUE_2); + readOnlyProperty.addListener(publicListener3); + v.get(); + publicListener3.reset(); + v.set(VALUE_1); + publicListener3.check(readOnlyProperty, 1); + } + + @Test + public void testRemoveListeners() { + attachInvalidationListeners(); + attachInternalChangeListener(); + property.removeListener(internalInvalidationListener); + property.removeListener(internalChangeListener); + property.get(); + internalInvalidationListener.reset(); + internalChangeListener.reset(); + + property.set(VALUE_1); + internalInvalidationListener.check(null, 0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // no read only property created => no-op + final ReadOnlyBooleanWrapper v1 = new ReadOnlyBooleanWrapper(); + v1.removeListener(internalInvalidationListener); + v1.removeListener(internalChangeListener); + } + + @Test + public void testNoReadOnlyPropertyCreated() { + final BooleanProperty v1 = new SimpleBooleanProperty(VALUE_1); + final ReadOnlyBooleanWrapper p1 = new ReadOnlyBooleanWrapper(); + + p1.set(VALUE_1); + p1.bind(v1); + assertEquals(VALUE_1, p1.get()); + v1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + } + + @Test + public void testToString() { + final BooleanProperty v1 = new SimpleBooleanProperty(VALUE_1); + + property.set(VALUE_1); + assertEquals("BooleanProperty [value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyBooleanProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + + property.bind(v1); + assertEquals("BooleanProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyBooleanProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("BooleanProperty [bound, value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyBooleanProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + v1.set(VALUE_2); + assertEquals("BooleanProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyBooleanProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("BooleanProperty [bound, value: " + VALUE_2 + "]", property.toString()); + assertEquals("ReadOnlyBooleanProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyBooleanWrapper v2 = new ReadOnlyBooleanWrapper(bean, name); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + assertEquals("ReadOnlyBooleanProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); + + final ReadOnlyBooleanWrapper v3 = new ReadOnlyBooleanWrapper(bean, ""); + assertEquals("BooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + assertEquals("ReadOnlyBooleanProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); + + final ReadOnlyBooleanWrapper v4 = new ReadOnlyBooleanWrapper(null, name); + assertEquals("BooleanProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); + assertEquals("ReadOnlyBooleanProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); + } + + private static class ReadOnlyBooleanWrapperMock extends ReadOnlyBooleanWrapper { + + private int counter; + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyDoublePropertyBaseTest.java 2015-08-31 10:23:35.149217387 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyDoublePropertyBaseTest { - - private static final Double UNDEFINED = null; - private static final double DEFAULT = 0.0; - private static final double VALUE_1 = -Math.PI; - private static final double VALUE_2 = Math.E; - - private ReadOnlyPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - @Test - public void testInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_2); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(property, DEFAULT, VALUE_1, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_2); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - private static class ReadOnlyPropertyMock extends ReadOnlyDoublePropertyBase { - - private double value; - - @Override - public Object getBean() { - // not used - return null; - } - - @Override - public String getName() { - // not used - return null; - } - - private void set(double value) { - this.value = value; - fireValueChangedEvent(); - } - - @Override - public double get() { - return value; - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyDoublePropertyBaseTest.java 2015-08-31 10:23:35.013217389 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.ReadOnlyDoublePropertyBase; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyDoublePropertyBaseTest { + + private static final Double UNDEFINED = null; + private static final double DEFAULT = 0.0; + private static final double VALUE_1 = -Math.PI; + private static final double VALUE_2 = Math.E; + + private ReadOnlyPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + @Test + public void testInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_2); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(property, DEFAULT, VALUE_1, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_2); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + private static class ReadOnlyPropertyMock extends ReadOnlyDoublePropertyBase { + + private double value; + + @Override + public Object getBean() { + // not used + return null; + } + + @Override + public String getName() { + // not used + return null; + } + + private void set(double value) { + this.value = value; + fireValueChangedEvent(); + } + + @Override + public double get() { + return value; + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyDoublePropertyTest.java 2015-08-31 10:23:35.845217379 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import javafx.beans.InvalidationListener; -import javafx.beans.binding.ObjectExpression; -import javafx.beans.value.ChangeListener; -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyDoublePropertyTest { - - private static final double DEFAULT = 0.0; - private static final float EPSILON = 1e-6f; - - @Before - public void setUp() throws Exception { - } - - @Test - public void testToString() { - final ReadOnlyDoubleProperty v1 = new ReadOnlyDoublePropertyStub(null, ""); - assertEquals("ReadOnlyDoubleProperty [value: " + DEFAULT + "]", v1.toString()); - - final ReadOnlyDoubleProperty v2 = new ReadOnlyDoublePropertyStub(null, null); - assertEquals("ReadOnlyDoubleProperty [value: " + DEFAULT + "]", v2.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyDoubleProperty v3 = new ReadOnlyDoublePropertyStub(bean, name); - assertEquals("ReadOnlyDoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); - - final ReadOnlyDoubleProperty v4 = new ReadOnlyDoublePropertyStub(bean, ""); - assertEquals("ReadOnlyDoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - - final ReadOnlyDoubleProperty v5 = new ReadOnlyDoublePropertyStub(bean, null); - assertEquals("ReadOnlyDoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); - - final ReadOnlyDoubleProperty v6 = new ReadOnlyDoublePropertyStub(null, name); - assertEquals("ReadOnlyDoubleProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); - - } - - @Test - public void testAsObject() { - final ReadOnlyDoubleWrapper valueModel = new ReadOnlyDoubleWrapper(); - final ReadOnlyObjectProperty exp = valueModel.getReadOnlyProperty().asObject(); - - assertEquals(0.0, exp.getValue(), EPSILON); - valueModel.set(-4354.3); - assertEquals(-4354.3, exp.getValue(), EPSILON); - valueModel.set(5e11); - assertEquals(5e11, exp.getValue(), EPSILON); - } - - @Test - public void testObjectToDouble() { - final ReadOnlyObjectWrapper valueModel = new ReadOnlyObjectWrapper(); - final ReadOnlyDoubleProperty exp = ReadOnlyDoubleProperty.readOnlyDoubleProperty(valueModel.getReadOnlyProperty()); - - - assertEquals(0.0, exp.doubleValue(), EPSILON); - valueModel.set(-4354.3); - assertEquals(-4354.3, exp.doubleValue(), EPSILON); - valueModel.set(5e11); - assertEquals(5e11, exp.doubleValue(), EPSILON); - } - - private static class ReadOnlyDoublePropertyStub extends ReadOnlyDoubleProperty { - - private final Object bean; - private final String name; - - private ReadOnlyDoublePropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override public Object getBean() { return bean; } - @Override public String getName() { return name; } - @Override public double get() { return 0.0; } - - @Override - public void addListener(ChangeListener listener) { - } - - @Override - public void removeListener(ChangeListener listener) { - } - - @Override - public void addListener(InvalidationListener listener) { - } - - @Override - public void removeListener(InvalidationListener listener) { - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyDoublePropertyTest.java 2015-08-31 10:23:35.713217381 -0400 @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import javafx.beans.InvalidationListener; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.property.ReadOnlyDoubleProperty; +import javafx.beans.property.ReadOnlyDoubleWrapper; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.beans.value.ChangeListener; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyDoublePropertyTest { + + private static final double DEFAULT = 0.0; + private static final float EPSILON = 1e-6f; + + @Before + public void setUp() throws Exception { + } + + @Test + public void testToString() { + final ReadOnlyDoubleProperty v1 = new ReadOnlyDoublePropertyStub(null, ""); + assertEquals("ReadOnlyDoubleProperty [value: " + DEFAULT + "]", v1.toString()); + + final ReadOnlyDoubleProperty v2 = new ReadOnlyDoublePropertyStub(null, null); + assertEquals("ReadOnlyDoubleProperty [value: " + DEFAULT + "]", v2.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyDoubleProperty v3 = new ReadOnlyDoublePropertyStub(bean, name); + assertEquals("ReadOnlyDoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); + + final ReadOnlyDoubleProperty v4 = new ReadOnlyDoublePropertyStub(bean, ""); + assertEquals("ReadOnlyDoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + + final ReadOnlyDoubleProperty v5 = new ReadOnlyDoublePropertyStub(bean, null); + assertEquals("ReadOnlyDoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); + + final ReadOnlyDoubleProperty v6 = new ReadOnlyDoublePropertyStub(null, name); + assertEquals("ReadOnlyDoubleProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); + + } + + @Test + public void testAsObject() { + final ReadOnlyDoubleWrapper valueModel = new ReadOnlyDoubleWrapper(); + final ReadOnlyObjectProperty exp = valueModel.getReadOnlyProperty().asObject(); + + assertEquals(0.0, exp.getValue(), EPSILON); + valueModel.set(-4354.3); + assertEquals(-4354.3, exp.getValue(), EPSILON); + valueModel.set(5e11); + assertEquals(5e11, exp.getValue(), EPSILON); + } + + @Test + public void testObjectToDouble() { + final ReadOnlyObjectWrapper valueModel = new ReadOnlyObjectWrapper(); + final ReadOnlyDoubleProperty exp = ReadOnlyDoubleProperty.readOnlyDoubleProperty(valueModel.getReadOnlyProperty()); + + + assertEquals(0.0, exp.doubleValue(), EPSILON); + valueModel.set(-4354.3); + assertEquals(-4354.3, exp.doubleValue(), EPSILON); + valueModel.set(5e11); + assertEquals(5e11, exp.doubleValue(), EPSILON); + } + + private static class ReadOnlyDoublePropertyStub extends ReadOnlyDoubleProperty { + + private final Object bean; + private final String name; + + private ReadOnlyDoublePropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override public Object getBean() { return bean; } + @Override public String getName() { return name; } + @Override public double get() { return 0.0; } + + @Override + public void addListener(ChangeListener listener) { + } + + @Override + public void removeListener(ChangeListener listener) { + } + + @Override + public void addListener(InvalidationListener listener) { + } + + @Override + public void removeListener(InvalidationListener listener) { + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyDoubleWrapperTest.java 2015-08-31 10:23:36.441217373 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,759 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableDoubleValueStub; -import javafx.beans.value.ObservableObjectValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyDoubleWrapperTest { - - private static final Double UNDEFINED = null; - private static final double DEFAULT = 0.0; - private static final double VALUE_1 = Math.PI; - private static final double VALUE_2 = Math.E; - private static final double EPSILON = 1e-12; - - private ReadOnlyDoubleWrapperMock property; - private ReadOnlyDoubleProperty readOnlyProperty; - private InvalidationListenerMock internalInvalidationListener; - private InvalidationListenerMock publicInvalidationListener; - private ChangeListenerMock internalChangeListener; - private ChangeListenerMock publicChangeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyDoubleWrapperMock(); - readOnlyProperty = property.getReadOnlyProperty(); - internalInvalidationListener = new InvalidationListenerMock(); - publicInvalidationListener = new InvalidationListenerMock(); - internalChangeListener = new ChangeListenerMock(UNDEFINED); - publicChangeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListeners() { - property.addListener(internalInvalidationListener); - readOnlyProperty.addListener(publicInvalidationListener); - property.get(); - readOnlyProperty.get(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - } - - private void attachInternalChangeListener() { - property.addListener(internalChangeListener); - property.get(); - internalChangeListener.reset(); - } - - private void attachPublicChangeListener() { - readOnlyProperty.addListener(publicChangeListener); - readOnlyProperty.get(); - publicChangeListener.reset(); - } - - @Test - public void testConstructor_NoArguments() { - final ReadOnlyDoubleWrapper p1 = new ReadOnlyDoubleWrapper(); - assertEquals(DEFAULT, p1.get(), EPSILON); - assertEquals((Double)DEFAULT, p1.getValue(), EPSILON); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyDoubleProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get(), EPSILON); - assertEquals((Double)DEFAULT, r1.getValue(), EPSILON); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_InitialValue() { - final ReadOnlyDoubleWrapper p1 = new ReadOnlyDoubleWrapper(VALUE_1); - assertEquals(VALUE_1, p1.get(), EPSILON); - assertEquals((Double)VALUE_1, p1.getValue(), EPSILON); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyDoubleProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get(), EPSILON); - assertEquals((Double)VALUE_1, r1.getValue(), EPSILON); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyDoubleWrapper p1 = new ReadOnlyDoubleWrapper(bean, name); - assertEquals(DEFAULT, p1.get(), EPSILON); - assertEquals((Double)DEFAULT, p1.getValue(), EPSILON); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyDoubleProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get(), EPSILON); - assertEquals((Double)DEFAULT, r1.getValue(), EPSILON); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyDoubleWrapper p1 = new ReadOnlyDoubleWrapper(bean, name, VALUE_1); - assertEquals(VALUE_1, p1.get(), EPSILON); - assertEquals((Double)VALUE_1, p1.getValue(), EPSILON); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyDoubleProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get(), EPSILON); - assertEquals((Double)VALUE_1, r1.getValue(), EPSILON); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testLazySet() { - attachInvalidationListeners(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSet() { - attachInternalChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - } - - @Test - public void testPublicEagerSet() { - attachPublicChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListeners(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSetValue() { - attachInternalChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - } - - @Test - public void testPublicEagerSetValue() { - attachPublicChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final DoubleProperty v = new SimpleDoubleProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind_primitive() { - attachInvalidationListeners(); - final ObservableDoubleValueStub v = new ObservableDoubleValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_primitive() { - attachInternalChangeListener(); - final ObservableDoubleValueStub v = new ObservableDoubleValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - } - - @Test - public void testPublicEagerBind_primitive() { - attachPublicChangeListener(); - final ObservableDoubleValueStub v = new ObservableDoubleValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test - public void testLazyBind_generic() { - attachInvalidationListeners(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_generic() { - attachInternalChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - } - - @Test - public void testPublicEagerBind_generic() { - attachPublicChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListeners(); - final DoubleProperty v1 = new SimpleDoubleProperty(VALUE_1); - final DoubleProperty v2 = new SimpleDoubleProperty(VALUE_2); - property.bind(v1); - property.get(); - readOnlyProperty.get(); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change new binding - v2.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change old binding - v1.set(VALUE_2); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(null, 0); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListeners(); - final DoubleProperty v = new SimpleDoubleProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get(), EPSILON); - assertFalse(property.isBound()); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(null, 0); - - // set value - property.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final DoubleProperty v = new SimpleDoubleProperty(VALUE_1); - final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); - - // setting the property,checking internal - property.set(VALUE_1); - property.addListener(internalListener2); - internalListener2.reset(); - property.set(VALUE_2); - internalListener2.check(property, 1); - - // setting the property, checking public - property.set(VALUE_1); - readOnlyProperty.addListener(publicListener2); - publicListener2.reset(); - property.set(VALUE_2); - publicListener2.check(readOnlyProperty, 1); - - // binding the property, checking internal - property.bind(v); - v.set(VALUE_2); - property.addListener(internalListener3); - v.get(); - internalListener3.reset(); - v.set(VALUE_1); - internalListener3.check(property, 1); - - // binding the property, checking public - property.bind(v); - v.set(VALUE_2); - readOnlyProperty.addListener(publicListener3); - v.get(); - publicListener3.reset(); - v.set(VALUE_1); - publicListener3.check(readOnlyProperty, 1); - } - - @Test - public void testRemoveListeners() { - attachInvalidationListeners(); - attachInternalChangeListener(); - property.removeListener(internalInvalidationListener); - property.removeListener(internalChangeListener); - property.get(); - internalInvalidationListener.reset(); - internalChangeListener.reset(); - - property.set(VALUE_1); - internalInvalidationListener.check(null, 0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // no read only property created => no-op - final ReadOnlyDoubleWrapper v1 = new ReadOnlyDoubleWrapper(); - v1.removeListener(internalInvalidationListener); - v1.removeListener(internalChangeListener); - } - - @Test - public void testNoReadOnlyPropertyCreated() { - final DoubleProperty v1 = new SimpleDoubleProperty(VALUE_1); - final ReadOnlyDoubleWrapper p1 = new ReadOnlyDoubleWrapper(); - - p1.set(VALUE_1); - p1.bind(v1); - assertEquals(VALUE_1, p1.get(), EPSILON); - v1.set(VALUE_2); - assertEquals(VALUE_2, p1.get(), EPSILON); - } - - @Test - public void testToString() { - final DoubleProperty v1 = new SimpleDoubleProperty(VALUE_1); - - property.set(VALUE_1); - assertEquals("DoubleProperty [value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyDoubleProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - - property.bind(v1); - assertEquals("DoubleProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyDoubleProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("DoubleProperty [bound, value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyDoubleProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - v1.set(VALUE_2); - assertEquals("DoubleProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyDoubleProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("DoubleProperty [bound, value: " + VALUE_2 + "]", property.toString()); - assertEquals("ReadOnlyDoubleProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyDoubleWrapper v2 = new ReadOnlyDoubleWrapper(bean, name); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - assertEquals("ReadOnlyDoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); - - final ReadOnlyDoubleWrapper v3 = new ReadOnlyDoubleWrapper(bean, ""); - assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - assertEquals("ReadOnlyDoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); - - final ReadOnlyDoubleWrapper v4 = new ReadOnlyDoubleWrapper(null, name); - assertEquals("DoubleProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); - assertEquals("ReadOnlyDoubleProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); - } - - private static class ReadOnlyDoubleWrapperMock extends ReadOnlyDoubleWrapper { - - private int counter; - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyDoubleWrapperTest.java 2015-08-31 10:23:36.309217374 -0400 @@ -0,0 +1,763 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.ReadOnlyDoubleProperty; +import javafx.beans.property.ReadOnlyDoubleWrapper; +import javafx.beans.property.SimpleDoubleProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableDoubleValueStub; +import javafx.beans.value.ObservableObjectValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyDoubleWrapperTest { + + private static final Double UNDEFINED = null; + private static final double DEFAULT = 0.0; + private static final double VALUE_1 = Math.PI; + private static final double VALUE_2 = Math.E; + private static final double EPSILON = 1e-12; + + private ReadOnlyDoubleWrapperMock property; + private ReadOnlyDoubleProperty readOnlyProperty; + private InvalidationListenerMock internalInvalidationListener; + private InvalidationListenerMock publicInvalidationListener; + private ChangeListenerMock internalChangeListener; + private ChangeListenerMock publicChangeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyDoubleWrapperMock(); + readOnlyProperty = property.getReadOnlyProperty(); + internalInvalidationListener = new InvalidationListenerMock(); + publicInvalidationListener = new InvalidationListenerMock(); + internalChangeListener = new ChangeListenerMock(UNDEFINED); + publicChangeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListeners() { + property.addListener(internalInvalidationListener); + readOnlyProperty.addListener(publicInvalidationListener); + property.get(); + readOnlyProperty.get(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + } + + private void attachInternalChangeListener() { + property.addListener(internalChangeListener); + property.get(); + internalChangeListener.reset(); + } + + private void attachPublicChangeListener() { + readOnlyProperty.addListener(publicChangeListener); + readOnlyProperty.get(); + publicChangeListener.reset(); + } + + @Test + public void testConstructor_NoArguments() { + final ReadOnlyDoubleWrapper p1 = new ReadOnlyDoubleWrapper(); + assertEquals(DEFAULT, p1.get(), EPSILON); + assertEquals((Double)DEFAULT, p1.getValue(), EPSILON); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyDoubleProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get(), EPSILON); + assertEquals((Double)DEFAULT, r1.getValue(), EPSILON); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_InitialValue() { + final ReadOnlyDoubleWrapper p1 = new ReadOnlyDoubleWrapper(VALUE_1); + assertEquals(VALUE_1, p1.get(), EPSILON); + assertEquals((Double)VALUE_1, p1.getValue(), EPSILON); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyDoubleProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get(), EPSILON); + assertEquals((Double)VALUE_1, r1.getValue(), EPSILON); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyDoubleWrapper p1 = new ReadOnlyDoubleWrapper(bean, name); + assertEquals(DEFAULT, p1.get(), EPSILON); + assertEquals((Double)DEFAULT, p1.getValue(), EPSILON); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyDoubleProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get(), EPSILON); + assertEquals((Double)DEFAULT, r1.getValue(), EPSILON); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyDoubleWrapper p1 = new ReadOnlyDoubleWrapper(bean, name, VALUE_1); + assertEquals(VALUE_1, p1.get(), EPSILON); + assertEquals((Double)VALUE_1, p1.getValue(), EPSILON); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyDoubleProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get(), EPSILON); + assertEquals((Double)VALUE_1, r1.getValue(), EPSILON); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testLazySet() { + attachInvalidationListeners(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSet() { + attachInternalChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + } + + @Test + public void testPublicEagerSet() { + attachPublicChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListeners(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSetValue() { + attachInternalChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + } + + @Test + public void testPublicEagerSetValue() { + attachPublicChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final DoubleProperty v = new SimpleDoubleProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind_primitive() { + attachInvalidationListeners(); + final ObservableDoubleValueStub v = new ObservableDoubleValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_primitive() { + attachInternalChangeListener(); + final ObservableDoubleValueStub v = new ObservableDoubleValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + } + + @Test + public void testPublicEagerBind_primitive() { + attachPublicChangeListener(); + final ObservableDoubleValueStub v = new ObservableDoubleValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test + public void testLazyBind_generic() { + attachInvalidationListeners(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_generic() { + attachInternalChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + } + + @Test + public void testPublicEagerBind_generic() { + attachPublicChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListeners(); + final DoubleProperty v1 = new SimpleDoubleProperty(VALUE_1); + final DoubleProperty v2 = new SimpleDoubleProperty(VALUE_2); + property.bind(v1); + property.get(); + readOnlyProperty.get(); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change new binding + v2.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change old binding + v1.set(VALUE_2); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(null, 0); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListeners(); + final DoubleProperty v = new SimpleDoubleProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get(), EPSILON); + assertFalse(property.isBound()); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(null, 0); + + // set value + property.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final DoubleProperty v = new SimpleDoubleProperty(VALUE_1); + final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); + + // setting the property,checking internal + property.set(VALUE_1); + property.addListener(internalListener2); + internalListener2.reset(); + property.set(VALUE_2); + internalListener2.check(property, 1); + + // setting the property, checking public + property.set(VALUE_1); + readOnlyProperty.addListener(publicListener2); + publicListener2.reset(); + property.set(VALUE_2); + publicListener2.check(readOnlyProperty, 1); + + // binding the property, checking internal + property.bind(v); + v.set(VALUE_2); + property.addListener(internalListener3); + v.get(); + internalListener3.reset(); + v.set(VALUE_1); + internalListener3.check(property, 1); + + // binding the property, checking public + property.bind(v); + v.set(VALUE_2); + readOnlyProperty.addListener(publicListener3); + v.get(); + publicListener3.reset(); + v.set(VALUE_1); + publicListener3.check(readOnlyProperty, 1); + } + + @Test + public void testRemoveListeners() { + attachInvalidationListeners(); + attachInternalChangeListener(); + property.removeListener(internalInvalidationListener); + property.removeListener(internalChangeListener); + property.get(); + internalInvalidationListener.reset(); + internalChangeListener.reset(); + + property.set(VALUE_1); + internalInvalidationListener.check(null, 0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // no read only property created => no-op + final ReadOnlyDoubleWrapper v1 = new ReadOnlyDoubleWrapper(); + v1.removeListener(internalInvalidationListener); + v1.removeListener(internalChangeListener); + } + + @Test + public void testNoReadOnlyPropertyCreated() { + final DoubleProperty v1 = new SimpleDoubleProperty(VALUE_1); + final ReadOnlyDoubleWrapper p1 = new ReadOnlyDoubleWrapper(); + + p1.set(VALUE_1); + p1.bind(v1); + assertEquals(VALUE_1, p1.get(), EPSILON); + v1.set(VALUE_2); + assertEquals(VALUE_2, p1.get(), EPSILON); + } + + @Test + public void testToString() { + final DoubleProperty v1 = new SimpleDoubleProperty(VALUE_1); + + property.set(VALUE_1); + assertEquals("DoubleProperty [value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyDoubleProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + + property.bind(v1); + assertEquals("DoubleProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyDoubleProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("DoubleProperty [bound, value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyDoubleProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + v1.set(VALUE_2); + assertEquals("DoubleProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyDoubleProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("DoubleProperty [bound, value: " + VALUE_2 + "]", property.toString()); + assertEquals("ReadOnlyDoubleProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyDoubleWrapper v2 = new ReadOnlyDoubleWrapper(bean, name); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + assertEquals("ReadOnlyDoubleProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); + + final ReadOnlyDoubleWrapper v3 = new ReadOnlyDoubleWrapper(bean, ""); + assertEquals("DoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + assertEquals("ReadOnlyDoubleProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); + + final ReadOnlyDoubleWrapper v4 = new ReadOnlyDoubleWrapper(null, name); + assertEquals("DoubleProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); + assertEquals("ReadOnlyDoubleProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); + } + + private static class ReadOnlyDoubleWrapperMock extends ReadOnlyDoubleWrapper { + + private int counter; + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyFloatPropertyBaseTest.java 2015-08-31 10:23:37.261217363 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyFloatPropertyBaseTest { - - private static final Float UNDEFINED = null; - private static final float DEFAULT = 0.0f; - private static final float VALUE_1 = (float)Math.E; - private static final float VALUE_2 = (float)Math.PI; - - private ReadOnlyPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - @Test - public void testInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_2); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(property, DEFAULT, VALUE_1, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_2); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - private static class ReadOnlyPropertyMock extends ReadOnlyFloatPropertyBase { - - private float value; - - @Override - public Object getBean() { - // not used - return null; - } - - @Override - public String getName() { - // not used - return null; - } - - private void set(float value) { - this.value = value; - fireValueChangedEvent(); - } - - @Override - public float get() { - return value; - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyFloatPropertyBaseTest.java 2015-08-31 10:23:37.053217366 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.ReadOnlyFloatPropertyBase; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyFloatPropertyBaseTest { + + private static final Float UNDEFINED = null; + private static final float DEFAULT = 0.0f; + private static final float VALUE_1 = (float)Math.E; + private static final float VALUE_2 = (float)Math.PI; + + private ReadOnlyPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + @Test + public void testInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_2); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(property, DEFAULT, VALUE_1, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_2); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + private static class ReadOnlyPropertyMock extends ReadOnlyFloatPropertyBase { + + private float value; + + @Override + public Object getBean() { + // not used + return null; + } + + @Override + public String getName() { + // not used + return null; + } + + private void set(float value) { + this.value = value; + fireValueChangedEvent(); + } + + @Override + public float get() { + return value; + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyFloatPropertyTest.java 2015-08-31 10:23:37.877217356 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import javafx.beans.InvalidationListener; -import javafx.beans.binding.ObjectExpression; -import javafx.beans.value.ChangeListener; -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyFloatPropertyTest { - - private static final float DEFAULT = 0.0f; - private static final float EPSILON = 1e-6f; - - @Before - public void setUp() throws Exception { - } - - @Test - public void testToString() { - final ReadOnlyFloatProperty v1 = new ReadOnlyFloatPropertyStub(null, ""); - assertEquals("ReadOnlyFloatProperty [value: " + DEFAULT + "]", v1.toString()); - - final ReadOnlyFloatProperty v2 = new ReadOnlyFloatPropertyStub(null, null); - assertEquals("ReadOnlyFloatProperty [value: " + DEFAULT + "]", v2.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyFloatProperty v3 = new ReadOnlyFloatPropertyStub(bean, name); - assertEquals("ReadOnlyFloatProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); - - final ReadOnlyFloatProperty v4 = new ReadOnlyFloatPropertyStub(bean, ""); - assertEquals("ReadOnlyFloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - - final ReadOnlyFloatProperty v5 = new ReadOnlyFloatPropertyStub(bean, null); - assertEquals("ReadOnlyFloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); - - final ReadOnlyFloatProperty v6 = new ReadOnlyFloatPropertyStub(null, name); - assertEquals("ReadOnlyFloatProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); - - } - - @Test - public void testAsObject() { - final ReadOnlyFloatWrapper valueModel = new ReadOnlyFloatWrapper(); - final ReadOnlyObjectProperty exp = valueModel.getReadOnlyProperty().asObject(); - - assertEquals(0.0, exp.getValue(), EPSILON); - valueModel.set(-4354.3f); - assertEquals(-4354.3f, exp.getValue(), EPSILON); - valueModel.set(5e11f); - assertEquals(5e11f, exp.getValue(), EPSILON); - } - - @Test - public void testObjectToFloat() { - final ReadOnlyObjectWrapper valueModel = new ReadOnlyObjectWrapper(); - final ReadOnlyFloatProperty exp = ReadOnlyFloatProperty.readOnlyFloatProperty(valueModel.getReadOnlyProperty()); - - - assertEquals(0.0, exp.floatValue(), EPSILON); - valueModel.set(-4354.3f); - assertEquals(-4354.3f, exp.floatValue(), EPSILON); - valueModel.set(5e11f); - assertEquals(5e11f, exp.floatValue(), EPSILON); - } - - private static class ReadOnlyFloatPropertyStub extends ReadOnlyFloatProperty { - - private final Object bean; - private final String name; - - private ReadOnlyFloatPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override public Object getBean() { return bean; } - @Override public String getName() { return name; } - @Override public float get() { return 0.0f; } - - @Override - public void addListener(ChangeListener listener) { - } - - @Override - public void removeListener(ChangeListener listener) { - } - - @Override - public void addListener(InvalidationListener listener) { - } - - @Override - public void removeListener(InvalidationListener listener) { - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyFloatPropertyTest.java 2015-08-31 10:23:37.741217358 -0400 @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import javafx.beans.InvalidationListener; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.property.ReadOnlyFloatProperty; +import javafx.beans.property.ReadOnlyFloatWrapper; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.beans.value.ChangeListener; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyFloatPropertyTest { + + private static final float DEFAULT = 0.0f; + private static final float EPSILON = 1e-6f; + + @Before + public void setUp() throws Exception { + } + + @Test + public void testToString() { + final ReadOnlyFloatProperty v1 = new ReadOnlyFloatPropertyStub(null, ""); + assertEquals("ReadOnlyFloatProperty [value: " + DEFAULT + "]", v1.toString()); + + final ReadOnlyFloatProperty v2 = new ReadOnlyFloatPropertyStub(null, null); + assertEquals("ReadOnlyFloatProperty [value: " + DEFAULT + "]", v2.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyFloatProperty v3 = new ReadOnlyFloatPropertyStub(bean, name); + assertEquals("ReadOnlyFloatProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); + + final ReadOnlyFloatProperty v4 = new ReadOnlyFloatPropertyStub(bean, ""); + assertEquals("ReadOnlyFloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + + final ReadOnlyFloatProperty v5 = new ReadOnlyFloatPropertyStub(bean, null); + assertEquals("ReadOnlyFloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); + + final ReadOnlyFloatProperty v6 = new ReadOnlyFloatPropertyStub(null, name); + assertEquals("ReadOnlyFloatProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); + + } + + @Test + public void testAsObject() { + final ReadOnlyFloatWrapper valueModel = new ReadOnlyFloatWrapper(); + final ReadOnlyObjectProperty exp = valueModel.getReadOnlyProperty().asObject(); + + assertEquals(0.0, exp.getValue(), EPSILON); + valueModel.set(-4354.3f); + assertEquals(-4354.3f, exp.getValue(), EPSILON); + valueModel.set(5e11f); + assertEquals(5e11f, exp.getValue(), EPSILON); + } + + @Test + public void testObjectToFloat() { + final ReadOnlyObjectWrapper valueModel = new ReadOnlyObjectWrapper(); + final ReadOnlyFloatProperty exp = ReadOnlyFloatProperty.readOnlyFloatProperty(valueModel.getReadOnlyProperty()); + + + assertEquals(0.0, exp.floatValue(), EPSILON); + valueModel.set(-4354.3f); + assertEquals(-4354.3f, exp.floatValue(), EPSILON); + valueModel.set(5e11f); + assertEquals(5e11f, exp.floatValue(), EPSILON); + } + + private static class ReadOnlyFloatPropertyStub extends ReadOnlyFloatProperty { + + private final Object bean; + private final String name; + + private ReadOnlyFloatPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override public Object getBean() { return bean; } + @Override public String getName() { return name; } + @Override public float get() { return 0.0f; } + + @Override + public void addListener(ChangeListener listener) { + } + + @Override + public void removeListener(ChangeListener listener) { + } + + @Override + public void addListener(InvalidationListener listener) { + } + + @Override + public void removeListener(InvalidationListener listener) { + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyFloatWrapperTest.java 2015-08-31 10:23:38.481217350 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,759 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableFloatValueStub; -import javafx.beans.value.ObservableObjectValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyFloatWrapperTest { - - private static final Float UNDEFINED = null; - private static final float DEFAULT = 0.0f; - private static final float VALUE_1 = (float)Math.PI; - private static final float VALUE_2 = (float)Math.E; - private static final float EPSILON = 1e-6f; - - private ReadOnlyFloatWrapperMock property; - private ReadOnlyFloatProperty readOnlyProperty; - private InvalidationListenerMock internalInvalidationListener; - private InvalidationListenerMock publicInvalidationListener; - private ChangeListenerMock internalChangeListener; - private ChangeListenerMock publicChangeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyFloatWrapperMock(); - readOnlyProperty = property.getReadOnlyProperty(); - internalInvalidationListener = new InvalidationListenerMock(); - publicInvalidationListener = new InvalidationListenerMock(); - internalChangeListener = new ChangeListenerMock(UNDEFINED); - publicChangeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListeners() { - property.addListener(internalInvalidationListener); - readOnlyProperty.addListener(publicInvalidationListener); - property.get(); - readOnlyProperty.get(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - } - - private void attachInternalChangeListener() { - property.addListener(internalChangeListener); - property.get(); - internalChangeListener.reset(); - } - - private void attachPublicChangeListener() { - readOnlyProperty.addListener(publicChangeListener); - readOnlyProperty.get(); - publicChangeListener.reset(); - } - - @Test - public void testConstructor_NoArguments() { - final ReadOnlyFloatWrapper p1 = new ReadOnlyFloatWrapper(); - assertEquals(DEFAULT, p1.get(), EPSILON); - assertEquals((Float)DEFAULT, p1.getValue(), EPSILON); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyFloatProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get(), EPSILON); - assertEquals((Float)DEFAULT, r1.getValue(), EPSILON); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_InitialValue() { - final ReadOnlyFloatWrapper p1 = new ReadOnlyFloatWrapper(VALUE_1); - assertEquals(VALUE_1, p1.get(), EPSILON); - assertEquals((Float)VALUE_1, p1.getValue(), EPSILON); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyFloatProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get(), EPSILON); - assertEquals((Float)VALUE_1, r1.getValue(), EPSILON); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyFloatWrapper p1 = new ReadOnlyFloatWrapper(bean, name); - assertEquals(DEFAULT, p1.get(), EPSILON); - assertEquals((Float)DEFAULT, p1.getValue(), EPSILON); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyFloatProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get(), EPSILON); - assertEquals((Float)DEFAULT, r1.getValue(), EPSILON); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyFloatWrapper p1 = new ReadOnlyFloatWrapper(bean, name, VALUE_1); - assertEquals(VALUE_1, p1.get(), EPSILON); - assertEquals((Float)VALUE_1, p1.getValue(), EPSILON); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyFloatProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get(), EPSILON); - assertEquals((Float)VALUE_1, r1.getValue(), EPSILON); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testLazySet() { - attachInvalidationListeners(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSet() { - attachInternalChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - } - - @Test - public void testPublicEagerSet() { - attachPublicChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListeners(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSetValue() { - attachInternalChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - } - - @Test - public void testPublicEagerSetValue() { - attachPublicChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final FloatProperty v = new SimpleFloatProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind_primitive() { - attachInvalidationListeners(); - final ObservableFloatValueStub v = new ObservableFloatValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_primitive() { - attachInternalChangeListener(); - final ObservableFloatValueStub v = new ObservableFloatValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - } - - @Test - public void testPublicEagerBind_primitive() { - attachPublicChangeListener(); - final ObservableFloatValueStub v = new ObservableFloatValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test - public void testLazyBind_generic() { - attachInvalidationListeners(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_generic() { - attachInternalChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - } - - @Test - public void testPublicEagerBind_generic() { - attachPublicChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListeners(); - final FloatProperty v1 = new SimpleFloatProperty(VALUE_1); - final FloatProperty v2 = new SimpleFloatProperty(VALUE_2); - property.bind(v1); - property.get(); - readOnlyProperty.get(); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change new binding - v2.set(VALUE_1); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change old binding - v1.set(VALUE_2); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(null, 0); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_1, property.get(), EPSILON); - assertTrue(property.isBound()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListeners(); - final FloatProperty v = new SimpleFloatProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get(), EPSILON); - assertFalse(property.isBound()); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get(), EPSILON); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(null, 0); - - // set value - property.set(VALUE_2); - assertEquals(VALUE_2, property.get(), EPSILON); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final FloatProperty v = new SimpleFloatProperty(VALUE_1); - final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); - - // setting the property,checking internal - property.set(VALUE_1); - property.addListener(internalListener2); - internalListener2.reset(); - property.set(VALUE_2); - internalListener2.check(property, 1); - - // setting the property, checking public - property.set(VALUE_1); - readOnlyProperty.addListener(publicListener2); - publicListener2.reset(); - property.set(VALUE_2); - publicListener2.check(readOnlyProperty, 1); - - // binding the property, checking internal - property.bind(v); - v.set(VALUE_2); - property.addListener(internalListener3); - v.get(); - internalListener3.reset(); - v.set(VALUE_1); - internalListener3.check(property, 1); - - // binding the property, checking public - property.bind(v); - v.set(VALUE_2); - readOnlyProperty.addListener(publicListener3); - v.get(); - publicListener3.reset(); - v.set(VALUE_1); - publicListener3.check(readOnlyProperty, 1); - } - - @Test - public void testRemoveListeners() { - attachInvalidationListeners(); - attachInternalChangeListener(); - property.removeListener(internalInvalidationListener); - property.removeListener(internalChangeListener); - property.get(); - internalInvalidationListener.reset(); - internalChangeListener.reset(); - - property.set(VALUE_1); - internalInvalidationListener.check(null, 0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // no read only property created => no-op - final ReadOnlyFloatWrapper v1 = new ReadOnlyFloatWrapper(); - v1.removeListener(internalInvalidationListener); - v1.removeListener(internalChangeListener); - } - - @Test - public void testNoReadOnlyPropertyCreated() { - final FloatProperty v1 = new SimpleFloatProperty(VALUE_1); - final ReadOnlyFloatWrapper p1 = new ReadOnlyFloatWrapper(); - - p1.set(VALUE_1); - p1.bind(v1); - assertEquals(VALUE_1, p1.get(), EPSILON); - v1.set(VALUE_2); - assertEquals(VALUE_2, p1.get(), EPSILON); - } - - @Test - public void testToString() { - final FloatProperty v1 = new SimpleFloatProperty(VALUE_1); - - property.set(VALUE_1); - assertEquals("FloatProperty [value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyFloatProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - - property.bind(v1); - assertEquals("FloatProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyFloatProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("FloatProperty [bound, value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyFloatProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - v1.set(VALUE_2); - assertEquals("FloatProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyFloatProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("FloatProperty [bound, value: " + VALUE_2 + "]", property.toString()); - assertEquals("ReadOnlyFloatProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyFloatWrapper v2 = new ReadOnlyFloatWrapper(bean, name); - assertEquals("FloatProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - assertEquals("ReadOnlyFloatProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); - - final ReadOnlyFloatWrapper v3 = new ReadOnlyFloatWrapper(bean, ""); - assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - assertEquals("ReadOnlyFloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); - - final ReadOnlyFloatWrapper v4 = new ReadOnlyFloatWrapper(null, name); - assertEquals("FloatProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); - assertEquals("ReadOnlyFloatProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); - } - - private static class ReadOnlyFloatWrapperMock extends ReadOnlyFloatWrapper { - - private int counter; - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyFloatWrapperTest.java 2015-08-31 10:23:38.345217351 -0400 @@ -0,0 +1,763 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.FloatProperty; +import javafx.beans.property.ReadOnlyFloatProperty; +import javafx.beans.property.ReadOnlyFloatWrapper; +import javafx.beans.property.SimpleFloatProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableFloatValueStub; +import javafx.beans.value.ObservableObjectValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyFloatWrapperTest { + + private static final Float UNDEFINED = null; + private static final float DEFAULT = 0.0f; + private static final float VALUE_1 = (float)Math.PI; + private static final float VALUE_2 = (float)Math.E; + private static final float EPSILON = 1e-6f; + + private ReadOnlyFloatWrapperMock property; + private ReadOnlyFloatProperty readOnlyProperty; + private InvalidationListenerMock internalInvalidationListener; + private InvalidationListenerMock publicInvalidationListener; + private ChangeListenerMock internalChangeListener; + private ChangeListenerMock publicChangeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyFloatWrapperMock(); + readOnlyProperty = property.getReadOnlyProperty(); + internalInvalidationListener = new InvalidationListenerMock(); + publicInvalidationListener = new InvalidationListenerMock(); + internalChangeListener = new ChangeListenerMock(UNDEFINED); + publicChangeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListeners() { + property.addListener(internalInvalidationListener); + readOnlyProperty.addListener(publicInvalidationListener); + property.get(); + readOnlyProperty.get(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + } + + private void attachInternalChangeListener() { + property.addListener(internalChangeListener); + property.get(); + internalChangeListener.reset(); + } + + private void attachPublicChangeListener() { + readOnlyProperty.addListener(publicChangeListener); + readOnlyProperty.get(); + publicChangeListener.reset(); + } + + @Test + public void testConstructor_NoArguments() { + final ReadOnlyFloatWrapper p1 = new ReadOnlyFloatWrapper(); + assertEquals(DEFAULT, p1.get(), EPSILON); + assertEquals((Float)DEFAULT, p1.getValue(), EPSILON); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyFloatProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get(), EPSILON); + assertEquals((Float)DEFAULT, r1.getValue(), EPSILON); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_InitialValue() { + final ReadOnlyFloatWrapper p1 = new ReadOnlyFloatWrapper(VALUE_1); + assertEquals(VALUE_1, p1.get(), EPSILON); + assertEquals((Float)VALUE_1, p1.getValue(), EPSILON); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyFloatProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get(), EPSILON); + assertEquals((Float)VALUE_1, r1.getValue(), EPSILON); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyFloatWrapper p1 = new ReadOnlyFloatWrapper(bean, name); + assertEquals(DEFAULT, p1.get(), EPSILON); + assertEquals((Float)DEFAULT, p1.getValue(), EPSILON); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyFloatProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get(), EPSILON); + assertEquals((Float)DEFAULT, r1.getValue(), EPSILON); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyFloatWrapper p1 = new ReadOnlyFloatWrapper(bean, name, VALUE_1); + assertEquals(VALUE_1, p1.get(), EPSILON); + assertEquals((Float)VALUE_1, p1.getValue(), EPSILON); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyFloatProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get(), EPSILON); + assertEquals((Float)VALUE_1, r1.getValue(), EPSILON); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testLazySet() { + attachInvalidationListeners(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSet() { + attachInternalChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + } + + @Test + public void testPublicEagerSet() { + attachPublicChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListeners(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSetValue() { + attachInternalChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + } + + @Test + public void testPublicEagerSetValue() { + attachPublicChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final FloatProperty v = new SimpleFloatProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind_primitive() { + attachInvalidationListeners(); + final ObservableFloatValueStub v = new ObservableFloatValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_primitive() { + attachInternalChangeListener(); + final ObservableFloatValueStub v = new ObservableFloatValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + } + + @Test + public void testPublicEagerBind_primitive() { + attachPublicChangeListener(); + final ObservableFloatValueStub v = new ObservableFloatValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test + public void testLazyBind_generic() { + attachInvalidationListeners(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_generic() { + attachInternalChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + } + + @Test + public void testPublicEagerBind_generic() { + attachPublicChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListeners(); + final FloatProperty v1 = new SimpleFloatProperty(VALUE_1); + final FloatProperty v2 = new SimpleFloatProperty(VALUE_2); + property.bind(v1); + property.get(); + readOnlyProperty.get(); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change new binding + v2.set(VALUE_1); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change old binding + v1.set(VALUE_2); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(null, 0); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_1, property.get(), EPSILON); + assertTrue(property.isBound()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListeners(); + final FloatProperty v = new SimpleFloatProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get(), EPSILON); + assertFalse(property.isBound()); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get(), EPSILON); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(null, 0); + + // set value + property.set(VALUE_2); + assertEquals(VALUE_2, property.get(), EPSILON); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get(), EPSILON); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final FloatProperty v = new SimpleFloatProperty(VALUE_1); + final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); + + // setting the property,checking internal + property.set(VALUE_1); + property.addListener(internalListener2); + internalListener2.reset(); + property.set(VALUE_2); + internalListener2.check(property, 1); + + // setting the property, checking public + property.set(VALUE_1); + readOnlyProperty.addListener(publicListener2); + publicListener2.reset(); + property.set(VALUE_2); + publicListener2.check(readOnlyProperty, 1); + + // binding the property, checking internal + property.bind(v); + v.set(VALUE_2); + property.addListener(internalListener3); + v.get(); + internalListener3.reset(); + v.set(VALUE_1); + internalListener3.check(property, 1); + + // binding the property, checking public + property.bind(v); + v.set(VALUE_2); + readOnlyProperty.addListener(publicListener3); + v.get(); + publicListener3.reset(); + v.set(VALUE_1); + publicListener3.check(readOnlyProperty, 1); + } + + @Test + public void testRemoveListeners() { + attachInvalidationListeners(); + attachInternalChangeListener(); + property.removeListener(internalInvalidationListener); + property.removeListener(internalChangeListener); + property.get(); + internalInvalidationListener.reset(); + internalChangeListener.reset(); + + property.set(VALUE_1); + internalInvalidationListener.check(null, 0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // no read only property created => no-op + final ReadOnlyFloatWrapper v1 = new ReadOnlyFloatWrapper(); + v1.removeListener(internalInvalidationListener); + v1.removeListener(internalChangeListener); + } + + @Test + public void testNoReadOnlyPropertyCreated() { + final FloatProperty v1 = new SimpleFloatProperty(VALUE_1); + final ReadOnlyFloatWrapper p1 = new ReadOnlyFloatWrapper(); + + p1.set(VALUE_1); + p1.bind(v1); + assertEquals(VALUE_1, p1.get(), EPSILON); + v1.set(VALUE_2); + assertEquals(VALUE_2, p1.get(), EPSILON); + } + + @Test + public void testToString() { + final FloatProperty v1 = new SimpleFloatProperty(VALUE_1); + + property.set(VALUE_1); + assertEquals("FloatProperty [value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyFloatProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + + property.bind(v1); + assertEquals("FloatProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyFloatProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("FloatProperty [bound, value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyFloatProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + v1.set(VALUE_2); + assertEquals("FloatProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyFloatProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("FloatProperty [bound, value: " + VALUE_2 + "]", property.toString()); + assertEquals("ReadOnlyFloatProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyFloatWrapper v2 = new ReadOnlyFloatWrapper(bean, name); + assertEquals("FloatProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + assertEquals("ReadOnlyFloatProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); + + final ReadOnlyFloatWrapper v3 = new ReadOnlyFloatWrapper(bean, ""); + assertEquals("FloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + assertEquals("ReadOnlyFloatProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); + + final ReadOnlyFloatWrapper v4 = new ReadOnlyFloatWrapper(null, name); + assertEquals("FloatProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); + assertEquals("ReadOnlyFloatProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); + } + + private static class ReadOnlyFloatWrapperMock extends ReadOnlyFloatWrapper { + + private int counter; + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyIntegerPropertyBaseTest.java 2015-08-31 10:23:39.189217342 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyIntegerPropertyBaseTest { - - private static final Integer UNDEFINED = null; - private static final int DEFAULT = 0; - private static final int VALUE_1 = -7; - private static final int VALUE_2 = 42; - - private ReadOnlyPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - @Test - public void testInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_2); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(property, DEFAULT, VALUE_1, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_2); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - private static class ReadOnlyPropertyMock extends ReadOnlyIntegerPropertyBase { - - private int value; - - @Override - public Object getBean() { - // not used - return null; - } - - @Override - public String getName() { - // not used - return null; - } - - private void set(int value) { - this.value = value; - fireValueChangedEvent(); - } - - @Override - public int get() { - return value; - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyIntegerPropertyBaseTest.java 2015-08-31 10:23:39.057217343 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.ReadOnlyIntegerPropertyBase; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyIntegerPropertyBaseTest { + + private static final Integer UNDEFINED = null; + private static final int DEFAULT = 0; + private static final int VALUE_1 = -7; + private static final int VALUE_2 = 42; + + private ReadOnlyPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + @Test + public void testInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_2); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(property, DEFAULT, VALUE_1, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_2); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + private static class ReadOnlyPropertyMock extends ReadOnlyIntegerPropertyBase { + + private int value; + + @Override + public Object getBean() { + // not used + return null; + } + + @Override + public String getName() { + // not used + return null; + } + + private void set(int value) { + this.value = value; + fireValueChangedEvent(); + } + + @Override + public int get() { + return value; + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyIntegerPropertyTest.java 2015-08-31 10:23:39.813217335 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import javafx.beans.InvalidationListener; -import javafx.beans.binding.ObjectExpression; -import javafx.beans.value.ChangeListener; -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyIntegerPropertyTest { - - private static final int DEFAULT = 0; - - @Before - public void setUp() throws Exception { - } - - @Test - public void testToString() { - final ReadOnlyIntegerProperty v1 = new ReadOnlyIntegerPropertyStub(null, ""); - assertEquals("ReadOnlyIntegerProperty [value: " + DEFAULT + "]", v1.toString()); - - final ReadOnlyIntegerProperty v2 = new ReadOnlyIntegerPropertyStub(null, null); - assertEquals("ReadOnlyIntegerProperty [value: " + DEFAULT + "]", v2.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyIntegerProperty v3 = new ReadOnlyIntegerPropertyStub(bean, name); - assertEquals("ReadOnlyIntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); - - final ReadOnlyIntegerProperty v4 = new ReadOnlyIntegerPropertyStub(bean, ""); - assertEquals("ReadOnlyIntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - - final ReadOnlyIntegerProperty v5 = new ReadOnlyIntegerPropertyStub(bean, null); - assertEquals("ReadOnlyIntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); - - final ReadOnlyIntegerProperty v6 = new ReadOnlyIntegerPropertyStub(null, name); - assertEquals("ReadOnlyIntegerProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); - - } - - @Test - public void testAsObject() { - final ReadOnlyIntegerWrapper valueModel = new ReadOnlyIntegerWrapper(); - final ReadOnlyObjectProperty exp = valueModel.getReadOnlyProperty().asObject(); - - assertEquals(Integer.valueOf(0), exp.getValue()); - valueModel.set(-4354); - assertEquals(Integer.valueOf(-4354), exp.getValue()); - valueModel.set(5); - assertEquals(Integer.valueOf(5), exp.getValue()); - } - - @Test - public void testObjectToInteger() { - final ReadOnlyObjectWrapper valueModel = new ReadOnlyObjectWrapper(); - final ReadOnlyIntegerProperty exp = ReadOnlyIntegerProperty.readOnlyIntegerProperty(valueModel.getReadOnlyProperty()); - - assertEquals(0, exp.intValue()); - valueModel.set(-4354); - assertEquals(-4354, exp.intValue()); - valueModel.set(5); - assertEquals(5, exp.intValue()); - } - - private static class ReadOnlyIntegerPropertyStub extends ReadOnlyIntegerProperty { - - private final Object bean; - private final String name; - - private ReadOnlyIntegerPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override public Object getBean() { return bean; } - @Override public String getName() { return name; } - @Override public int get() { return 0; } - - @Override - public void addListener(ChangeListener listener) { - } - - @Override - public void removeListener(ChangeListener listener) { - } - - @Override - public void addListener(InvalidationListener listener) { - } - - @Override - public void removeListener(InvalidationListener listener) { - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyIntegerPropertyTest.java 2015-08-31 10:23:39.681217336 -0400 @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import javafx.beans.InvalidationListener; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.ReadOnlyIntegerWrapper; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.beans.value.ChangeListener; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyIntegerPropertyTest { + + private static final int DEFAULT = 0; + + @Before + public void setUp() throws Exception { + } + + @Test + public void testToString() { + final ReadOnlyIntegerProperty v1 = new ReadOnlyIntegerPropertyStub(null, ""); + assertEquals("ReadOnlyIntegerProperty [value: " + DEFAULT + "]", v1.toString()); + + final ReadOnlyIntegerProperty v2 = new ReadOnlyIntegerPropertyStub(null, null); + assertEquals("ReadOnlyIntegerProperty [value: " + DEFAULT + "]", v2.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyIntegerProperty v3 = new ReadOnlyIntegerPropertyStub(bean, name); + assertEquals("ReadOnlyIntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); + + final ReadOnlyIntegerProperty v4 = new ReadOnlyIntegerPropertyStub(bean, ""); + assertEquals("ReadOnlyIntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + + final ReadOnlyIntegerProperty v5 = new ReadOnlyIntegerPropertyStub(bean, null); + assertEquals("ReadOnlyIntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); + + final ReadOnlyIntegerProperty v6 = new ReadOnlyIntegerPropertyStub(null, name); + assertEquals("ReadOnlyIntegerProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); + + } + + @Test + public void testAsObject() { + final ReadOnlyIntegerWrapper valueModel = new ReadOnlyIntegerWrapper(); + final ReadOnlyObjectProperty exp = valueModel.getReadOnlyProperty().asObject(); + + assertEquals(Integer.valueOf(0), exp.getValue()); + valueModel.set(-4354); + assertEquals(Integer.valueOf(-4354), exp.getValue()); + valueModel.set(5); + assertEquals(Integer.valueOf(5), exp.getValue()); + } + + @Test + public void testObjectToInteger() { + final ReadOnlyObjectWrapper valueModel = new ReadOnlyObjectWrapper(); + final ReadOnlyIntegerProperty exp = ReadOnlyIntegerProperty.readOnlyIntegerProperty(valueModel.getReadOnlyProperty()); + + assertEquals(0, exp.intValue()); + valueModel.set(-4354); + assertEquals(-4354, exp.intValue()); + valueModel.set(5); + assertEquals(5, exp.intValue()); + } + + private static class ReadOnlyIntegerPropertyStub extends ReadOnlyIntegerProperty { + + private final Object bean; + private final String name; + + private ReadOnlyIntegerPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override public Object getBean() { return bean; } + @Override public String getName() { return name; } + @Override public int get() { return 0; } + + @Override + public void addListener(ChangeListener listener) { + } + + @Override + public void removeListener(ChangeListener listener) { + } + + @Override + public void addListener(InvalidationListener listener) { + } + + @Override + public void removeListener(InvalidationListener listener) { + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyIntegerWrapperTest.java 2015-08-31 10:23:40.489217327 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,758 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableIntegerValueStub; -import javafx.beans.value.ObservableObjectValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyIntegerWrapperTest { - - private static final Integer UNDEFINED = null; - private static final int DEFAULT = 0; - private static final int VALUE_1 = 4711; - private static final int VALUE_2 = 42; - - private ReadOnlyIntegerWrapperMock property; - private ReadOnlyIntegerProperty readOnlyProperty; - private InvalidationListenerMock internalInvalidationListener; - private InvalidationListenerMock publicInvalidationListener; - private ChangeListenerMock internalChangeListener; - private ChangeListenerMock publicChangeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyIntegerWrapperMock(); - readOnlyProperty = property.getReadOnlyProperty(); - internalInvalidationListener = new InvalidationListenerMock(); - publicInvalidationListener = new InvalidationListenerMock(); - internalChangeListener = new ChangeListenerMock(UNDEFINED); - publicChangeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListeners() { - property.addListener(internalInvalidationListener); - readOnlyProperty.addListener(publicInvalidationListener); - property.get(); - readOnlyProperty.get(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - } - - private void attachInternalChangeListener() { - property.addListener(internalChangeListener); - property.get(); - internalChangeListener.reset(); - } - - private void attachPublicChangeListener() { - readOnlyProperty.addListener(publicChangeListener); - readOnlyProperty.get(); - publicChangeListener.reset(); - } - - @Test - public void testConstructor_NoArguments() { - final ReadOnlyIntegerWrapper p1 = new ReadOnlyIntegerWrapper(); - assertEquals(DEFAULT, p1.get()); - assertEquals((Integer)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyIntegerProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Integer)DEFAULT, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_InitialValue() { - final ReadOnlyIntegerWrapper p1 = new ReadOnlyIntegerWrapper(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Integer)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyIntegerProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Integer)VALUE_1, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyIntegerWrapper p1 = new ReadOnlyIntegerWrapper(bean, name); - assertEquals(DEFAULT, p1.get()); - assertEquals((Integer)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyIntegerProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Integer)DEFAULT, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyIntegerWrapper p1 = new ReadOnlyIntegerWrapper(bean, name, VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Integer)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyIntegerProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Integer)VALUE_1, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testLazySet() { - attachInvalidationListeners(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSet() { - attachInternalChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSet() { - attachPublicChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListeners(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSetValue() { - attachInternalChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSetValue() { - attachPublicChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind_primitive() { - attachInvalidationListeners(); - final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_primitive() { - attachInternalChangeListener(); - final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_primitive() { - attachPublicChangeListener(); - final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test - public void testLazyBind_generic() { - attachInvalidationListeners(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_generic() { - attachInternalChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_generic() { - attachPublicChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListeners(); - final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1); - final IntegerProperty v2 = new SimpleIntegerProperty(VALUE_2); - property.bind(v1); - property.get(); - readOnlyProperty.get(); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change new binding - v2.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change old binding - v1.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListeners(); - final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get()); - assertFalse(property.isBound()); - assertEquals(VALUE_1, readOnlyProperty.get()); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); - final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); - - // setting the property,checking internal - property.set(VALUE_1); - property.addListener(internalListener2); - internalListener2.reset(); - property.set(VALUE_2); - internalListener2.check(property, 1); - - // setting the property, checking public - property.set(VALUE_1); - readOnlyProperty.addListener(publicListener2); - publicListener2.reset(); - property.set(VALUE_2); - publicListener2.check(readOnlyProperty, 1); - - // binding the property, checking internal - property.bind(v); - v.set(VALUE_2); - property.addListener(internalListener3); - v.get(); - internalListener3.reset(); - v.set(VALUE_1); - internalListener3.check(property, 1); - - // binding the property, checking public - property.bind(v); - v.set(VALUE_2); - readOnlyProperty.addListener(publicListener3); - v.get(); - publicListener3.reset(); - v.set(VALUE_1); - publicListener3.check(readOnlyProperty, 1); - } - - @Test - public void testRemoveListeners() { - attachInvalidationListeners(); - attachInternalChangeListener(); - property.removeListener(internalInvalidationListener); - property.removeListener(internalChangeListener); - property.get(); - internalInvalidationListener.reset(); - internalChangeListener.reset(); - - property.set(VALUE_1); - internalInvalidationListener.check(null, 0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // no read only property created => no-op - final ReadOnlyIntegerWrapper v1 = new ReadOnlyIntegerWrapper(); - v1.removeListener(internalInvalidationListener); - v1.removeListener(internalChangeListener); - } - - @Test - public void testNoReadOnlyPropertyCreated() { - final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1); - final ReadOnlyIntegerWrapper p1 = new ReadOnlyIntegerWrapper(); - - p1.set(VALUE_1); - p1.bind(v1); - assertEquals(VALUE_1, p1.get()); - v1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - } - - @Test - public void testToString() { - final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1); - - property.set(VALUE_1); - assertEquals("IntegerProperty [value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyIntegerProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - - property.bind(v1); - assertEquals("IntegerProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyIntegerProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("IntegerProperty [bound, value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyIntegerProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - v1.set(VALUE_2); - assertEquals("IntegerProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyIntegerProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("IntegerProperty [bound, value: " + VALUE_2 + "]", property.toString()); - assertEquals("ReadOnlyIntegerProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyIntegerWrapper v2 = new ReadOnlyIntegerWrapper(bean, name); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - assertEquals("ReadOnlyIntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); - - final ReadOnlyIntegerWrapper v3 = new ReadOnlyIntegerWrapper(bean, ""); - assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - assertEquals("ReadOnlyIntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); - - final ReadOnlyIntegerWrapper v4 = new ReadOnlyIntegerWrapper(null, name); - assertEquals("IntegerProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); - assertEquals("ReadOnlyIntegerProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); - } - - private static class ReadOnlyIntegerWrapperMock extends ReadOnlyIntegerWrapper { - - private int counter; - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyIntegerWrapperTest.java 2015-08-31 10:23:40.357217329 -0400 @@ -0,0 +1,762 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.ReadOnlyIntegerWrapper; +import javafx.beans.property.SimpleIntegerProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableIntegerValueStub; +import javafx.beans.value.ObservableObjectValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyIntegerWrapperTest { + + private static final Integer UNDEFINED = null; + private static final int DEFAULT = 0; + private static final int VALUE_1 = 4711; + private static final int VALUE_2 = 42; + + private ReadOnlyIntegerWrapperMock property; + private ReadOnlyIntegerProperty readOnlyProperty; + private InvalidationListenerMock internalInvalidationListener; + private InvalidationListenerMock publicInvalidationListener; + private ChangeListenerMock internalChangeListener; + private ChangeListenerMock publicChangeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyIntegerWrapperMock(); + readOnlyProperty = property.getReadOnlyProperty(); + internalInvalidationListener = new InvalidationListenerMock(); + publicInvalidationListener = new InvalidationListenerMock(); + internalChangeListener = new ChangeListenerMock(UNDEFINED); + publicChangeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListeners() { + property.addListener(internalInvalidationListener); + readOnlyProperty.addListener(publicInvalidationListener); + property.get(); + readOnlyProperty.get(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + } + + private void attachInternalChangeListener() { + property.addListener(internalChangeListener); + property.get(); + internalChangeListener.reset(); + } + + private void attachPublicChangeListener() { + readOnlyProperty.addListener(publicChangeListener); + readOnlyProperty.get(); + publicChangeListener.reset(); + } + + @Test + public void testConstructor_NoArguments() { + final ReadOnlyIntegerWrapper p1 = new ReadOnlyIntegerWrapper(); + assertEquals(DEFAULT, p1.get()); + assertEquals((Integer)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyIntegerProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Integer)DEFAULT, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_InitialValue() { + final ReadOnlyIntegerWrapper p1 = new ReadOnlyIntegerWrapper(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Integer)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyIntegerProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Integer)VALUE_1, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyIntegerWrapper p1 = new ReadOnlyIntegerWrapper(bean, name); + assertEquals(DEFAULT, p1.get()); + assertEquals((Integer)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyIntegerProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Integer)DEFAULT, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyIntegerWrapper p1 = new ReadOnlyIntegerWrapper(bean, name, VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Integer)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyIntegerProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Integer)VALUE_1, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testLazySet() { + attachInvalidationListeners(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSet() { + attachInternalChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSet() { + attachPublicChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListeners(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSetValue() { + attachInternalChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSetValue() { + attachPublicChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind_primitive() { + attachInvalidationListeners(); + final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_primitive() { + attachInternalChangeListener(); + final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_primitive() { + attachPublicChangeListener(); + final ObservableIntegerValueStub v = new ObservableIntegerValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test + public void testLazyBind_generic() { + attachInvalidationListeners(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_generic() { + attachInternalChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_generic() { + attachPublicChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListeners(); + final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1); + final IntegerProperty v2 = new SimpleIntegerProperty(VALUE_2); + property.bind(v1); + property.get(); + readOnlyProperty.get(); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change new binding + v2.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change old binding + v1.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListeners(); + final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get()); + assertFalse(property.isBound()); + assertEquals(VALUE_1, readOnlyProperty.get()); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final IntegerProperty v = new SimpleIntegerProperty(VALUE_1); + final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); + + // setting the property,checking internal + property.set(VALUE_1); + property.addListener(internalListener2); + internalListener2.reset(); + property.set(VALUE_2); + internalListener2.check(property, 1); + + // setting the property, checking public + property.set(VALUE_1); + readOnlyProperty.addListener(publicListener2); + publicListener2.reset(); + property.set(VALUE_2); + publicListener2.check(readOnlyProperty, 1); + + // binding the property, checking internal + property.bind(v); + v.set(VALUE_2); + property.addListener(internalListener3); + v.get(); + internalListener3.reset(); + v.set(VALUE_1); + internalListener3.check(property, 1); + + // binding the property, checking public + property.bind(v); + v.set(VALUE_2); + readOnlyProperty.addListener(publicListener3); + v.get(); + publicListener3.reset(); + v.set(VALUE_1); + publicListener3.check(readOnlyProperty, 1); + } + + @Test + public void testRemoveListeners() { + attachInvalidationListeners(); + attachInternalChangeListener(); + property.removeListener(internalInvalidationListener); + property.removeListener(internalChangeListener); + property.get(); + internalInvalidationListener.reset(); + internalChangeListener.reset(); + + property.set(VALUE_1); + internalInvalidationListener.check(null, 0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // no read only property created => no-op + final ReadOnlyIntegerWrapper v1 = new ReadOnlyIntegerWrapper(); + v1.removeListener(internalInvalidationListener); + v1.removeListener(internalChangeListener); + } + + @Test + public void testNoReadOnlyPropertyCreated() { + final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1); + final ReadOnlyIntegerWrapper p1 = new ReadOnlyIntegerWrapper(); + + p1.set(VALUE_1); + p1.bind(v1); + assertEquals(VALUE_1, p1.get()); + v1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + } + + @Test + public void testToString() { + final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1); + + property.set(VALUE_1); + assertEquals("IntegerProperty [value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyIntegerProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + + property.bind(v1); + assertEquals("IntegerProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyIntegerProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("IntegerProperty [bound, value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyIntegerProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + v1.set(VALUE_2); + assertEquals("IntegerProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyIntegerProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("IntegerProperty [bound, value: " + VALUE_2 + "]", property.toString()); + assertEquals("ReadOnlyIntegerProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyIntegerWrapper v2 = new ReadOnlyIntegerWrapper(bean, name); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + assertEquals("ReadOnlyIntegerProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); + + final ReadOnlyIntegerWrapper v3 = new ReadOnlyIntegerWrapper(bean, ""); + assertEquals("IntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + assertEquals("ReadOnlyIntegerProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); + + final ReadOnlyIntegerWrapper v4 = new ReadOnlyIntegerWrapper(null, name); + assertEquals("IntegerProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); + assertEquals("ReadOnlyIntegerProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); + } + + private static class ReadOnlyIntegerWrapperMock extends ReadOnlyIntegerWrapper { + + private int counter; + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyListPropertyBaseTest.java 2015-08-31 10:23:41.205217319 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.fail; - -public class ReadOnlyListPropertyBaseTest { - - private static final Object UNDEFINED = null; - private static final Object DEFAULT = null; - private static final ObservableList VALUE_1 = FXCollections.observableArrayList(); - private static final ObservableList VALUE_2 = FXCollections.observableArrayList(new Object()); - - private ReadOnlyPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - @Test - public void testInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_2); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(property, DEFAULT, VALUE_1, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_2); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - private static class ReadOnlyPropertyMock extends ReadOnlyListPropertyBase { - - private ObservableList value; - - @Override - public Object getBean() { - // not used - return null; - } - - @Override - public String getName() { - // not used - return null; - } - - private void set(ObservableList value) { - this.value = value; - fireValueChangedEvent(); - } - - @Override - public ObservableList get() { - return value; - } - - @Override - public ReadOnlyIntegerProperty sizeProperty() { - fail("Not in use"); - return null; - } - - @Override - public ReadOnlyBooleanProperty emptyProperty() { - fail("Not in use"); - return null; - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyListPropertyBaseTest.java 2015-08-31 10:23:41.073217321 -0400 @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.ReadOnlyListPropertyBase; +import javafx.beans.property.ReadOnlyListPropertyBaseShim; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class ReadOnlyListPropertyBaseTest { + + private static final Object UNDEFINED = null; + private static final Object DEFAULT = null; + private static final ObservableList VALUE_1 = FXCollections.observableArrayList(); + private static final ObservableList VALUE_2 = FXCollections.observableArrayList(new Object()); + + private ReadOnlyPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + @Test + public void testInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_2); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(property, DEFAULT, VALUE_1, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_2); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + private static class ReadOnlyPropertyMock extends ReadOnlyListPropertyBase { + + private ObservableList value; + + @Override + public Object getBean() { + // not used + return null; + } + + @Override + public String getName() { + // not used + return null; + } + + private void set(ObservableList value) { + this.value = value; + ReadOnlyListPropertyBaseShim.fireValueChangedEvent(this); + } + + @Override + public ObservableList get() { + return value; + } + + @Override + public ReadOnlyIntegerProperty sizeProperty() { + fail("Not in use"); + return null; + } + + @Override + public ReadOnlyBooleanProperty emptyProperty() { + fail("Not in use"); + return null; + } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyListPropertyTest.java 2015-08-31 10:23:42.033217310 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class ReadOnlyListPropertyTest { - - private static final Object DEFAULT = null; - - @Before - public void setUp() throws Exception { - } - - - @Test - public void testToString() { - final ReadOnlyListProperty v1 = new ReadOnlyListPropertyStub(null, ""); - assertEquals("ReadOnlyListProperty [value: " + DEFAULT + "]", v1.toString()); - - final ReadOnlyListProperty v2 = new ReadOnlyListPropertyStub(null, null); - assertEquals("ReadOnlyListProperty [value: " + DEFAULT + "]", v2.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyListProperty v3 = new ReadOnlyListPropertyStub(bean, name); - assertEquals("ReadOnlyListProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); - - final ReadOnlyListProperty v4 = new ReadOnlyListPropertyStub(bean, ""); - assertEquals("ReadOnlyListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - - final ReadOnlyListProperty v5 = new ReadOnlyListPropertyStub(bean, null); - assertEquals("ReadOnlyListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); - - final ReadOnlyListProperty v6 = new ReadOnlyListPropertyStub(null, name); - assertEquals("ReadOnlyListProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); - - } - - private static class ReadOnlyListPropertyStub extends ReadOnlyListProperty { - - private final Object bean; - private final String name; - - private ReadOnlyListPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override public Object getBean() { return bean; } - @Override public String getName() { return name; } - @Override public ObservableList get() { return null; } - - @Override - public void addListener(ChangeListener> listener) { - } - - @Override - public void removeListener(ChangeListener> listener) { - } - - @Override - public void addListener(InvalidationListener listener) { - } - - @Override - public void removeListener(InvalidationListener listener) { - } - - @Override - public void addListener(ListChangeListener listChangeListener) { - } - - @Override - public void removeListener(ListChangeListener listChangeListener) { - } - - @Override - public ReadOnlyIntegerProperty sizeProperty() { - fail("Not in use"); - return null; - } - - @Override - public ReadOnlyBooleanProperty emptyProperty() { - fail("Not in use"); - return null; - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyListPropertyTest.java 2015-08-31 10:23:41.893217311 -0400 @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.InvalidationListener; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.ReadOnlyListProperty; +import javafx.beans.value.ChangeListener; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ReadOnlyListPropertyTest { + + private static final Object DEFAULT = null; + + @Before + public void setUp() throws Exception { + } + + + @Test + public void testToString() { + final ReadOnlyListProperty v1 = new ReadOnlyListPropertyStub(null, ""); + assertEquals("ReadOnlyListProperty [value: " + DEFAULT + "]", v1.toString()); + + final ReadOnlyListProperty v2 = new ReadOnlyListPropertyStub(null, null); + assertEquals("ReadOnlyListProperty [value: " + DEFAULT + "]", v2.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyListProperty v3 = new ReadOnlyListPropertyStub(bean, name); + assertEquals("ReadOnlyListProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); + + final ReadOnlyListProperty v4 = new ReadOnlyListPropertyStub(bean, ""); + assertEquals("ReadOnlyListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + + final ReadOnlyListProperty v5 = new ReadOnlyListPropertyStub(bean, null); + assertEquals("ReadOnlyListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); + + final ReadOnlyListProperty v6 = new ReadOnlyListPropertyStub(null, name); + assertEquals("ReadOnlyListProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); + + } + + private static class ReadOnlyListPropertyStub extends ReadOnlyListProperty { + + private final Object bean; + private final String name; + + private ReadOnlyListPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override public Object getBean() { return bean; } + @Override public String getName() { return name; } + @Override public ObservableList get() { return null; } + + @Override + public void addListener(ChangeListener> listener) { + } + + @Override + public void removeListener(ChangeListener> listener) { + } + + @Override + public void addListener(InvalidationListener listener) { + } + + @Override + public void removeListener(InvalidationListener listener) { + } + + @Override + public void addListener(ListChangeListener listChangeListener) { + } + + @Override + public void removeListener(ListChangeListener listChangeListener) { + } + + @Override + public ReadOnlyIntegerProperty sizeProperty() { + fail("Not in use"); + return null; + } + + @Override + public ReadOnlyBooleanProperty emptyProperty() { + fail("Not in use"); + return null; + } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyListWrapperTest.java 2015-08-31 10:23:42.661217303 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,756 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableObjectValueStub; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class ReadOnlyListWrapperTest { - - private static final Object UNDEFINED = null; - private static final ObservableList DEFAULT = null; - private static final ObservableList VALUE_1 = FXCollections.observableArrayList(); - private static final ObservableList VALUE_2 = FXCollections.observableArrayList(new Object()); - - private ReadOnlyListWrapperMock property; - private ReadOnlyListProperty readOnlyProperty; - private InvalidationListenerMock internalInvalidationListener; - private InvalidationListenerMock publicInvalidationListener; - private ChangeListenerMock internalChangeListener; - private ChangeListenerMock publicChangeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyListWrapperMock(); - readOnlyProperty = property.getReadOnlyProperty(); - internalInvalidationListener = new InvalidationListenerMock(); - publicInvalidationListener = new InvalidationListenerMock(); - internalChangeListener = new ChangeListenerMock(UNDEFINED); - publicChangeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListeners() { - property.addListener(internalInvalidationListener); - readOnlyProperty.addListener(publicInvalidationListener); - property.get(); - readOnlyProperty.get(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - } - - private void attachInternalChangeListener() { - property.addListener(internalChangeListener); - property.get(); - internalChangeListener.reset(); - } - - private void attachPublicChangeListener() { - readOnlyProperty.addListener(publicChangeListener); - readOnlyProperty.get(); - publicChangeListener.reset(); - } - - @Test - public void testConstructor_NoArguments() { - final ReadOnlyListWrapper p1 = new ReadOnlyListWrapper(); - assertEquals(DEFAULT, p1.get()); - assertEquals((Object)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyListProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Object)DEFAULT, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_InitialValue() { - final ReadOnlyListWrapper p1 = new ReadOnlyListWrapper(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Object)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyListProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Object)VALUE_1, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyListWrapper p1 = new ReadOnlyListWrapper(bean, name); - assertEquals(DEFAULT, p1.get()); - assertEquals((Object)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyListProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Object)DEFAULT, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyListWrapper p1 = new ReadOnlyListWrapper(bean, name, VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Object)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyListProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Object)VALUE_1, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testLazySet() { - attachInvalidationListeners(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSet() { - attachInternalChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSet() { - attachPublicChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListeners(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSetValue() { - attachInternalChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSetValue() { - attachPublicChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final ListProperty v = new SimpleListProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind_primitive() { - attachInvalidationListeners(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_primitive() { - attachInternalChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_primitive() { - attachPublicChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test - public void testLazyBind_generic() { - attachInvalidationListeners(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_generic() { - attachInternalChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_generic() { - attachPublicChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListeners(); - final ListProperty v1 = new SimpleListProperty(VALUE_1); - final ListProperty v2 = new SimpleListProperty(VALUE_2); - property.bind(v1); - property.get(); - readOnlyProperty.get(); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change new binding - v2.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change old binding - v1.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListeners(); - final ListProperty v = new SimpleListProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get()); - assertFalse(property.isBound()); - assertEquals(VALUE_1, readOnlyProperty.get()); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final ListProperty v = new SimpleListProperty(VALUE_1); - final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); - - // setting the property,checking internal - property.set(VALUE_1); - property.addListener(internalListener2); - internalListener2.reset(); - property.set(VALUE_2); - internalListener2.check(property, 1); - - // setting the property, checking public - property.set(VALUE_1); - readOnlyProperty.addListener(publicListener2); - publicListener2.reset(); - property.set(VALUE_2); - publicListener2.check(readOnlyProperty, 1); - - // binding the property, checking internal - property.bind(v); - v.set(VALUE_2); - property.addListener(internalListener3); - v.get(); - internalListener3.reset(); - v.set(VALUE_1); - internalListener3.check(property, 1); - - // binding the property, checking public - property.bind(v); - v.set(VALUE_2); - readOnlyProperty.addListener(publicListener3); - v.get(); - publicListener3.reset(); - v.set(VALUE_1); - publicListener3.check(readOnlyProperty, 1); - } - - @Test - public void testRemoveListeners() { - attachInvalidationListeners(); - attachInternalChangeListener(); - property.removeListener(internalInvalidationListener); - property.removeListener(internalChangeListener); - property.get(); - internalInvalidationListener.reset(); - internalChangeListener.reset(); - - property.set(VALUE_1); - internalInvalidationListener.check(null, 0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // no read only property created => no-op - final ReadOnlyListWrapper v1 = new ReadOnlyListWrapper(); - v1.removeListener(internalInvalidationListener); - v1.removeListener(internalChangeListener); - } - - @Test - public void testNoReadOnlyPropertyCreated() { - final ListProperty v1 = new SimpleListProperty(VALUE_1); - final ReadOnlyListWrapper p1 = new ReadOnlyListWrapper(); - - p1.set(VALUE_1); - p1.bind(v1); - assertEquals(VALUE_1, p1.get()); - v1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - } - - @Test - public void testToString() { - final ListProperty v1 = new SimpleListProperty(VALUE_1); - - property.set(VALUE_1); - assertEquals("ListProperty [value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyListProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - - property.bind(v1); - assertEquals("ListProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyListProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("ListProperty [bound, value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyListProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - v1.set(VALUE_2); - assertEquals("ListProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyListProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("ListProperty [bound, value: " + VALUE_2 + "]", property.toString()); - assertEquals("ReadOnlyListProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyListWrapper v2 = new ReadOnlyListWrapper(bean, name); - assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - assertEquals("ReadOnlyListProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); - - final ReadOnlyListWrapper v3 = new ReadOnlyListWrapper(bean, ""); - assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - assertEquals("ReadOnlyListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); - - final ReadOnlyListWrapper v4 = new ReadOnlyListWrapper(null, name); - assertEquals("ListProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); - assertEquals("ReadOnlyListProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); - } - - private static class ReadOnlyListWrapperMock extends ReadOnlyListWrapper { - - private int counter; - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyListWrapperTest.java 2015-08-31 10:23:42.525217304 -0400 @@ -0,0 +1,760 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.ListProperty; +import javafx.beans.property.ReadOnlyListProperty; +import javafx.beans.property.ReadOnlyListWrapper; +import javafx.beans.property.SimpleListProperty; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableObjectValueStub; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ReadOnlyListWrapperTest { + + private static final Object UNDEFINED = null; + private static final ObservableList DEFAULT = null; + private static final ObservableList VALUE_1 = FXCollections.observableArrayList(); + private static final ObservableList VALUE_2 = FXCollections.observableArrayList(new Object()); + + private ReadOnlyListWrapperMock property; + private ReadOnlyListProperty readOnlyProperty; + private InvalidationListenerMock internalInvalidationListener; + private InvalidationListenerMock publicInvalidationListener; + private ChangeListenerMock internalChangeListener; + private ChangeListenerMock publicChangeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyListWrapperMock(); + readOnlyProperty = property.getReadOnlyProperty(); + internalInvalidationListener = new InvalidationListenerMock(); + publicInvalidationListener = new InvalidationListenerMock(); + internalChangeListener = new ChangeListenerMock(UNDEFINED); + publicChangeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListeners() { + property.addListener(internalInvalidationListener); + readOnlyProperty.addListener(publicInvalidationListener); + property.get(); + readOnlyProperty.get(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + } + + private void attachInternalChangeListener() { + property.addListener(internalChangeListener); + property.get(); + internalChangeListener.reset(); + } + + private void attachPublicChangeListener() { + readOnlyProperty.addListener(publicChangeListener); + readOnlyProperty.get(); + publicChangeListener.reset(); + } + + @Test + public void testConstructor_NoArguments() { + final ReadOnlyListWrapper p1 = new ReadOnlyListWrapper(); + assertEquals(DEFAULT, p1.get()); + assertEquals((Object)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyListProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Object)DEFAULT, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_InitialValue() { + final ReadOnlyListWrapper p1 = new ReadOnlyListWrapper(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Object)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyListProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Object)VALUE_1, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyListWrapper p1 = new ReadOnlyListWrapper(bean, name); + assertEquals(DEFAULT, p1.get()); + assertEquals((Object)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyListProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Object)DEFAULT, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyListWrapper p1 = new ReadOnlyListWrapper(bean, name, VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Object)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyListProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Object)VALUE_1, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testLazySet() { + attachInvalidationListeners(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSet() { + attachInternalChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSet() { + attachPublicChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListeners(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSetValue() { + attachInternalChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSetValue() { + attachPublicChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final ListProperty v = new SimpleListProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind_primitive() { + attachInvalidationListeners(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_primitive() { + attachInternalChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_primitive() { + attachPublicChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test + public void testLazyBind_generic() { + attachInvalidationListeners(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_generic() { + attachInternalChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_generic() { + attachPublicChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListeners(); + final ListProperty v1 = new SimpleListProperty(VALUE_1); + final ListProperty v2 = new SimpleListProperty(VALUE_2); + property.bind(v1); + property.get(); + readOnlyProperty.get(); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change new binding + v2.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change old binding + v1.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListeners(); + final ListProperty v = new SimpleListProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get()); + assertFalse(property.isBound()); + assertEquals(VALUE_1, readOnlyProperty.get()); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final ListProperty v = new SimpleListProperty(VALUE_1); + final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); + + // setting the property,checking internal + property.set(VALUE_1); + property.addListener(internalListener2); + internalListener2.reset(); + property.set(VALUE_2); + internalListener2.check(property, 1); + + // setting the property, checking public + property.set(VALUE_1); + readOnlyProperty.addListener(publicListener2); + publicListener2.reset(); + property.set(VALUE_2); + publicListener2.check(readOnlyProperty, 1); + + // binding the property, checking internal + property.bind(v); + v.set(VALUE_2); + property.addListener(internalListener3); + v.get(); + internalListener3.reset(); + v.set(VALUE_1); + internalListener3.check(property, 1); + + // binding the property, checking public + property.bind(v); + v.set(VALUE_2); + readOnlyProperty.addListener(publicListener3); + v.get(); + publicListener3.reset(); + v.set(VALUE_1); + publicListener3.check(readOnlyProperty, 1); + } + + @Test + public void testRemoveListeners() { + attachInvalidationListeners(); + attachInternalChangeListener(); + property.removeListener(internalInvalidationListener); + property.removeListener(internalChangeListener); + property.get(); + internalInvalidationListener.reset(); + internalChangeListener.reset(); + + property.set(VALUE_1); + internalInvalidationListener.check(null, 0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // no read only property created => no-op + final ReadOnlyListWrapper v1 = new ReadOnlyListWrapper(); + v1.removeListener(internalInvalidationListener); + v1.removeListener(internalChangeListener); + } + + @Test + public void testNoReadOnlyPropertyCreated() { + final ListProperty v1 = new SimpleListProperty(VALUE_1); + final ReadOnlyListWrapper p1 = new ReadOnlyListWrapper(); + + p1.set(VALUE_1); + p1.bind(v1); + assertEquals(VALUE_1, p1.get()); + v1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + } + + @Test + public void testToString() { + final ListProperty v1 = new SimpleListProperty(VALUE_1); + + property.set(VALUE_1); + assertEquals("ListProperty [value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyListProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + + property.bind(v1); + assertEquals("ListProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyListProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("ListProperty [bound, value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyListProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + v1.set(VALUE_2); + assertEquals("ListProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyListProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("ListProperty [bound, value: " + VALUE_2 + "]", property.toString()); + assertEquals("ReadOnlyListProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyListWrapper v2 = new ReadOnlyListWrapper(bean, name); + assertEquals("ListProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + assertEquals("ReadOnlyListProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); + + final ReadOnlyListWrapper v3 = new ReadOnlyListWrapper(bean, ""); + assertEquals("ListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + assertEquals("ReadOnlyListProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); + + final ReadOnlyListWrapper v4 = new ReadOnlyListWrapper(null, name); + assertEquals("ListProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); + assertEquals("ReadOnlyListProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); + } + + private static class ReadOnlyListWrapperMock extends ReadOnlyListWrapper { + + private int counter; + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyLongPropertyBaseTest.java 2015-08-31 10:23:43.333217295 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyLongPropertyBaseTest { - - private static final Long UNDEFINED = null; - private static final long DEFAULT = 0L; - private static final long VALUE_1 = 543210987654321L; - private static final long VALUE_2 = -678901234567890L; - - private ReadOnlyPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - @Test - public void testInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_2); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(property, DEFAULT, VALUE_1, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_2); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - private static class ReadOnlyPropertyMock extends ReadOnlyLongPropertyBase { - - private long value; - - @Override - public Object getBean() { - // not used - return null; - } - - @Override - public String getName() { - // not used - return null; - } - - private void set(long value) { - this.value = value; - fireValueChangedEvent(); - } - - @Override - public long get() { - return value; - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyLongPropertyBaseTest.java 2015-08-31 10:23:43.133217297 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.ReadOnlyLongPropertyBase; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyLongPropertyBaseTest { + + private static final Long UNDEFINED = null; + private static final long DEFAULT = 0L; + private static final long VALUE_1 = 543210987654321L; + private static final long VALUE_2 = -678901234567890L; + + private ReadOnlyPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + @Test + public void testInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_2); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(property, DEFAULT, VALUE_1, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_2); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + private static class ReadOnlyPropertyMock extends ReadOnlyLongPropertyBase { + + private long value; + + @Override + public Object getBean() { + // not used + return null; + } + + @Override + public String getName() { + // not used + return null; + } + + private void set(long value) { + this.value = value; + fireValueChangedEvent(); + } + + @Override + public long get() { + return value; + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyLongPropertyTest.java 2015-08-31 10:23:43.929217288 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import javafx.beans.InvalidationListener; -import javafx.beans.binding.ObjectExpression; -import javafx.beans.value.ChangeListener; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyLongPropertyTest { - - private static final long DEFAULT = 0L; - - @Before - public void setUp() throws Exception { - } - - - @Test - public void testToString() { - final ReadOnlyLongProperty v1 = new ReadOnlyLongPropertyStub(null, ""); - assertEquals("ReadOnlyLongProperty [value: " + DEFAULT + "]", v1.toString()); - - final ReadOnlyLongProperty v2 = new ReadOnlyLongPropertyStub(null, null); - assertEquals("ReadOnlyLongProperty [value: " + DEFAULT + "]", v2.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyLongProperty v3 = new ReadOnlyLongPropertyStub(bean, name); - assertEquals("ReadOnlyLongProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); - - final ReadOnlyLongProperty v4 = new ReadOnlyLongPropertyStub(bean, ""); - assertEquals("ReadOnlyLongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - - final ReadOnlyLongProperty v5 = new ReadOnlyLongPropertyStub(bean, null); - assertEquals("ReadOnlyLongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); - - final ReadOnlyLongProperty v6 = new ReadOnlyLongPropertyStub(null, name); - assertEquals("ReadOnlyLongProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); - - } - - @Test - public void testAsObject() { - final ReadOnlyLongWrapper valueModel = new ReadOnlyLongWrapper(); - final ReadOnlyObjectProperty exp = valueModel.getReadOnlyProperty().asObject(); - - assertEquals(Long.valueOf(0L), exp.getValue()); - valueModel.set(-4354L); - assertEquals(Long.valueOf(-4354L), exp.getValue()); - valueModel.set(5L); - assertEquals(Long.valueOf(5L), exp.getValue()); - } - - @Test - public void testObjectToLong() { - final ReadOnlyObjectWrapper valueModel = new ReadOnlyObjectWrapper(); - final ReadOnlyLongProperty exp = ReadOnlyLongProperty.readOnlyLongProperty(valueModel.getReadOnlyProperty()); - - assertEquals(0L, exp.longValue()); - valueModel.set(-4354L); - assertEquals(-4354L, exp.longValue()); - valueModel.set(5L); - assertEquals(5L, exp.longValue()); - } - - private static class ReadOnlyLongPropertyStub extends ReadOnlyLongProperty { - - private final Object bean; - private final String name; - - private ReadOnlyLongPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override public Object getBean() { return bean; } - @Override public String getName() { return name; } - @Override public long get() { return 0L; } - - @Override - public void addListener(ChangeListener listener) { - } - - @Override - public void removeListener(ChangeListener listener) { - } - - @Override - public void addListener(InvalidationListener listener) { - } - - @Override - public void removeListener(InvalidationListener listener) { - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyLongPropertyTest.java 2015-08-31 10:23:43.793217290 -0400 @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import javafx.beans.InvalidationListener; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.property.ReadOnlyLongProperty; +import javafx.beans.property.ReadOnlyLongWrapper; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.beans.value.ChangeListener; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyLongPropertyTest { + + private static final long DEFAULT = 0L; + + @Before + public void setUp() throws Exception { + } + + + @Test + public void testToString() { + final ReadOnlyLongProperty v1 = new ReadOnlyLongPropertyStub(null, ""); + assertEquals("ReadOnlyLongProperty [value: " + DEFAULT + "]", v1.toString()); + + final ReadOnlyLongProperty v2 = new ReadOnlyLongPropertyStub(null, null); + assertEquals("ReadOnlyLongProperty [value: " + DEFAULT + "]", v2.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyLongProperty v3 = new ReadOnlyLongPropertyStub(bean, name); + assertEquals("ReadOnlyLongProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); + + final ReadOnlyLongProperty v4 = new ReadOnlyLongPropertyStub(bean, ""); + assertEquals("ReadOnlyLongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + + final ReadOnlyLongProperty v5 = new ReadOnlyLongPropertyStub(bean, null); + assertEquals("ReadOnlyLongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); + + final ReadOnlyLongProperty v6 = new ReadOnlyLongPropertyStub(null, name); + assertEquals("ReadOnlyLongProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); + + } + + @Test + public void testAsObject() { + final ReadOnlyLongWrapper valueModel = new ReadOnlyLongWrapper(); + final ReadOnlyObjectProperty exp = valueModel.getReadOnlyProperty().asObject(); + + assertEquals(Long.valueOf(0L), exp.getValue()); + valueModel.set(-4354L); + assertEquals(Long.valueOf(-4354L), exp.getValue()); + valueModel.set(5L); + assertEquals(Long.valueOf(5L), exp.getValue()); + } + + @Test + public void testObjectToLong() { + final ReadOnlyObjectWrapper valueModel = new ReadOnlyObjectWrapper(); + final ReadOnlyLongProperty exp = ReadOnlyLongProperty.readOnlyLongProperty(valueModel.getReadOnlyProperty()); + + assertEquals(0L, exp.longValue()); + valueModel.set(-4354L); + assertEquals(-4354L, exp.longValue()); + valueModel.set(5L); + assertEquals(5L, exp.longValue()); + } + + private static class ReadOnlyLongPropertyStub extends ReadOnlyLongProperty { + + private final Object bean; + private final String name; + + private ReadOnlyLongPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override public Object getBean() { return bean; } + @Override public String getName() { return name; } + @Override public long get() { return 0L; } + + @Override + public void addListener(ChangeListener listener) { + } + + @Override + public void removeListener(ChangeListener listener) { + } + + @Override + public void addListener(InvalidationListener listener) { + } + + @Override + public void removeListener(InvalidationListener listener) { + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyLongWrapperTest.java 2015-08-31 10:23:44.533217282 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,758 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableLongValueStub; -import javafx.beans.value.ObservableObjectValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyLongWrapperTest { - - private static final Long UNDEFINED = null; - private static final long DEFAULT = 0L; - private static final long VALUE_1 = 890987654321L; - private static final long VALUE_2 = 2123456789098L; - - private ReadOnlyLongWrapperMock property; - private ReadOnlyLongProperty readOnlyProperty; - private InvalidationListenerMock internalInvalidationListener; - private InvalidationListenerMock publicInvalidationListener; - private ChangeListenerMock internalChangeListener; - private ChangeListenerMock publicChangeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyLongWrapperMock(); - readOnlyProperty = property.getReadOnlyProperty(); - internalInvalidationListener = new InvalidationListenerMock(); - publicInvalidationListener = new InvalidationListenerMock(); - internalChangeListener = new ChangeListenerMock(UNDEFINED); - publicChangeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListeners() { - property.addListener(internalInvalidationListener); - readOnlyProperty.addListener(publicInvalidationListener); - property.get(); - readOnlyProperty.get(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - } - - private void attachInternalChangeListener() { - property.addListener(internalChangeListener); - property.get(); - internalChangeListener.reset(); - } - - private void attachPublicChangeListener() { - readOnlyProperty.addListener(publicChangeListener); - readOnlyProperty.get(); - publicChangeListener.reset(); - } - - @Test - public void testConstructor_NoArguments() { - final ReadOnlyLongWrapper p1 = new ReadOnlyLongWrapper(); - assertEquals(DEFAULT, p1.get()); - assertEquals((Long)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyLongProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Long)DEFAULT, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_InitialValue() { - final ReadOnlyLongWrapper p1 = new ReadOnlyLongWrapper(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Long)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyLongProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Long)VALUE_1, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyLongWrapper p1 = new ReadOnlyLongWrapper(bean, name); - assertEquals(DEFAULT, p1.get()); - assertEquals((Long)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyLongProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Long)DEFAULT, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyLongWrapper p1 = new ReadOnlyLongWrapper(bean, name, VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Long)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyLongProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Long)VALUE_1, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testLazySet() { - attachInvalidationListeners(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSet() { - attachInternalChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSet() { - attachPublicChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListeners(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSetValue() { - attachInternalChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSetValue() { - attachPublicChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final LongProperty v = new SimpleLongProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind_primitive() { - attachInvalidationListeners(); - final ObservableLongValueStub v = new ObservableLongValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_primitive() { - attachInternalChangeListener(); - final ObservableLongValueStub v = new ObservableLongValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_primitive() { - attachPublicChangeListener(); - final ObservableLongValueStub v = new ObservableLongValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test - public void testLazyBind_generic() { - attachInvalidationListeners(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_generic() { - attachInternalChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_generic() { - attachPublicChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListeners(); - final LongProperty v1 = new SimpleLongProperty(VALUE_1); - final LongProperty v2 = new SimpleLongProperty(VALUE_2); - property.bind(v1); - property.get(); - readOnlyProperty.get(); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change new binding - v2.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change old binding - v1.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListeners(); - final LongProperty v = new SimpleLongProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get()); - assertFalse(property.isBound()); - assertEquals(VALUE_1, readOnlyProperty.get()); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final LongProperty v = new SimpleLongProperty(VALUE_1); - final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); - - // setting the property,checking internal - property.set(VALUE_1); - property.addListener(internalListener2); - internalListener2.reset(); - property.set(VALUE_2); - internalListener2.check(property, 1); - - // setting the property, checking public - property.set(VALUE_1); - readOnlyProperty.addListener(publicListener2); - publicListener2.reset(); - property.set(VALUE_2); - publicListener2.check(readOnlyProperty, 1); - - // binding the property, checking internal - property.bind(v); - v.set(VALUE_2); - property.addListener(internalListener3); - v.get(); - internalListener3.reset(); - v.set(VALUE_1); - internalListener3.check(property, 1); - - // binding the property, checking public - property.bind(v); - v.set(VALUE_2); - readOnlyProperty.addListener(publicListener3); - v.get(); - publicListener3.reset(); - v.set(VALUE_1); - publicListener3.check(readOnlyProperty, 1); - } - - @Test - public void testRemoveListeners() { - attachInvalidationListeners(); - attachInternalChangeListener(); - property.removeListener(internalInvalidationListener); - property.removeListener(internalChangeListener); - property.get(); - internalInvalidationListener.reset(); - internalChangeListener.reset(); - - property.set(VALUE_1); - internalInvalidationListener.check(null, 0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // no read only property created => no-op - final ReadOnlyLongWrapper v1 = new ReadOnlyLongWrapper(); - v1.removeListener(internalInvalidationListener); - v1.removeListener(internalChangeListener); - } - - @Test - public void testNoReadOnlyPropertyCreated() { - final LongProperty v1 = new SimpleLongProperty(VALUE_1); - final ReadOnlyLongWrapper p1 = new ReadOnlyLongWrapper(); - - p1.set(VALUE_1); - p1.bind(v1); - assertEquals(VALUE_1, p1.get()); - v1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - } - - @Test - public void testToString() { - final LongProperty v1 = new SimpleLongProperty(VALUE_1); - - property.set(VALUE_1); - assertEquals("LongProperty [value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyLongProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - - property.bind(v1); - assertEquals("LongProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyLongProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("LongProperty [bound, value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyLongProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - v1.set(VALUE_2); - assertEquals("LongProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyLongProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("LongProperty [bound, value: " + VALUE_2 + "]", property.toString()); - assertEquals("ReadOnlyLongProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyLongWrapper v2 = new ReadOnlyLongWrapper(bean, name); - assertEquals("LongProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - assertEquals("ReadOnlyLongProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); - - final ReadOnlyLongWrapper v3 = new ReadOnlyLongWrapper(bean, ""); - assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - assertEquals("ReadOnlyLongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); - - final ReadOnlyLongWrapper v4 = new ReadOnlyLongWrapper(null, name); - assertEquals("LongProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); - assertEquals("ReadOnlyLongProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); - } - - private static class ReadOnlyLongWrapperMock extends ReadOnlyLongWrapper { - - private int counter; - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyLongWrapperTest.java 2015-08-31 10:23:44.401217283 -0400 @@ -0,0 +1,762 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.LongProperty; +import javafx.beans.property.ReadOnlyLongProperty; +import javafx.beans.property.ReadOnlyLongWrapper; +import javafx.beans.property.SimpleLongProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableLongValueStub; +import javafx.beans.value.ObservableObjectValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyLongWrapperTest { + + private static final Long UNDEFINED = null; + private static final long DEFAULT = 0L; + private static final long VALUE_1 = 890987654321L; + private static final long VALUE_2 = 2123456789098L; + + private ReadOnlyLongWrapperMock property; + private ReadOnlyLongProperty readOnlyProperty; + private InvalidationListenerMock internalInvalidationListener; + private InvalidationListenerMock publicInvalidationListener; + private ChangeListenerMock internalChangeListener; + private ChangeListenerMock publicChangeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyLongWrapperMock(); + readOnlyProperty = property.getReadOnlyProperty(); + internalInvalidationListener = new InvalidationListenerMock(); + publicInvalidationListener = new InvalidationListenerMock(); + internalChangeListener = new ChangeListenerMock(UNDEFINED); + publicChangeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListeners() { + property.addListener(internalInvalidationListener); + readOnlyProperty.addListener(publicInvalidationListener); + property.get(); + readOnlyProperty.get(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + } + + private void attachInternalChangeListener() { + property.addListener(internalChangeListener); + property.get(); + internalChangeListener.reset(); + } + + private void attachPublicChangeListener() { + readOnlyProperty.addListener(publicChangeListener); + readOnlyProperty.get(); + publicChangeListener.reset(); + } + + @Test + public void testConstructor_NoArguments() { + final ReadOnlyLongWrapper p1 = new ReadOnlyLongWrapper(); + assertEquals(DEFAULT, p1.get()); + assertEquals((Long)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyLongProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Long)DEFAULT, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_InitialValue() { + final ReadOnlyLongWrapper p1 = new ReadOnlyLongWrapper(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Long)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyLongProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Long)VALUE_1, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyLongWrapper p1 = new ReadOnlyLongWrapper(bean, name); + assertEquals(DEFAULT, p1.get()); + assertEquals((Long)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyLongProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Long)DEFAULT, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyLongWrapper p1 = new ReadOnlyLongWrapper(bean, name, VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Long)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyLongProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Long)VALUE_1, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testLazySet() { + attachInvalidationListeners(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSet() { + attachInternalChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSet() { + attachPublicChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListeners(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSetValue() { + attachInternalChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSetValue() { + attachPublicChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final LongProperty v = new SimpleLongProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind_primitive() { + attachInvalidationListeners(); + final ObservableLongValueStub v = new ObservableLongValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_primitive() { + attachInternalChangeListener(); + final ObservableLongValueStub v = new ObservableLongValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_primitive() { + attachPublicChangeListener(); + final ObservableLongValueStub v = new ObservableLongValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test + public void testLazyBind_generic() { + attachInvalidationListeners(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_generic() { + attachInternalChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_generic() { + attachPublicChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListeners(); + final LongProperty v1 = new SimpleLongProperty(VALUE_1); + final LongProperty v2 = new SimpleLongProperty(VALUE_2); + property.bind(v1); + property.get(); + readOnlyProperty.get(); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change new binding + v2.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change old binding + v1.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListeners(); + final LongProperty v = new SimpleLongProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get()); + assertFalse(property.isBound()); + assertEquals(VALUE_1, readOnlyProperty.get()); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final LongProperty v = new SimpleLongProperty(VALUE_1); + final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); + + // setting the property,checking internal + property.set(VALUE_1); + property.addListener(internalListener2); + internalListener2.reset(); + property.set(VALUE_2); + internalListener2.check(property, 1); + + // setting the property, checking public + property.set(VALUE_1); + readOnlyProperty.addListener(publicListener2); + publicListener2.reset(); + property.set(VALUE_2); + publicListener2.check(readOnlyProperty, 1); + + // binding the property, checking internal + property.bind(v); + v.set(VALUE_2); + property.addListener(internalListener3); + v.get(); + internalListener3.reset(); + v.set(VALUE_1); + internalListener3.check(property, 1); + + // binding the property, checking public + property.bind(v); + v.set(VALUE_2); + readOnlyProperty.addListener(publicListener3); + v.get(); + publicListener3.reset(); + v.set(VALUE_1); + publicListener3.check(readOnlyProperty, 1); + } + + @Test + public void testRemoveListeners() { + attachInvalidationListeners(); + attachInternalChangeListener(); + property.removeListener(internalInvalidationListener); + property.removeListener(internalChangeListener); + property.get(); + internalInvalidationListener.reset(); + internalChangeListener.reset(); + + property.set(VALUE_1); + internalInvalidationListener.check(null, 0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // no read only property created => no-op + final ReadOnlyLongWrapper v1 = new ReadOnlyLongWrapper(); + v1.removeListener(internalInvalidationListener); + v1.removeListener(internalChangeListener); + } + + @Test + public void testNoReadOnlyPropertyCreated() { + final LongProperty v1 = new SimpleLongProperty(VALUE_1); + final ReadOnlyLongWrapper p1 = new ReadOnlyLongWrapper(); + + p1.set(VALUE_1); + p1.bind(v1); + assertEquals(VALUE_1, p1.get()); + v1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + } + + @Test + public void testToString() { + final LongProperty v1 = new SimpleLongProperty(VALUE_1); + + property.set(VALUE_1); + assertEquals("LongProperty [value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyLongProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + + property.bind(v1); + assertEquals("LongProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyLongProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("LongProperty [bound, value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyLongProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + v1.set(VALUE_2); + assertEquals("LongProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyLongProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("LongProperty [bound, value: " + VALUE_2 + "]", property.toString()); + assertEquals("ReadOnlyLongProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyLongWrapper v2 = new ReadOnlyLongWrapper(bean, name); + assertEquals("LongProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + assertEquals("ReadOnlyLongProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); + + final ReadOnlyLongWrapper v3 = new ReadOnlyLongWrapper(bean, ""); + assertEquals("LongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + assertEquals("ReadOnlyLongProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); + + final ReadOnlyLongWrapper v4 = new ReadOnlyLongWrapper(null, name); + assertEquals("LongProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); + assertEquals("ReadOnlyLongProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); + } + + private static class ReadOnlyLongWrapperMock extends ReadOnlyLongWrapper { + + private int counter; + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyMapPropertyBaseTest.java 2015-08-31 10:23:45.193217274 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.collections.FXCollections; -import javafx.collections.ObservableMap; -import org.junit.Before; -import org.junit.Test; - -import java.util.Collections; -import java.util.HashMap; - -import static org.junit.Assert.fail; - -public class ReadOnlyMapPropertyBaseTest { - - private static final Object UNDEFINED = null; - private static final Object DEFAULT = null; - private static final ObservableMap VALUE_1 = FXCollections.observableMap(Collections.emptyMap()); - private static final ObservableMap VALUE_2 = FXCollections.observableMap(Collections.singletonMap(new Object(), new Object())); - - private ReadOnlyPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - @Test - public void testInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_2); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(property, DEFAULT, VALUE_1, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_2); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - private static class ReadOnlyPropertyMock extends ReadOnlyMapPropertyBase { - - private ObservableMap value; - - @Override - public Object getBean() { - // not used - return null; - } - - @Override - public String getName() { - // not used - return null; - } - - private void set(ObservableMap value) { - this.value = value; - fireValueChangedEvent(); - } - - @Override - public ObservableMap get() { - return value; - } - - @Override - public ReadOnlyIntegerProperty sizeProperty() { - fail("Not in use"); - return null; - } - - @Override - public ReadOnlyBooleanProperty emptyProperty() { - fail("Not in use"); - return null; - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyMapPropertyBaseTest.java 2015-08-31 10:23:45.009217276 -0400 @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.collections.FXCollections; +import javafx.collections.ObservableMap; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.ReadOnlyMapPropertyBase; +import javafx.beans.property.ReadOnlyMapPropertyBaseShim; + +import static org.junit.Assert.fail; + +public class ReadOnlyMapPropertyBaseTest { + + private static final Object UNDEFINED = null; + private static final Object DEFAULT = null; + private static final ObservableMap VALUE_1 = FXCollections.observableMap(Collections.emptyMap()); + private static final ObservableMap VALUE_2 = FXCollections.observableMap(Collections.singletonMap(new Object(), new Object())); + + private ReadOnlyPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + @Test + public void testInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_2); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(property, DEFAULT, VALUE_1, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_2); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + private static class ReadOnlyPropertyMock extends ReadOnlyMapPropertyBase { + + private ObservableMap value; + + @Override + public Object getBean() { + // not used + return null; + } + + @Override + public String getName() { + // not used + return null; + } + + private void set(ObservableMap value) { + this.value = value; + ReadOnlyMapPropertyBaseShim.fireValueChangedEvent(this); + } + + @Override + public ObservableMap get() { + return value; + } + + @Override + public ReadOnlyIntegerProperty sizeProperty() { + fail("Not in use"); + return null; + } + + @Override + public ReadOnlyBooleanProperty emptyProperty() { + fail("Not in use"); + return null; + } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyMapPropertyTest.java 2015-08-31 10:23:45.837217267 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.collections.MapChangeListener; -import javafx.collections.ObservableMap; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class ReadOnlyMapPropertyTest { - - private static final Object DEFAULT = null; - - @Before - public void setUp() throws Exception { - } - - @Test - public void testToString() { - final ReadOnlyMapProperty v1 = new ReadOnlyMapPropertyStub(null, ""); - assertEquals("ReadOnlyMapProperty [value: " + DEFAULT + "]", v1.toString()); - - final ReadOnlyMapProperty v2 = new ReadOnlyMapPropertyStub(null, null); - assertEquals("ReadOnlyMapProperty [value: " + DEFAULT + "]", v2.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyMapProperty v3 = new ReadOnlyMapPropertyStub(bean, name); - assertEquals("ReadOnlyMapProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); - - final ReadOnlyMapProperty v4 = new ReadOnlyMapPropertyStub(bean, ""); - assertEquals("ReadOnlyMapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - - final ReadOnlyMapProperty v5 = new ReadOnlyMapPropertyStub(bean, null); - assertEquals("ReadOnlyMapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); - - final ReadOnlyMapProperty v6 = new ReadOnlyMapPropertyStub(null, name); - assertEquals("ReadOnlyMapProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); - - } - - private static class ReadOnlyMapPropertyStub extends ReadOnlyMapProperty { - - private final Object bean; - private final String name; - - private ReadOnlyMapPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override public Object getBean() { return bean; } - @Override public String getName() { return name; } - @Override public ObservableMap get() { return null; } - - @Override - public void addListener(ChangeListener> listener) { - } - - @Override - public void removeListener(ChangeListener> listener) { - } - - @Override - public void addListener(InvalidationListener listener) { - } - - @Override - public void removeListener(InvalidationListener listener) { - } - - @Override - public void addListener(MapChangeListener listChangeListener) { - } - - @Override - public void removeListener(MapChangeListener listChangeListener) { - } - - @Override - public ReadOnlyIntegerProperty sizeProperty() { - fail("Not in use"); - return null; - } - - @Override - public ReadOnlyBooleanProperty emptyProperty() { - fail("Not in use"); - return null; - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyMapPropertyTest.java 2015-08-31 10:23:45.705217269 -0400 @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.InvalidationListener; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.ReadOnlyMapProperty; +import javafx.beans.value.ChangeListener; +import javafx.collections.MapChangeListener; +import javafx.collections.ObservableMap; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ReadOnlyMapPropertyTest { + + private static final Object DEFAULT = null; + + @Before + public void setUp() throws Exception { + } + + @Test + public void testToString() { + final ReadOnlyMapProperty v1 = new ReadOnlyMapPropertyStub(null, ""); + assertEquals("ReadOnlyMapProperty [value: " + DEFAULT + "]", v1.toString()); + + final ReadOnlyMapProperty v2 = new ReadOnlyMapPropertyStub(null, null); + assertEquals("ReadOnlyMapProperty [value: " + DEFAULT + "]", v2.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyMapProperty v3 = new ReadOnlyMapPropertyStub(bean, name); + assertEquals("ReadOnlyMapProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); + + final ReadOnlyMapProperty v4 = new ReadOnlyMapPropertyStub(bean, ""); + assertEquals("ReadOnlyMapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + + final ReadOnlyMapProperty v5 = new ReadOnlyMapPropertyStub(bean, null); + assertEquals("ReadOnlyMapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); + + final ReadOnlyMapProperty v6 = new ReadOnlyMapPropertyStub(null, name); + assertEquals("ReadOnlyMapProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); + + } + + private static class ReadOnlyMapPropertyStub extends ReadOnlyMapProperty { + + private final Object bean; + private final String name; + + private ReadOnlyMapPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override public Object getBean() { return bean; } + @Override public String getName() { return name; } + @Override public ObservableMap get() { return null; } + + @Override + public void addListener(ChangeListener> listener) { + } + + @Override + public void removeListener(ChangeListener> listener) { + } + + @Override + public void addListener(InvalidationListener listener) { + } + + @Override + public void removeListener(InvalidationListener listener) { + } + + @Override + public void addListener(MapChangeListener listChangeListener) { + } + + @Override + public void removeListener(MapChangeListener listChangeListener) { + } + + @Override + public ReadOnlyIntegerProperty sizeProperty() { + fail("Not in use"); + return null; + } + + @Override + public ReadOnlyBooleanProperty emptyProperty() { + fail("Not in use"); + return null; + } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyMapWrapperTest.java 2015-08-31 10:23:46.449217260 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,758 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableObjectValueStub; -import javafx.collections.FXCollections; -import javafx.collections.ObservableMap; -import org.junit.Before; -import org.junit.Test; - -import java.util.Collections; - -import static org.junit.Assert.*; - -public class ReadOnlyMapWrapperTest { - - private static final Object UNDEFINED = null; - private static final ObservableMap DEFAULT = null; - private static final ObservableMap VALUE_1 = FXCollections.observableMap(Collections.emptyMap()); - private static final ObservableMap VALUE_2 = FXCollections.observableMap(Collections.singletonMap(new Object(), new Object())); - - private ReadOnlyMapWrapperMock property; - private ReadOnlyMapProperty readOnlyProperty; - private InvalidationListenerMock internalInvalidationListener; - private InvalidationListenerMock publicInvalidationListener; - private ChangeListenerMock internalChangeListener; - private ChangeListenerMock publicChangeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyMapWrapperMock(); - readOnlyProperty = property.getReadOnlyProperty(); - internalInvalidationListener = new InvalidationListenerMock(); - publicInvalidationListener = new InvalidationListenerMock(); - internalChangeListener = new ChangeListenerMock(UNDEFINED); - publicChangeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListeners() { - property.addListener(internalInvalidationListener); - readOnlyProperty.addListener(publicInvalidationListener); - property.get(); - readOnlyProperty.get(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - } - - private void attachInternalChangeListener() { - property.addListener(internalChangeListener); - property.get(); - internalChangeListener.reset(); - } - - private void attachPublicChangeListener() { - readOnlyProperty.addListener(publicChangeListener); - readOnlyProperty.get(); - publicChangeListener.reset(); - } - - @Test - public void testConstructor_NoArguments() { - final ReadOnlyMapWrapper p1 = new ReadOnlyMapWrapper(); - assertEquals(DEFAULT, p1.get()); - assertEquals((Object)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyMapProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Object)DEFAULT, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_InitialValue() { - final ReadOnlyMapWrapper p1 = new ReadOnlyMapWrapper(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Object)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyMapProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Object)VALUE_1, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyMapWrapper p1 = new ReadOnlyMapWrapper(bean, name); - assertEquals(DEFAULT, p1.get()); - assertEquals((Object)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyMapProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Object)DEFAULT, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyMapWrapper p1 = new ReadOnlyMapWrapper(bean, name, VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Object)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyMapProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Object)VALUE_1, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testLazyMap() { - attachInvalidationListeners(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerMap() { - attachInternalChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerMap() { - attachPublicChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test - public void testLazyMapValue() { - attachInvalidationListeners(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerMapValue() { - attachInternalChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerMapValue() { - attachPublicChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testMapBoundValue() { - final MapProperty v = new SimpleMapProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind_primitive() { - attachInvalidationListeners(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_primitive() { - attachInternalChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_primitive() { - attachPublicChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test - public void testLazyBind_generic() { - attachInvalidationListeners(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_generic() { - attachInternalChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_generic() { - attachPublicChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListeners(); - final MapProperty v1 = new SimpleMapProperty(VALUE_1); - final MapProperty v2 = new SimpleMapProperty(VALUE_2); - property.bind(v1); - property.get(); - readOnlyProperty.get(); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change new binding - v2.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change old binding - v1.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListeners(); - final MapProperty v = new SimpleMapProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get()); - assertFalse(property.isBound()); - assertEquals(VALUE_1, readOnlyProperty.get()); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final MapProperty v = new SimpleMapProperty(VALUE_1); - final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); - - // setting the property,checking internal - property.set(VALUE_1); - property.addListener(internalListener2); - internalListener2.reset(); - property.set(VALUE_2); - internalListener2.check(property, 1); - - // setting the property, checking public - property.set(VALUE_1); - readOnlyProperty.addListener(publicListener2); - publicListener2.reset(); - property.set(VALUE_2); - publicListener2.check(readOnlyProperty, 1); - - // binding the property, checking internal - property.bind(v); - v.set(VALUE_2); - property.addListener(internalListener3); - v.get(); - internalListener3.reset(); - v.set(VALUE_1); - internalListener3.check(property, 1); - - // binding the property, checking public - property.bind(v); - v.set(VALUE_2); - readOnlyProperty.addListener(publicListener3); - v.get(); - publicListener3.reset(); - v.set(VALUE_1); - publicListener3.check(readOnlyProperty, 1); - } - - @Test - public void testRemoveListeners() { - attachInvalidationListeners(); - attachInternalChangeListener(); - property.removeListener(internalInvalidationListener); - property.removeListener(internalChangeListener); - property.get(); - internalInvalidationListener.reset(); - internalChangeListener.reset(); - - property.set(VALUE_1); - internalInvalidationListener.check(null, 0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // no read only property created => no-op - final ReadOnlyMapWrapper v1 = new ReadOnlyMapWrapper(); - v1.removeListener(internalInvalidationListener); - v1.removeListener(internalChangeListener); - } - - @Test - public void testNoReadOnlyPropertyCreated() { - final MapProperty v1 = new SimpleMapProperty(VALUE_1); - final ReadOnlyMapWrapper p1 = new ReadOnlyMapWrapper(); - - p1.set(VALUE_1); - p1.bind(v1); - assertEquals(VALUE_1, p1.get()); - v1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - } - - @Test - public void testToString() { - final MapProperty v1 = new SimpleMapProperty(VALUE_1); - - property.set(VALUE_1); - assertEquals("MapProperty [value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyMapProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - - property.bind(v1); - assertEquals("MapProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyMapProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("MapProperty [bound, value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyMapProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - v1.set(VALUE_2); - assertEquals("MapProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyMapProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("MapProperty [bound, value: " + VALUE_2 + "]", property.toString()); - assertEquals("ReadOnlyMapProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyMapWrapper v2 = new ReadOnlyMapWrapper(bean, name); - assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - assertEquals("ReadOnlyMapProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); - - final ReadOnlyMapWrapper v3 = new ReadOnlyMapWrapper(bean, ""); - assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - assertEquals("ReadOnlyMapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); - - final ReadOnlyMapWrapper v4 = new ReadOnlyMapWrapper(null, name); - assertEquals("MapProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); - assertEquals("ReadOnlyMapProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); - } - - private static class ReadOnlyMapWrapperMock extends ReadOnlyMapWrapper { - - private int counter; - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyMapWrapperTest.java 2015-08-31 10:23:46.317217262 -0400 @@ -0,0 +1,762 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableObjectValueStub; +import javafx.collections.FXCollections; +import javafx.collections.ObservableMap; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import javafx.beans.property.MapProperty; +import javafx.beans.property.ReadOnlyMapProperty; +import javafx.beans.property.ReadOnlyMapWrapper; +import javafx.beans.property.SimpleMapProperty; + +import static org.junit.Assert.*; + +public class ReadOnlyMapWrapperTest { + + private static final Object UNDEFINED = null; + private static final ObservableMap DEFAULT = null; + private static final ObservableMap VALUE_1 = FXCollections.observableMap(Collections.emptyMap()); + private static final ObservableMap VALUE_2 = FXCollections.observableMap(Collections.singletonMap(new Object(), new Object())); + + private ReadOnlyMapWrapperMock property; + private ReadOnlyMapProperty readOnlyProperty; + private InvalidationListenerMock internalInvalidationListener; + private InvalidationListenerMock publicInvalidationListener; + private ChangeListenerMock internalChangeListener; + private ChangeListenerMock publicChangeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyMapWrapperMock(); + readOnlyProperty = property.getReadOnlyProperty(); + internalInvalidationListener = new InvalidationListenerMock(); + publicInvalidationListener = new InvalidationListenerMock(); + internalChangeListener = new ChangeListenerMock(UNDEFINED); + publicChangeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListeners() { + property.addListener(internalInvalidationListener); + readOnlyProperty.addListener(publicInvalidationListener); + property.get(); + readOnlyProperty.get(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + } + + private void attachInternalChangeListener() { + property.addListener(internalChangeListener); + property.get(); + internalChangeListener.reset(); + } + + private void attachPublicChangeListener() { + readOnlyProperty.addListener(publicChangeListener); + readOnlyProperty.get(); + publicChangeListener.reset(); + } + + @Test + public void testConstructor_NoArguments() { + final ReadOnlyMapWrapper p1 = new ReadOnlyMapWrapper(); + assertEquals(DEFAULT, p1.get()); + assertEquals((Object)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyMapProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Object)DEFAULT, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_InitialValue() { + final ReadOnlyMapWrapper p1 = new ReadOnlyMapWrapper(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Object)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyMapProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Object)VALUE_1, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyMapWrapper p1 = new ReadOnlyMapWrapper(bean, name); + assertEquals(DEFAULT, p1.get()); + assertEquals((Object)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyMapProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Object)DEFAULT, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyMapWrapper p1 = new ReadOnlyMapWrapper(bean, name, VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Object)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyMapProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Object)VALUE_1, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testLazyMap() { + attachInvalidationListeners(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerMap() { + attachInternalChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerMap() { + attachPublicChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test + public void testLazyMapValue() { + attachInvalidationListeners(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerMapValue() { + attachInternalChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerMapValue() { + attachPublicChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testMapBoundValue() { + final MapProperty v = new SimpleMapProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind_primitive() { + attachInvalidationListeners(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_primitive() { + attachInternalChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_primitive() { + attachPublicChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test + public void testLazyBind_generic() { + attachInvalidationListeners(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_generic() { + attachInternalChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_generic() { + attachPublicChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListeners(); + final MapProperty v1 = new SimpleMapProperty(VALUE_1); + final MapProperty v2 = new SimpleMapProperty(VALUE_2); + property.bind(v1); + property.get(); + readOnlyProperty.get(); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change new binding + v2.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change old binding + v1.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListeners(); + final MapProperty v = new SimpleMapProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get()); + assertFalse(property.isBound()); + assertEquals(VALUE_1, readOnlyProperty.get()); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final MapProperty v = new SimpleMapProperty(VALUE_1); + final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); + + // setting the property,checking internal + property.set(VALUE_1); + property.addListener(internalListener2); + internalListener2.reset(); + property.set(VALUE_2); + internalListener2.check(property, 1); + + // setting the property, checking public + property.set(VALUE_1); + readOnlyProperty.addListener(publicListener2); + publicListener2.reset(); + property.set(VALUE_2); + publicListener2.check(readOnlyProperty, 1); + + // binding the property, checking internal + property.bind(v); + v.set(VALUE_2); + property.addListener(internalListener3); + v.get(); + internalListener3.reset(); + v.set(VALUE_1); + internalListener3.check(property, 1); + + // binding the property, checking public + property.bind(v); + v.set(VALUE_2); + readOnlyProperty.addListener(publicListener3); + v.get(); + publicListener3.reset(); + v.set(VALUE_1); + publicListener3.check(readOnlyProperty, 1); + } + + @Test + public void testRemoveListeners() { + attachInvalidationListeners(); + attachInternalChangeListener(); + property.removeListener(internalInvalidationListener); + property.removeListener(internalChangeListener); + property.get(); + internalInvalidationListener.reset(); + internalChangeListener.reset(); + + property.set(VALUE_1); + internalInvalidationListener.check(null, 0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // no read only property created => no-op + final ReadOnlyMapWrapper v1 = new ReadOnlyMapWrapper(); + v1.removeListener(internalInvalidationListener); + v1.removeListener(internalChangeListener); + } + + @Test + public void testNoReadOnlyPropertyCreated() { + final MapProperty v1 = new SimpleMapProperty(VALUE_1); + final ReadOnlyMapWrapper p1 = new ReadOnlyMapWrapper(); + + p1.set(VALUE_1); + p1.bind(v1); + assertEquals(VALUE_1, p1.get()); + v1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + } + + @Test + public void testToString() { + final MapProperty v1 = new SimpleMapProperty(VALUE_1); + + property.set(VALUE_1); + assertEquals("MapProperty [value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyMapProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + + property.bind(v1); + assertEquals("MapProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyMapProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("MapProperty [bound, value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyMapProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + v1.set(VALUE_2); + assertEquals("MapProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyMapProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("MapProperty [bound, value: " + VALUE_2 + "]", property.toString()); + assertEquals("ReadOnlyMapProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyMapWrapper v2 = new ReadOnlyMapWrapper(bean, name); + assertEquals("MapProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + assertEquals("ReadOnlyMapProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); + + final ReadOnlyMapWrapper v3 = new ReadOnlyMapWrapper(bean, ""); + assertEquals("MapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + assertEquals("ReadOnlyMapProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); + + final ReadOnlyMapWrapper v4 = new ReadOnlyMapWrapper(null, name); + assertEquals("MapProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); + assertEquals("ReadOnlyMapProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); + } + + private static class ReadOnlyMapWrapperMock extends ReadOnlyMapWrapper { + + private int counter; + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyObjectPropertyBaseTest.java 2015-08-31 10:23:47.049217253 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyObjectPropertyBaseTest { - - private static final Object UNDEFINED = null; - private static final Object DEFAULT = null; - private static final Object VALUE_1 = new Object(); - private static final Object VALUE_2 = new Object(); - - private ReadOnlyPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - @Test - public void testInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_2); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(property, DEFAULT, VALUE_1, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_2); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - private static class ReadOnlyPropertyMock extends ReadOnlyObjectPropertyBase { - - private Object value; - - @Override - public Object getBean() { - // not used - return null; - } - - @Override - public String getName() { - // not used - return null; - } - - private void set(Object value) { - this.value = value; - fireValueChangedEvent(); - } - - @Override - public Object get() { - return value; - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyObjectPropertyBaseTest.java 2015-08-31 10:23:46.913217255 -0400 @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.ReadOnlyObjectPropertyBase; +import javafx.beans.property.ReadOnlyObjectPropertyBaseShim; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyObjectPropertyBaseTest { + + private static final Object UNDEFINED = null; + private static final Object DEFAULT = null; + private static final Object VALUE_1 = new Object(); + private static final Object VALUE_2 = new Object(); + + private ReadOnlyPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + @Test + public void testInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_2); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(property, DEFAULT, VALUE_1, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_2); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + private static class ReadOnlyPropertyMock extends ReadOnlyObjectPropertyBase { + + private Object value; + + @Override + public Object getBean() { + // not used + return null; + } + + @Override + public String getName() { + // not used + return null; + } + + private void set(Object value) { + this.value = value; + ReadOnlyObjectPropertyBaseShim.fireValueChangedEvent(this); + } + + @Override + public Object get() { + return value; + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyObjectPropertyTest.java 2015-08-31 10:23:47.645217247 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyObjectPropertyTest { - - private static final Object DEFAULT = null; - - @Before - public void setUp() throws Exception { - } - - - @Test - public void testToString() { - final ReadOnlyObjectProperty v1 = new ReadOnlyObjectPropertyStub(null, ""); - assertEquals("ReadOnlyObjectProperty [value: " + DEFAULT + "]", v1.toString()); - - final ReadOnlyObjectProperty v2 = new ReadOnlyObjectPropertyStub(null, null); - assertEquals("ReadOnlyObjectProperty [value: " + DEFAULT + "]", v2.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyObjectProperty v3 = new ReadOnlyObjectPropertyStub(bean, name); - assertEquals("ReadOnlyObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); - - final ReadOnlyObjectProperty v4 = new ReadOnlyObjectPropertyStub(bean, ""); - assertEquals("ReadOnlyObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - - final ReadOnlyObjectProperty v5 = new ReadOnlyObjectPropertyStub(bean, null); - assertEquals("ReadOnlyObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); - - final ReadOnlyObjectProperty v6 = new ReadOnlyObjectPropertyStub(null, name); - assertEquals("ReadOnlyObjectProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); - - } - - private static class ReadOnlyObjectPropertyStub extends ReadOnlyObjectProperty { - - private final Object bean; - private final String name; - - private ReadOnlyObjectPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override public Object getBean() { return bean; } - @Override public String getName() { return name; } - @Override public Object get() { return null; } - - @Override - public void addListener(ChangeListener listener) { - } - - @Override - public void removeListener(ChangeListener listener) { - } - - @Override - public void addListener(InvalidationListener listener) { - } - - @Override - public void removeListener(InvalidationListener listener) { - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyObjectPropertyTest.java 2015-08-31 10:23:47.513217248 -0400 @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import javafx.beans.InvalidationListener; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.beans.value.ChangeListener; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyObjectPropertyTest { + + private static final Object DEFAULT = null; + + @Before + public void setUp() throws Exception { + } + + + @Test + public void testToString() { + final ReadOnlyObjectProperty v1 = new ReadOnlyObjectPropertyStub(null, ""); + assertEquals("ReadOnlyObjectProperty [value: " + DEFAULT + "]", v1.toString()); + + final ReadOnlyObjectProperty v2 = new ReadOnlyObjectPropertyStub(null, null); + assertEquals("ReadOnlyObjectProperty [value: " + DEFAULT + "]", v2.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyObjectProperty v3 = new ReadOnlyObjectPropertyStub(bean, name); + assertEquals("ReadOnlyObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); + + final ReadOnlyObjectProperty v4 = new ReadOnlyObjectPropertyStub(bean, ""); + assertEquals("ReadOnlyObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + + final ReadOnlyObjectProperty v5 = new ReadOnlyObjectPropertyStub(bean, null); + assertEquals("ReadOnlyObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); + + final ReadOnlyObjectProperty v6 = new ReadOnlyObjectPropertyStub(null, name); + assertEquals("ReadOnlyObjectProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); + + } + + private static class ReadOnlyObjectPropertyStub extends ReadOnlyObjectProperty { + + private final Object bean; + private final String name; + + private ReadOnlyObjectPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override public Object getBean() { return bean; } + @Override public String getName() { return name; } + @Override public Object get() { return null; } + + @Override + public void addListener(ChangeListener listener) { + } + + @Override + public void removeListener(ChangeListener listener) { + } + + @Override + public void addListener(InvalidationListener listener) { + } + + @Override + public void removeListener(InvalidationListener listener) { + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyObjectWrapperTest.java 2015-08-31 10:23:48.509217237 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,757 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableObjectValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyObjectWrapperTest { - - private static final Object UNDEFINED = null; - private static final Object DEFAULT = null; - private static final Object VALUE_1 = new Object(); - private static final Object VALUE_2 = new Object(); - - private ReadOnlyObjectWrapperMock property; - private ReadOnlyObjectProperty readOnlyProperty; - private InvalidationListenerMock internalInvalidationListener; - private InvalidationListenerMock publicInvalidationListener; - private ChangeListenerMock internalChangeListener; - private ChangeListenerMock publicChangeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyObjectWrapperMock(); - readOnlyProperty = property.getReadOnlyProperty(); - internalInvalidationListener = new InvalidationListenerMock(); - publicInvalidationListener = new InvalidationListenerMock(); - internalChangeListener = new ChangeListenerMock(UNDEFINED); - publicChangeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListeners() { - property.addListener(internalInvalidationListener); - readOnlyProperty.addListener(publicInvalidationListener); - property.get(); - readOnlyProperty.get(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - } - - private void attachInternalChangeListener() { - property.addListener(internalChangeListener); - property.get(); - internalChangeListener.reset(); - } - - private void attachPublicChangeListener() { - readOnlyProperty.addListener(publicChangeListener); - readOnlyProperty.get(); - publicChangeListener.reset(); - } - - @Test - public void testConstructor_NoArguments() { - final ReadOnlyObjectWrapper p1 = new ReadOnlyObjectWrapper(); - assertEquals(DEFAULT, p1.get()); - assertEquals((Object)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyObjectProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Object)DEFAULT, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_InitialValue() { - final ReadOnlyObjectWrapper p1 = new ReadOnlyObjectWrapper(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Object)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyObjectProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Object)VALUE_1, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyObjectWrapper p1 = new ReadOnlyObjectWrapper(bean, name); - assertEquals(DEFAULT, p1.get()); - assertEquals((Object)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyObjectProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Object)DEFAULT, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyObjectWrapper p1 = new ReadOnlyObjectWrapper(bean, name, VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Object)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyObjectProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Object)VALUE_1, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testLazySet() { - attachInvalidationListeners(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSet() { - attachInternalChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSet() { - attachPublicChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListeners(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSetValue() { - attachInternalChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSetValue() { - attachPublicChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final ObjectProperty v = new SimpleObjectProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind_primitive() { - attachInvalidationListeners(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_primitive() { - attachInternalChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_primitive() { - attachPublicChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test - public void testLazyBind_generic() { - attachInvalidationListeners(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_generic() { - attachInternalChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_generic() { - attachPublicChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListeners(); - final ObjectProperty v1 = new SimpleObjectProperty(VALUE_1); - final ObjectProperty v2 = new SimpleObjectProperty(VALUE_2); - property.bind(v1); - property.get(); - readOnlyProperty.get(); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change new binding - v2.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change old binding - v1.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListeners(); - final ObjectProperty v = new SimpleObjectProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get()); - assertFalse(property.isBound()); - assertEquals(VALUE_1, readOnlyProperty.get()); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final ObjectProperty v = new SimpleObjectProperty(VALUE_1); - final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); - - // setting the property,checking internal - property.set(VALUE_1); - property.addListener(internalListener2); - internalListener2.reset(); - property.set(VALUE_2); - internalListener2.check(property, 1); - - // setting the property, checking public - property.set(VALUE_1); - readOnlyProperty.addListener(publicListener2); - publicListener2.reset(); - property.set(VALUE_2); - publicListener2.check(readOnlyProperty, 1); - - // binding the property, checking internal - property.bind(v); - v.set(VALUE_2); - property.addListener(internalListener3); - v.get(); - internalListener3.reset(); - v.set(VALUE_1); - internalListener3.check(property, 1); - - // binding the property, checking public - property.bind(v); - v.set(VALUE_2); - readOnlyProperty.addListener(publicListener3); - v.get(); - publicListener3.reset(); - v.set(VALUE_1); - publicListener3.check(readOnlyProperty, 1); - } - - @Test - public void testRemoveListeners() { - attachInvalidationListeners(); - attachInternalChangeListener(); - property.removeListener(internalInvalidationListener); - property.removeListener(internalChangeListener); - property.get(); - internalInvalidationListener.reset(); - internalChangeListener.reset(); - - property.set(VALUE_1); - internalInvalidationListener.check(null, 0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // no read only property created => no-op - final ReadOnlyObjectWrapper v1 = new ReadOnlyObjectWrapper(); - v1.removeListener(internalInvalidationListener); - v1.removeListener(internalChangeListener); - } - - @Test - public void testNoReadOnlyPropertyCreated() { - final ObjectProperty v1 = new SimpleObjectProperty(VALUE_1); - final ReadOnlyObjectWrapper p1 = new ReadOnlyObjectWrapper(); - - p1.set(VALUE_1); - p1.bind(v1); - assertEquals(VALUE_1, p1.get()); - v1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - } - - @Test - public void testToString() { - final ObjectProperty v1 = new SimpleObjectProperty(VALUE_1); - - property.set(VALUE_1); - assertEquals("ObjectProperty [value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyObjectProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - - property.bind(v1); - assertEquals("ObjectProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyObjectProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("ObjectProperty [bound, value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyObjectProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - v1.set(VALUE_2); - assertEquals("ObjectProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyObjectProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("ObjectProperty [bound, value: " + VALUE_2 + "]", property.toString()); - assertEquals("ReadOnlyObjectProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyObjectWrapper v2 = new ReadOnlyObjectWrapper(bean, name); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - assertEquals("ReadOnlyObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); - - final ReadOnlyObjectWrapper v3 = new ReadOnlyObjectWrapper(bean, ""); - assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - assertEquals("ReadOnlyObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); - - final ReadOnlyObjectWrapper v4 = new ReadOnlyObjectWrapper(null, name); - assertEquals("ObjectProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); - assertEquals("ReadOnlyObjectProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); - } - - private static class ReadOnlyObjectWrapperMock extends ReadOnlyObjectWrapper { - - private int counter; - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyObjectWrapperTest.java 2015-08-31 10:23:48.297217239 -0400 @@ -0,0 +1,761 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.beans.property.SimpleObjectProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableObjectValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyObjectWrapperTest { + + private static final Object UNDEFINED = null; + private static final Object DEFAULT = null; + private static final Object VALUE_1 = new Object(); + private static final Object VALUE_2 = new Object(); + + private ReadOnlyObjectWrapperMock property; + private ReadOnlyObjectProperty readOnlyProperty; + private InvalidationListenerMock internalInvalidationListener; + private InvalidationListenerMock publicInvalidationListener; + private ChangeListenerMock internalChangeListener; + private ChangeListenerMock publicChangeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyObjectWrapperMock(); + readOnlyProperty = property.getReadOnlyProperty(); + internalInvalidationListener = new InvalidationListenerMock(); + publicInvalidationListener = new InvalidationListenerMock(); + internalChangeListener = new ChangeListenerMock(UNDEFINED); + publicChangeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListeners() { + property.addListener(internalInvalidationListener); + readOnlyProperty.addListener(publicInvalidationListener); + property.get(); + readOnlyProperty.get(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + } + + private void attachInternalChangeListener() { + property.addListener(internalChangeListener); + property.get(); + internalChangeListener.reset(); + } + + private void attachPublicChangeListener() { + readOnlyProperty.addListener(publicChangeListener); + readOnlyProperty.get(); + publicChangeListener.reset(); + } + + @Test + public void testConstructor_NoArguments() { + final ReadOnlyObjectWrapper p1 = new ReadOnlyObjectWrapper(); + assertEquals(DEFAULT, p1.get()); + assertEquals((Object)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyObjectProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Object)DEFAULT, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_InitialValue() { + final ReadOnlyObjectWrapper p1 = new ReadOnlyObjectWrapper(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Object)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyObjectProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Object)VALUE_1, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyObjectWrapper p1 = new ReadOnlyObjectWrapper(bean, name); + assertEquals(DEFAULT, p1.get()); + assertEquals((Object)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyObjectProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Object)DEFAULT, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyObjectWrapper p1 = new ReadOnlyObjectWrapper(bean, name, VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Object)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyObjectProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Object)VALUE_1, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testLazySet() { + attachInvalidationListeners(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSet() { + attachInternalChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSet() { + attachPublicChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListeners(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSetValue() { + attachInternalChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSetValue() { + attachPublicChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final ObjectProperty v = new SimpleObjectProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind_primitive() { + attachInvalidationListeners(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_primitive() { + attachInternalChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_primitive() { + attachPublicChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test + public void testLazyBind_generic() { + attachInvalidationListeners(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_generic() { + attachInternalChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_generic() { + attachPublicChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListeners(); + final ObjectProperty v1 = new SimpleObjectProperty(VALUE_1); + final ObjectProperty v2 = new SimpleObjectProperty(VALUE_2); + property.bind(v1); + property.get(); + readOnlyProperty.get(); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change new binding + v2.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change old binding + v1.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListeners(); + final ObjectProperty v = new SimpleObjectProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get()); + assertFalse(property.isBound()); + assertEquals(VALUE_1, readOnlyProperty.get()); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final ObjectProperty v = new SimpleObjectProperty(VALUE_1); + final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); + + // setting the property,checking internal + property.set(VALUE_1); + property.addListener(internalListener2); + internalListener2.reset(); + property.set(VALUE_2); + internalListener2.check(property, 1); + + // setting the property, checking public + property.set(VALUE_1); + readOnlyProperty.addListener(publicListener2); + publicListener2.reset(); + property.set(VALUE_2); + publicListener2.check(readOnlyProperty, 1); + + // binding the property, checking internal + property.bind(v); + v.set(VALUE_2); + property.addListener(internalListener3); + v.get(); + internalListener3.reset(); + v.set(VALUE_1); + internalListener3.check(property, 1); + + // binding the property, checking public + property.bind(v); + v.set(VALUE_2); + readOnlyProperty.addListener(publicListener3); + v.get(); + publicListener3.reset(); + v.set(VALUE_1); + publicListener3.check(readOnlyProperty, 1); + } + + @Test + public void testRemoveListeners() { + attachInvalidationListeners(); + attachInternalChangeListener(); + property.removeListener(internalInvalidationListener); + property.removeListener(internalChangeListener); + property.get(); + internalInvalidationListener.reset(); + internalChangeListener.reset(); + + property.set(VALUE_1); + internalInvalidationListener.check(null, 0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // no read only property created => no-op + final ReadOnlyObjectWrapper v1 = new ReadOnlyObjectWrapper(); + v1.removeListener(internalInvalidationListener); + v1.removeListener(internalChangeListener); + } + + @Test + public void testNoReadOnlyPropertyCreated() { + final ObjectProperty v1 = new SimpleObjectProperty(VALUE_1); + final ReadOnlyObjectWrapper p1 = new ReadOnlyObjectWrapper(); + + p1.set(VALUE_1); + p1.bind(v1); + assertEquals(VALUE_1, p1.get()); + v1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + } + + @Test + public void testToString() { + final ObjectProperty v1 = new SimpleObjectProperty(VALUE_1); + + property.set(VALUE_1); + assertEquals("ObjectProperty [value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyObjectProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + + property.bind(v1); + assertEquals("ObjectProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyObjectProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("ObjectProperty [bound, value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyObjectProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + v1.set(VALUE_2); + assertEquals("ObjectProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyObjectProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("ObjectProperty [bound, value: " + VALUE_2 + "]", property.toString()); + assertEquals("ReadOnlyObjectProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyObjectWrapper v2 = new ReadOnlyObjectWrapper(bean, name); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + assertEquals("ReadOnlyObjectProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); + + final ReadOnlyObjectWrapper v3 = new ReadOnlyObjectWrapper(bean, ""); + assertEquals("ObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + assertEquals("ReadOnlyObjectProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); + + final ReadOnlyObjectWrapper v4 = new ReadOnlyObjectWrapper(null, name); + assertEquals("ObjectProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); + assertEquals("ReadOnlyObjectProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); + } + + private static class ReadOnlyObjectWrapperMock extends ReadOnlyObjectWrapper { + + private int counter; + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlySetPropertyBaseTest.java 2015-08-31 10:23:49.109217230 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.collections.FXCollections; -import javafx.collections.ObservableSet; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.fail; - -public class ReadOnlySetPropertyBaseTest { - - private static final Object UNDEFINED = null; - private static final Object DEFAULT = null; - private static final ObservableSet VALUE_1 = FXCollections.observableSet(); - private static final ObservableSet VALUE_2 = FXCollections.observableSet(new Object()); - - private ReadOnlyPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - @Test - public void testInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_2); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(property, DEFAULT, VALUE_1, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_2); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - private static class ReadOnlyPropertyMock extends ReadOnlySetPropertyBase { - - private ObservableSet value; - - @Override - public Object getBean() { - // not used - return null; - } - - @Override - public String getName() { - // not used - return null; - } - - private void set(ObservableSet value) { - this.value = value; - fireValueChangedEvent(); - } - - @Override - public ObservableSet get() { - return value; - } - - @Override - public ReadOnlyIntegerProperty sizeProperty() { - fail("Not in use"); - return null; - } - - @Override - public ReadOnlyBooleanProperty emptyProperty() { - fail("Not in use"); - return null; - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlySetPropertyBaseTest.java 2015-08-31 10:23:48.973217232 -0400 @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.ReadOnlySetPropertyBase; +import javafx.beans.property.ReadOnlySetPropertyBaseShim; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.collections.FXCollections; +import javafx.collections.ObservableSet; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class ReadOnlySetPropertyBaseTest { + + private static final Object UNDEFINED = null; + private static final Object DEFAULT = null; + private static final ObservableSet VALUE_1 = FXCollections.observableSet(); + private static final ObservableSet VALUE_2 = FXCollections.observableSet(new Object()); + + private ReadOnlyPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + @Test + public void testInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_2); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(property, DEFAULT, VALUE_1, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_2); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + private static class ReadOnlyPropertyMock extends ReadOnlySetPropertyBase { + + private ObservableSet value; + + @Override + public Object getBean() { + // not used + return null; + } + + @Override + public String getName() { + // not used + return null; + } + + private void set(ObservableSet value) { + this.value = value; + ReadOnlySetPropertyBaseShim.fireValueChangedEvent(this); + } + + @Override + public ObservableSet get() { + return value; + } + + @Override + public ReadOnlyIntegerProperty sizeProperty() { + fail("Not in use"); + return null; + } + + @Override + public ReadOnlyBooleanProperty emptyProperty() { + fail("Not in use"); + return null; + } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlySetPropertyTest.java 2015-08-31 10:23:49.801217222 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.collections.ObservableSet; -import javafx.collections.SetChangeListener; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class ReadOnlySetPropertyTest { - - private static final Object DEFAULT = null; - - @Before - public void setUp() throws Exception { - } - - - @Test - public void testToString() { - final ReadOnlySetProperty v1 = new ReadOnlySetPropertyStub(null, ""); - assertEquals("ReadOnlySetProperty [value: " + DEFAULT + "]", v1.toString()); - - final ReadOnlySetProperty v2 = new ReadOnlySetPropertyStub(null, null); - assertEquals("ReadOnlySetProperty [value: " + DEFAULT + "]", v2.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlySetProperty v3 = new ReadOnlySetPropertyStub(bean, name); - assertEquals("ReadOnlySetProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); - - final ReadOnlySetProperty v4 = new ReadOnlySetPropertyStub(bean, ""); - assertEquals("ReadOnlySetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - - final ReadOnlySetProperty v5 = new ReadOnlySetPropertyStub(bean, null); - assertEquals("ReadOnlySetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); - - final ReadOnlySetProperty v6 = new ReadOnlySetPropertyStub(null, name); - assertEquals("ReadOnlySetProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); - - } - - private static class ReadOnlySetPropertyStub extends ReadOnlySetProperty { - - private final Object bean; - private final String name; - - private ReadOnlySetPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override public Object getBean() { return bean; } - @Override public String getName() { return name; } - @Override public ObservableSet get() { return null; } - - @Override - public void addListener(ChangeListener> listener) { - } - - @Override - public void removeListener(ChangeListener> listener) { - } - - @Override - public void addListener(InvalidationListener listener) { - } - - @Override - public void removeListener(InvalidationListener listener) { - } - - @Override - public void addListener(SetChangeListener listChangeListener) { - } - - @Override - public void removeListener(SetChangeListener listChangeListener) { - } - - @Override - public ReadOnlyIntegerProperty sizeProperty() { - fail("Not in use"); - return null; - } - - @Override - public ReadOnlyBooleanProperty emptyProperty() { - fail("Not in use"); - return null; - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlySetPropertyTest.java 2015-08-31 10:23:49.585217225 -0400 @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.InvalidationListener; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.ReadOnlySetProperty; +import javafx.beans.value.ChangeListener; +import javafx.collections.ObservableSet; +import javafx.collections.SetChangeListener; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ReadOnlySetPropertyTest { + + private static final Object DEFAULT = null; + + @Before + public void setUp() throws Exception { + } + + + @Test + public void testToString() { + final ReadOnlySetProperty v1 = new ReadOnlySetPropertyStub(null, ""); + assertEquals("ReadOnlySetProperty [value: " + DEFAULT + "]", v1.toString()); + + final ReadOnlySetProperty v2 = new ReadOnlySetPropertyStub(null, null); + assertEquals("ReadOnlySetProperty [value: " + DEFAULT + "]", v2.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlySetProperty v3 = new ReadOnlySetPropertyStub(bean, name); + assertEquals("ReadOnlySetProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); + + final ReadOnlySetProperty v4 = new ReadOnlySetPropertyStub(bean, ""); + assertEquals("ReadOnlySetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + + final ReadOnlySetProperty v5 = new ReadOnlySetPropertyStub(bean, null); + assertEquals("ReadOnlySetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); + + final ReadOnlySetProperty v6 = new ReadOnlySetPropertyStub(null, name); + assertEquals("ReadOnlySetProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); + + } + + private static class ReadOnlySetPropertyStub extends ReadOnlySetProperty { + + private final Object bean; + private final String name; + + private ReadOnlySetPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override public Object getBean() { return bean; } + @Override public String getName() { return name; } + @Override public ObservableSet get() { return null; } + + @Override + public void addListener(ChangeListener> listener) { + } + + @Override + public void removeListener(ChangeListener> listener) { + } + + @Override + public void addListener(InvalidationListener listener) { + } + + @Override + public void removeListener(InvalidationListener listener) { + } + + @Override + public void addListener(SetChangeListener listChangeListener) { + } + + @Override + public void removeListener(SetChangeListener listChangeListener) { + } + + @Override + public ReadOnlyIntegerProperty sizeProperty() { + fail("Not in use"); + return null; + } + + @Override + public ReadOnlyBooleanProperty emptyProperty() { + fail("Not in use"); + return null; + } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlySetWrapperTest.java 2015-08-31 10:23:50.485217215 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,756 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableObjectValueStub; -import javafx.collections.FXCollections; -import javafx.collections.ObservableSet; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class ReadOnlySetWrapperTest { - - private static final Object UNDEFINED = null; - private static final ObservableSet DEFAULT = null; - private static final ObservableSet VALUE_1 = FXCollections.observableSet(); - private static final ObservableSet VALUE_2 = FXCollections.observableSet(new Object()); - - private ReadOnlySetWrapperMock property; - private ReadOnlySetProperty readOnlyProperty; - private InvalidationListenerMock internalInvalidationListener; - private InvalidationListenerMock publicInvalidationListener; - private ChangeListenerMock internalChangeListener; - private ChangeListenerMock publicChangeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlySetWrapperMock(); - readOnlyProperty = property.getReadOnlyProperty(); - internalInvalidationListener = new InvalidationListenerMock(); - publicInvalidationListener = new InvalidationListenerMock(); - internalChangeListener = new ChangeListenerMock(UNDEFINED); - publicChangeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListeners() { - property.addListener(internalInvalidationListener); - readOnlyProperty.addListener(publicInvalidationListener); - property.get(); - readOnlyProperty.get(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - } - - private void attachInternalChangeListener() { - property.addListener(internalChangeListener); - property.get(); - internalChangeListener.reset(); - } - - private void attachPublicChangeListener() { - readOnlyProperty.addListener(publicChangeListener); - readOnlyProperty.get(); - publicChangeListener.reset(); - } - - @Test - public void testConstructor_NoArguments() { - final ReadOnlySetWrapper p1 = new ReadOnlySetWrapper(); - assertEquals(DEFAULT, p1.get()); - assertEquals((Object)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlySetProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Object)DEFAULT, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_InitialValue() { - final ReadOnlySetWrapper p1 = new ReadOnlySetWrapper(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Object)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlySetProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Object)VALUE_1, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlySetWrapper p1 = new ReadOnlySetWrapper(bean, name); - assertEquals(DEFAULT, p1.get()); - assertEquals((Object)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlySetProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((Object)DEFAULT, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlySetWrapper p1 = new ReadOnlySetWrapper(bean, name, VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((Object)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlySetProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((Object)VALUE_1, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testLazySet() { - attachInvalidationListeners(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSet() { - attachInternalChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSet() { - attachPublicChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListeners(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSetValue() { - attachInternalChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSetValue() { - attachPublicChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final SetProperty v = new SimpleSetProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind_primitive() { - attachInvalidationListeners(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_primitive() { - attachInternalChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_primitive() { - attachPublicChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test - public void testLazyBind_generic() { - attachInvalidationListeners(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_generic() { - attachInternalChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_generic() { - attachPublicChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListeners(); - final SetProperty v1 = new SimpleSetProperty(VALUE_1); - final SetProperty v2 = new SimpleSetProperty(VALUE_2); - property.bind(v1); - property.get(); - readOnlyProperty.get(); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change new binding - v2.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change old binding - v1.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListeners(); - final SetProperty v = new SimpleSetProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get()); - assertFalse(property.isBound()); - assertEquals(VALUE_1, readOnlyProperty.get()); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final SetProperty v = new SimpleSetProperty(VALUE_1); - final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); - - // setting the property,checking internal - property.set(VALUE_1); - property.addListener(internalListener2); - internalListener2.reset(); - property.set(VALUE_2); - internalListener2.check(property, 1); - - // setting the property, checking public - property.set(VALUE_1); - readOnlyProperty.addListener(publicListener2); - publicListener2.reset(); - property.set(VALUE_2); - publicListener2.check(readOnlyProperty, 1); - - // binding the property, checking internal - property.bind(v); - v.set(VALUE_2); - property.addListener(internalListener3); - v.get(); - internalListener3.reset(); - v.set(VALUE_1); - internalListener3.check(property, 1); - - // binding the property, checking public - property.bind(v); - v.set(VALUE_2); - readOnlyProperty.addListener(publicListener3); - v.get(); - publicListener3.reset(); - v.set(VALUE_1); - publicListener3.check(readOnlyProperty, 1); - } - - @Test - public void testRemoveListeners() { - attachInvalidationListeners(); - attachInternalChangeListener(); - property.removeListener(internalInvalidationListener); - property.removeListener(internalChangeListener); - property.get(); - internalInvalidationListener.reset(); - internalChangeListener.reset(); - - property.set(VALUE_1); - internalInvalidationListener.check(null, 0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // no read only property created => no-op - final ReadOnlySetWrapper v1 = new ReadOnlySetWrapper(); - v1.removeListener(internalInvalidationListener); - v1.removeListener(internalChangeListener); - } - - @Test - public void testNoReadOnlyPropertyCreated() { - final SetProperty v1 = new SimpleSetProperty(VALUE_1); - final ReadOnlySetWrapper p1 = new ReadOnlySetWrapper(); - - p1.set(VALUE_1); - p1.bind(v1); - assertEquals(VALUE_1, p1.get()); - v1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - } - - @Test - public void testToString() { - final SetProperty v1 = new SimpleSetProperty(VALUE_1); - - property.set(VALUE_1); - assertEquals("SetProperty [value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlySetProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - - property.bind(v1); - assertEquals("SetProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlySetProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("SetProperty [bound, value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlySetProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - v1.set(VALUE_2); - assertEquals("SetProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlySetProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("SetProperty [bound, value: " + VALUE_2 + "]", property.toString()); - assertEquals("ReadOnlySetProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlySetWrapper v2 = new ReadOnlySetWrapper(bean, name); - assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - assertEquals("ReadOnlySetProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); - - final ReadOnlySetWrapper v3 = new ReadOnlySetWrapper(bean, ""); - assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - assertEquals("ReadOnlySetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); - - final ReadOnlySetWrapper v4 = new ReadOnlySetWrapper(null, name); - assertEquals("SetProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); - assertEquals("ReadOnlySetProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); - } - - private static class ReadOnlySetWrapperMock extends ReadOnlySetWrapper { - - private int counter; - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlySetWrapperTest.java 2015-08-31 10:23:50.281217217 -0400 @@ -0,0 +1,760 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.ReadOnlySetProperty; +import javafx.beans.property.ReadOnlySetWrapper; +import javafx.beans.property.SetProperty; +import javafx.beans.property.SimpleSetProperty; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableObjectValueStub; +import javafx.collections.FXCollections; +import javafx.collections.ObservableSet; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ReadOnlySetWrapperTest { + + private static final Object UNDEFINED = null; + private static final ObservableSet DEFAULT = null; + private static final ObservableSet VALUE_1 = FXCollections.observableSet(); + private static final ObservableSet VALUE_2 = FXCollections.observableSet(new Object()); + + private ReadOnlySetWrapperMock property; + private ReadOnlySetProperty readOnlyProperty; + private InvalidationListenerMock internalInvalidationListener; + private InvalidationListenerMock publicInvalidationListener; + private ChangeListenerMock internalChangeListener; + private ChangeListenerMock publicChangeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlySetWrapperMock(); + readOnlyProperty = property.getReadOnlyProperty(); + internalInvalidationListener = new InvalidationListenerMock(); + publicInvalidationListener = new InvalidationListenerMock(); + internalChangeListener = new ChangeListenerMock(UNDEFINED); + publicChangeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListeners() { + property.addListener(internalInvalidationListener); + readOnlyProperty.addListener(publicInvalidationListener); + property.get(); + readOnlyProperty.get(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + } + + private void attachInternalChangeListener() { + property.addListener(internalChangeListener); + property.get(); + internalChangeListener.reset(); + } + + private void attachPublicChangeListener() { + readOnlyProperty.addListener(publicChangeListener); + readOnlyProperty.get(); + publicChangeListener.reset(); + } + + @Test + public void testConstructor_NoArguments() { + final ReadOnlySetWrapper p1 = new ReadOnlySetWrapper(); + assertEquals(DEFAULT, p1.get()); + assertEquals((Object)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlySetProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Object)DEFAULT, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_InitialValue() { + final ReadOnlySetWrapper p1 = new ReadOnlySetWrapper(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Object)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlySetProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Object)VALUE_1, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlySetWrapper p1 = new ReadOnlySetWrapper(bean, name); + assertEquals(DEFAULT, p1.get()); + assertEquals((Object)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlySetProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((Object)DEFAULT, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlySetWrapper p1 = new ReadOnlySetWrapper(bean, name, VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((Object)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlySetProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((Object)VALUE_1, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testLazySet() { + attachInvalidationListeners(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSet() { + attachInternalChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSet() { + attachPublicChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListeners(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSetValue() { + attachInternalChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSetValue() { + attachPublicChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final SetProperty v = new SimpleSetProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind_primitive() { + attachInvalidationListeners(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_primitive() { + attachInternalChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_primitive() { + attachPublicChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test + public void testLazyBind_generic() { + attachInvalidationListeners(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_generic() { + attachInternalChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_generic() { + attachPublicChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListeners(); + final SetProperty v1 = new SimpleSetProperty(VALUE_1); + final SetProperty v2 = new SimpleSetProperty(VALUE_2); + property.bind(v1); + property.get(); + readOnlyProperty.get(); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change new binding + v2.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change old binding + v1.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListeners(); + final SetProperty v = new SimpleSetProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get()); + assertFalse(property.isBound()); + assertEquals(VALUE_1, readOnlyProperty.get()); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final SetProperty v = new SimpleSetProperty(VALUE_1); + final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); + + // setting the property,checking internal + property.set(VALUE_1); + property.addListener(internalListener2); + internalListener2.reset(); + property.set(VALUE_2); + internalListener2.check(property, 1); + + // setting the property, checking public + property.set(VALUE_1); + readOnlyProperty.addListener(publicListener2); + publicListener2.reset(); + property.set(VALUE_2); + publicListener2.check(readOnlyProperty, 1); + + // binding the property, checking internal + property.bind(v); + v.set(VALUE_2); + property.addListener(internalListener3); + v.get(); + internalListener3.reset(); + v.set(VALUE_1); + internalListener3.check(property, 1); + + // binding the property, checking public + property.bind(v); + v.set(VALUE_2); + readOnlyProperty.addListener(publicListener3); + v.get(); + publicListener3.reset(); + v.set(VALUE_1); + publicListener3.check(readOnlyProperty, 1); + } + + @Test + public void testRemoveListeners() { + attachInvalidationListeners(); + attachInternalChangeListener(); + property.removeListener(internalInvalidationListener); + property.removeListener(internalChangeListener); + property.get(); + internalInvalidationListener.reset(); + internalChangeListener.reset(); + + property.set(VALUE_1); + internalInvalidationListener.check(null, 0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // no read only property created => no-op + final ReadOnlySetWrapper v1 = new ReadOnlySetWrapper(); + v1.removeListener(internalInvalidationListener); + v1.removeListener(internalChangeListener); + } + + @Test + public void testNoReadOnlyPropertyCreated() { + final SetProperty v1 = new SimpleSetProperty(VALUE_1); + final ReadOnlySetWrapper p1 = new ReadOnlySetWrapper(); + + p1.set(VALUE_1); + p1.bind(v1); + assertEquals(VALUE_1, p1.get()); + v1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + } + + @Test + public void testToString() { + final SetProperty v1 = new SimpleSetProperty(VALUE_1); + + property.set(VALUE_1); + assertEquals("SetProperty [value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlySetProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + + property.bind(v1); + assertEquals("SetProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlySetProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("SetProperty [bound, value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlySetProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + v1.set(VALUE_2); + assertEquals("SetProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlySetProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("SetProperty [bound, value: " + VALUE_2 + "]", property.toString()); + assertEquals("ReadOnlySetProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlySetWrapper v2 = new ReadOnlySetWrapper(bean, name); + assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + assertEquals("ReadOnlySetProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); + + final ReadOnlySetWrapper v3 = new ReadOnlySetWrapper(bean, ""); + assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + assertEquals("ReadOnlySetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); + + final ReadOnlySetWrapper v4 = new ReadOnlySetWrapper(null, name); + assertEquals("SetProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); + assertEquals("ReadOnlySetProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); + } + + private static class ReadOnlySetWrapperMock extends ReadOnlySetWrapper { + + private int counter; + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyStringPropertyBaseTest.java 2015-08-31 10:23:51.285217206 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyStringPropertyBaseTest { - - private static final String UNDEFINED = null; - private static final String DEFAULT = null; - private static final String VALUE_1 = "Hello World!"; - private static final String VALUE_2 = "Goodbye World!"; - - private ReadOnlyPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - @Test - public void testInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - property.set(VALUE_1); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_2); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - property.set(VALUE_1); - changeListener.check(property, DEFAULT, VALUE_1, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_2); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - private static class ReadOnlyPropertyMock extends ReadOnlyStringPropertyBase { - - private String value; - - @Override - public Object getBean() { - // not used - return null; - } - - @Override - public String getName() { - // not used - return null; - } - - private void set(String value) { - this.value = value; - fireValueChangedEvent(); - } - - @Override - public String get() { - return value; - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyStringPropertyBaseTest.java 2015-08-31 10:23:51.073217208 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.ReadOnlyStringPropertyBase; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyStringPropertyBaseTest { + + private static final String UNDEFINED = null; + private static final String DEFAULT = null; + private static final String VALUE_1 = "Hello World!"; + private static final String VALUE_2 = "Goodbye World!"; + + private ReadOnlyPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + @Test + public void testInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + property.set(VALUE_1); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_2); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + property.set(VALUE_1); + changeListener.check(property, DEFAULT, VALUE_1, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_2); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + private static class ReadOnlyPropertyMock extends ReadOnlyStringPropertyBase { + + private String value; + + @Override + public Object getBean() { + // not used + return null; + } + + @Override + public String getName() { + // not used + return null; + } + + private void set(String value) { + this.value = value; + fireValueChangedEvent(); + } + + @Override + public String get() { + return value; + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyStringPropertyTest.java 2015-08-31 10:23:52.033217197 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyStringPropertyTest { - - private static final String DEFAULT = null; - - @Before - public void setUp() throws Exception { - } - - - @Test - public void testToString() { - final ReadOnlyStringProperty v1 = new ReadOnlyStringPropertyStub(null, ""); - assertEquals("ReadOnlyStringProperty [value: " + DEFAULT + "]", v1.toString()); - - final ReadOnlyStringProperty v2 = new ReadOnlyStringPropertyStub(null, null); - assertEquals("ReadOnlyStringProperty [value: " + DEFAULT + "]", v2.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyStringProperty v3 = new ReadOnlyStringPropertyStub(bean, name); - assertEquals("ReadOnlyStringProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); - - final ReadOnlyStringProperty v4 = new ReadOnlyStringPropertyStub(bean, ""); - assertEquals("ReadOnlyStringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - - final ReadOnlyStringProperty v5 = new ReadOnlyStringPropertyStub(bean, null); - assertEquals("ReadOnlyStringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); - - final ReadOnlyStringProperty v6 = new ReadOnlyStringPropertyStub(null, name); - assertEquals("ReadOnlyStringProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); - - } - - private static class ReadOnlyStringPropertyStub extends ReadOnlyStringProperty { - - private final Object bean; - private final String name; - - private ReadOnlyStringPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override public Object getBean() { return bean; } - @Override public String getName() { return name; } - @Override public String get() { return null; } - - @Override - public void addListener(ChangeListener listener) { - } - - @Override - public void removeListener(ChangeListener listener) { - } - - @Override - public void addListener(InvalidationListener listener) { - } - - @Override - public void removeListener(InvalidationListener listener) { - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyStringPropertyTest.java 2015-08-31 10:23:51.833217200 -0400 @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import javafx.beans.InvalidationListener; +import javafx.beans.property.ReadOnlyStringProperty; +import javafx.beans.value.ChangeListener; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyStringPropertyTest { + + private static final String DEFAULT = null; + + @Before + public void setUp() throws Exception { + } + + + @Test + public void testToString() { + final ReadOnlyStringProperty v1 = new ReadOnlyStringPropertyStub(null, ""); + assertEquals("ReadOnlyStringProperty [value: " + DEFAULT + "]", v1.toString()); + + final ReadOnlyStringProperty v2 = new ReadOnlyStringPropertyStub(null, null); + assertEquals("ReadOnlyStringProperty [value: " + DEFAULT + "]", v2.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyStringProperty v3 = new ReadOnlyStringPropertyStub(bean, name); + assertEquals("ReadOnlyStringProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v3.toString()); + + final ReadOnlyStringProperty v4 = new ReadOnlyStringPropertyStub(bean, ""); + assertEquals("ReadOnlyStringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + + final ReadOnlyStringProperty v5 = new ReadOnlyStringPropertyStub(bean, null); + assertEquals("ReadOnlyStringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v5.toString()); + + final ReadOnlyStringProperty v6 = new ReadOnlyStringPropertyStub(null, name); + assertEquals("ReadOnlyStringProperty [name: My name, value: " + DEFAULT + "]", v6.toString()); + + } + + private static class ReadOnlyStringPropertyStub extends ReadOnlyStringProperty { + + private final Object bean; + private final String name; + + private ReadOnlyStringPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override public Object getBean() { return bean; } + @Override public String getName() { return name; } + @Override public String get() { return null; } + + @Override + public void addListener(ChangeListener listener) { + } + + @Override + public void removeListener(ChangeListener listener) { + } + + @Override + public void addListener(InvalidationListener listener) { + } + + @Override + public void removeListener(InvalidationListener listener) { + } + + } + +} --- old/modules/base/src/test/java/javafx/beans/property/ReadOnlyStringWrapperTest.java 2015-08-31 10:23:52.681217190 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,758 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableStringValueStub; -import javafx.beans.value.ObservableObjectValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class ReadOnlyStringWrapperTest { - - private static final String UNDEFINED = null; - private static final String DEFAULT = null; - private static final String VALUE_1 = "Hello World!"; - private static final String VALUE_2 = "Goodbye World!"; - - private ReadOnlyStringWrapperMock property; - private ReadOnlyStringProperty readOnlyProperty; - private InvalidationListenerMock internalInvalidationListener; - private InvalidationListenerMock publicInvalidationListener; - private ChangeListenerMock internalChangeListener; - private ChangeListenerMock publicChangeListener; - - @Before - public void setUp() throws Exception { - property = new ReadOnlyStringWrapperMock(); - readOnlyProperty = property.getReadOnlyProperty(); - internalInvalidationListener = new InvalidationListenerMock(); - publicInvalidationListener = new InvalidationListenerMock(); - internalChangeListener = new ChangeListenerMock(UNDEFINED); - publicChangeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListeners() { - property.addListener(internalInvalidationListener); - readOnlyProperty.addListener(publicInvalidationListener); - property.get(); - readOnlyProperty.get(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - } - - private void attachInternalChangeListener() { - property.addListener(internalChangeListener); - property.get(); - internalChangeListener.reset(); - } - - private void attachPublicChangeListener() { - readOnlyProperty.addListener(publicChangeListener); - readOnlyProperty.get(); - publicChangeListener.reset(); - } - - @Test - public void testConstructor_NoArguments() { - final ReadOnlyStringWrapper p1 = new ReadOnlyStringWrapper(); - assertEquals(DEFAULT, p1.get()); - assertEquals((String)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyStringProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((String)DEFAULT, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_InitialValue() { - final ReadOnlyStringWrapper p1 = new ReadOnlyStringWrapper(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((String)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(null, p1.getBean()); - assertEquals("", p1.getName()); - final ReadOnlyStringProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((String)VALUE_1, r1.getValue()); - assertEquals(null, r1.getBean()); - assertEquals("", r1.getName()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyStringWrapper p1 = new ReadOnlyStringWrapper(bean, name); - assertEquals(DEFAULT, p1.get()); - assertEquals((String)DEFAULT, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyStringProperty r1 = p1.getReadOnlyProperty(); - assertEquals(DEFAULT, r1.get()); - assertEquals((String)DEFAULT, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyStringWrapper p1 = new ReadOnlyStringWrapper(bean, name, VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals((String)VALUE_1, p1.getValue()); - assertFalse(property.isBound()); - assertEquals(bean, p1.getBean()); - assertEquals(name, p1.getName()); - final ReadOnlyStringProperty r1 = p1.getReadOnlyProperty(); - assertEquals(VALUE_1, r1.get()); - assertEquals((String)VALUE_1, r1.getValue()); - assertEquals(bean, r1.getBean()); - assertEquals(name, r1.getName()); - } - - @Test - public void testLazySet() { - attachInvalidationListeners(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSet() { - attachInternalChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSet() { - attachPublicChangeListener(); - - // set value once - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_2); - property.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListeners(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerSetValue() { - attachInternalChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 2); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerSetValue() { - attachPublicChangeListener(); - - // set value once - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // set same value again - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_2); - property.setValue(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final StringProperty v = new SimpleStringProperty(VALUE_1); - property.bind(v); - property.set(VALUE_1); - } - - @Test - public void testLazyBind_primitive() { - attachInvalidationListeners(); - final ObservableStringValueStub v = new ObservableStringValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_primitive() { - attachInternalChangeListener(); - final ObservableStringValueStub v = new ObservableStringValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_primitive() { - attachPublicChangeListener(); - final ObservableStringValueStub v = new ObservableStringValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test - public void testLazyBind_generic() { - attachInvalidationListeners(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testInternalEagerBind_generic() { - attachInternalChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalChangeListener.check(property, DEFAULT, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalChangeListener.check(property, VALUE_1, VALUE_2, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_1, VALUE_2, 2); - assertEquals(VALUE_2, readOnlyProperty.get()); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - internalChangeListener.check(property, VALUE_2, VALUE_1, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - } - - @Test - public void testPublicEagerBind_generic() { - attachPublicChangeListener(); - final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); - - property.bind(v); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); - - // change binding once - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); - - // change binding twice without reading - v.set(VALUE_1); - v.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(2); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); - - // change binding twice to same value - v.set(VALUE_1); - v.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(2); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListeners(); - final StringProperty v1 = new SimpleStringProperty(VALUE_1); - final StringProperty v2 = new SimpleStringProperty(VALUE_2); - property.bind(v1); - property.get(); - readOnlyProperty.get(); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2, property.get()); - assertTrue(property.isBound()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change new binding - v2.set(VALUE_1); - assertEquals(VALUE_1, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - - // change old binding - v1.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_1, property.get()); - assertTrue(property.isBound()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListeners(); - final StringProperty v = new SimpleStringProperty(VALUE_1); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1, property.get()); - assertFalse(property.isBound()); - assertEquals(VALUE_1, readOnlyProperty.get()); - property.reset(); - internalInvalidationListener.reset(); - publicInvalidationListener.reset(); - - // change binding - v.set(VALUE_2); - assertEquals(VALUE_1, property.get()); - property.check(0); - internalInvalidationListener.check(null, 0); - assertEquals(VALUE_1, readOnlyProperty.get()); - publicInvalidationListener.check(null, 0); - - // set value - property.set(VALUE_2); - assertEquals(VALUE_2, property.get()); - property.check(1); - internalInvalidationListener.check(property, 1); - assertEquals(VALUE_2, readOnlyProperty.get()); - publicInvalidationListener.check(readOnlyProperty, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final StringProperty v = new SimpleStringProperty(VALUE_1); - final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); - final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); - - // setting the property,checking internal - property.set(VALUE_1); - property.addListener(internalListener2); - internalListener2.reset(); - property.set(VALUE_2); - internalListener2.check(property, 1); - - // setting the property, checking public - property.set(VALUE_1); - readOnlyProperty.addListener(publicListener2); - publicListener2.reset(); - property.set(VALUE_2); - publicListener2.check(readOnlyProperty, 1); - - // binding the property, checking internal - property.bind(v); - v.set(VALUE_2); - property.addListener(internalListener3); - v.get(); - internalListener3.reset(); - v.set(VALUE_1); - internalListener3.check(property, 1); - - // binding the property, checking public - property.bind(v); - v.set(VALUE_2); - readOnlyProperty.addListener(publicListener3); - v.get(); - publicListener3.reset(); - v.set(VALUE_1); - publicListener3.check(readOnlyProperty, 1); - } - - @Test - public void testRemoveListeners() { - attachInvalidationListeners(); - attachInternalChangeListener(); - property.removeListener(internalInvalidationListener); - property.removeListener(internalChangeListener); - property.get(); - internalInvalidationListener.reset(); - internalChangeListener.reset(); - - property.set(VALUE_1); - internalInvalidationListener.check(null, 0); - internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // no read only property created => no-op - final ReadOnlyStringWrapper v1 = new ReadOnlyStringWrapper(); - v1.removeListener(internalInvalidationListener); - v1.removeListener(internalChangeListener); - } - - @Test - public void testNoReadOnlyPropertyCreated() { - final StringProperty v1 = new SimpleStringProperty(VALUE_1); - final ReadOnlyStringWrapper p1 = new ReadOnlyStringWrapper(); - - p1.set(VALUE_1); - p1.bind(v1); - assertEquals(VALUE_1, p1.get()); - v1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - } - - @Test - public void testToString() { - final StringProperty v1 = new SimpleStringProperty(VALUE_1); - - property.set(VALUE_1); - assertEquals("StringProperty [value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyStringProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - - property.bind(v1); - assertEquals("StringProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyStringProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("StringProperty [bound, value: " + VALUE_1 + "]", property.toString()); - assertEquals("ReadOnlyStringProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); - v1.set(VALUE_2); - assertEquals("StringProperty [bound, invalid]", property.toString()); - assertEquals("ReadOnlyStringProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - property.get(); - assertEquals("StringProperty [bound, value: " + VALUE_2 + "]", property.toString()); - assertEquals("ReadOnlyStringProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final ReadOnlyStringWrapper v2 = new ReadOnlyStringWrapper(bean, name); - assertEquals("StringProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - assertEquals("ReadOnlyStringProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); - - final ReadOnlyStringWrapper v3 = new ReadOnlyStringWrapper(bean, ""); - assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - assertEquals("ReadOnlyStringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); - - final ReadOnlyStringWrapper v4 = new ReadOnlyStringWrapper(null, name); - assertEquals("StringProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); - assertEquals("ReadOnlyStringProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); - } - - private static class ReadOnlyStringWrapperMock extends ReadOnlyStringWrapper { - - private int counter; - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/ReadOnlyStringWrapperTest.java 2015-08-31 10:23:52.513217192 -0400 @@ -0,0 +1,762 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.ReadOnlyStringProperty; +import javafx.beans.property.ReadOnlyStringWrapper; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableStringValueStub; +import javafx.beans.value.ObservableObjectValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class ReadOnlyStringWrapperTest { + + private static final String UNDEFINED = null; + private static final String DEFAULT = null; + private static final String VALUE_1 = "Hello World!"; + private static final String VALUE_2 = "Goodbye World!"; + + private ReadOnlyStringWrapperMock property; + private ReadOnlyStringProperty readOnlyProperty; + private InvalidationListenerMock internalInvalidationListener; + private InvalidationListenerMock publicInvalidationListener; + private ChangeListenerMock internalChangeListener; + private ChangeListenerMock publicChangeListener; + + @Before + public void setUp() throws Exception { + property = new ReadOnlyStringWrapperMock(); + readOnlyProperty = property.getReadOnlyProperty(); + internalInvalidationListener = new InvalidationListenerMock(); + publicInvalidationListener = new InvalidationListenerMock(); + internalChangeListener = new ChangeListenerMock(UNDEFINED); + publicChangeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListeners() { + property.addListener(internalInvalidationListener); + readOnlyProperty.addListener(publicInvalidationListener); + property.get(); + readOnlyProperty.get(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + } + + private void attachInternalChangeListener() { + property.addListener(internalChangeListener); + property.get(); + internalChangeListener.reset(); + } + + private void attachPublicChangeListener() { + readOnlyProperty.addListener(publicChangeListener); + readOnlyProperty.get(); + publicChangeListener.reset(); + } + + @Test + public void testConstructor_NoArguments() { + final ReadOnlyStringWrapper p1 = new ReadOnlyStringWrapper(); + assertEquals(DEFAULT, p1.get()); + assertEquals((String)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyStringProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((String)DEFAULT, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_InitialValue() { + final ReadOnlyStringWrapper p1 = new ReadOnlyStringWrapper(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((String)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(null, p1.getBean()); + assertEquals("", p1.getName()); + final ReadOnlyStringProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((String)VALUE_1, r1.getValue()); + assertEquals(null, r1.getBean()); + assertEquals("", r1.getName()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyStringWrapper p1 = new ReadOnlyStringWrapper(bean, name); + assertEquals(DEFAULT, p1.get()); + assertEquals((String)DEFAULT, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyStringProperty r1 = p1.getReadOnlyProperty(); + assertEquals(DEFAULT, r1.get()); + assertEquals((String)DEFAULT, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyStringWrapper p1 = new ReadOnlyStringWrapper(bean, name, VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals((String)VALUE_1, p1.getValue()); + assertFalse(property.isBound()); + assertEquals(bean, p1.getBean()); + assertEquals(name, p1.getName()); + final ReadOnlyStringProperty r1 = p1.getReadOnlyProperty(); + assertEquals(VALUE_1, r1.get()); + assertEquals((String)VALUE_1, r1.getValue()); + assertEquals(bean, r1.getBean()); + assertEquals(name, r1.getName()); + } + + @Test + public void testLazySet() { + attachInvalidationListeners(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSet() { + attachInternalChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSet() { + attachPublicChangeListener(); + + // set value once + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_2); + property.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListeners(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerSetValue() { + attachInternalChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 2); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerSetValue() { + attachPublicChangeListener(); + + // set value once + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // set same value again + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_2); + property.setValue(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final StringProperty v = new SimpleStringProperty(VALUE_1); + property.bind(v); + property.set(VALUE_1); + } + + @Test + public void testLazyBind_primitive() { + attachInvalidationListeners(); + final ObservableStringValueStub v = new ObservableStringValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_primitive() { + attachInternalChangeListener(); + final ObservableStringValueStub v = new ObservableStringValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_primitive() { + attachPublicChangeListener(); + final ObservableStringValueStub v = new ObservableStringValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test + public void testLazyBind_generic() { + attachInvalidationListeners(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testInternalEagerBind_generic() { + attachInternalChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalChangeListener.check(property, DEFAULT, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalChangeListener.check(property, VALUE_1, VALUE_2, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_1, VALUE_2, 2); + assertEquals(VALUE_2, readOnlyProperty.get()); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + internalChangeListener.check(property, VALUE_2, VALUE_1, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + } + + @Test + public void testPublicEagerBind_generic() { + attachPublicChangeListener(); + final ObservableObjectValueStub v = new ObservableObjectValueStub(VALUE_1); + + property.bind(v); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, DEFAULT, VALUE_1, 1); + + // change binding once + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 1); + + // change binding twice without reading + v.set(VALUE_1); + v.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(2); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_1, VALUE_2, 2); + + // change binding twice to same value + v.set(VALUE_1); + v.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(2); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicChangeListener.check(readOnlyProperty, VALUE_2, VALUE_1, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListeners(); + final StringProperty v1 = new SimpleStringProperty(VALUE_1); + final StringProperty v2 = new SimpleStringProperty(VALUE_2); + property.bind(v1); + property.get(); + readOnlyProperty.get(); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2, property.get()); + assertTrue(property.isBound()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change new binding + v2.set(VALUE_1); + assertEquals(VALUE_1, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + + // change old binding + v1.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_1, property.get()); + assertTrue(property.isBound()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListeners(); + final StringProperty v = new SimpleStringProperty(VALUE_1); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1, property.get()); + assertFalse(property.isBound()); + assertEquals(VALUE_1, readOnlyProperty.get()); + property.reset(); + internalInvalidationListener.reset(); + publicInvalidationListener.reset(); + + // change binding + v.set(VALUE_2); + assertEquals(VALUE_1, property.get()); + property.check(0); + internalInvalidationListener.check(null, 0); + assertEquals(VALUE_1, readOnlyProperty.get()); + publicInvalidationListener.check(null, 0); + + // set value + property.set(VALUE_2); + assertEquals(VALUE_2, property.get()); + property.check(1); + internalInvalidationListener.check(property, 1); + assertEquals(VALUE_2, readOnlyProperty.get()); + publicInvalidationListener.check(readOnlyProperty, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final StringProperty v = new SimpleStringProperty(VALUE_1); + final InvalidationListenerMock internalListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock internalListener3 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener2 = new InvalidationListenerMock(); + final InvalidationListenerMock publicListener3 = new InvalidationListenerMock(); + + // setting the property,checking internal + property.set(VALUE_1); + property.addListener(internalListener2); + internalListener2.reset(); + property.set(VALUE_2); + internalListener2.check(property, 1); + + // setting the property, checking public + property.set(VALUE_1); + readOnlyProperty.addListener(publicListener2); + publicListener2.reset(); + property.set(VALUE_2); + publicListener2.check(readOnlyProperty, 1); + + // binding the property, checking internal + property.bind(v); + v.set(VALUE_2); + property.addListener(internalListener3); + v.get(); + internalListener3.reset(); + v.set(VALUE_1); + internalListener3.check(property, 1); + + // binding the property, checking public + property.bind(v); + v.set(VALUE_2); + readOnlyProperty.addListener(publicListener3); + v.get(); + publicListener3.reset(); + v.set(VALUE_1); + publicListener3.check(readOnlyProperty, 1); + } + + @Test + public void testRemoveListeners() { + attachInvalidationListeners(); + attachInternalChangeListener(); + property.removeListener(internalInvalidationListener); + property.removeListener(internalChangeListener); + property.get(); + internalInvalidationListener.reset(); + internalChangeListener.reset(); + + property.set(VALUE_1); + internalInvalidationListener.check(null, 0); + internalChangeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // no read only property created => no-op + final ReadOnlyStringWrapper v1 = new ReadOnlyStringWrapper(); + v1.removeListener(internalInvalidationListener); + v1.removeListener(internalChangeListener); + } + + @Test + public void testNoReadOnlyPropertyCreated() { + final StringProperty v1 = new SimpleStringProperty(VALUE_1); + final ReadOnlyStringWrapper p1 = new ReadOnlyStringWrapper(); + + p1.set(VALUE_1); + p1.bind(v1); + assertEquals(VALUE_1, p1.get()); + v1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + } + + @Test + public void testToString() { + final StringProperty v1 = new SimpleStringProperty(VALUE_1); + + property.set(VALUE_1); + assertEquals("StringProperty [value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyStringProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + + property.bind(v1); + assertEquals("StringProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyStringProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("StringProperty [bound, value: " + VALUE_1 + "]", property.toString()); + assertEquals("ReadOnlyStringProperty [value: " + VALUE_1 + "]", readOnlyProperty.toString()); + v1.set(VALUE_2); + assertEquals("StringProperty [bound, invalid]", property.toString()); + assertEquals("ReadOnlyStringProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + property.get(); + assertEquals("StringProperty [bound, value: " + VALUE_2 + "]", property.toString()); + assertEquals("ReadOnlyStringProperty [value: " + VALUE_2 + "]", readOnlyProperty.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final ReadOnlyStringWrapper v2 = new ReadOnlyStringWrapper(bean, name); + assertEquals("StringProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + assertEquals("ReadOnlyStringProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.getReadOnlyProperty().toString()); + + final ReadOnlyStringWrapper v3 = new ReadOnlyStringWrapper(bean, ""); + assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + assertEquals("ReadOnlyStringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.getReadOnlyProperty().toString()); + + final ReadOnlyStringWrapper v4 = new ReadOnlyStringWrapper(null, name); + assertEquals("StringProperty [name: My name, value: " + DEFAULT + "]", v4.toString()); + assertEquals("ReadOnlyStringProperty [name: My name, value: " + DEFAULT + "]", v4.getReadOnlyProperty().toString()); + } + + private static class ReadOnlyStringWrapperMock extends ReadOnlyStringWrapper { + + private int counter; + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/SetPropertyBaseTest.java 2015-08-31 10:23:53.393217182 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,730 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import java.util.HashSet; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableObjectValueStub; -import javafx.collections.*; -import org.junit.Before; -import org.junit.Test; - -import static javafx.collections.MockSetObserver.Call; -import javafx.collections.MockSetObserver.Tuple; -import static org.junit.Assert.*; - -public class SetPropertyBaseTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final Object OBJECT_1b = new Object(); - private static final Object OBJECT_2a_0 = new Object(); - private static final Object OBJECT_2a_1 = new Object(); - private static final Object OBJECT_2b_0 = new Object(); - private static final Object OBJECT_2b_1 = new Object(); - private static final Object OBJECT_2b_2 = new Object(); - private static final ObservableSet UNDEFINED = FXCollections.observableSet(); - private static final ObservableSet VALUE_1a = FXCollections.observableSet(); - private static final ObservableSet VALUE_1b = FXCollections.observableSet(OBJECT_1b); - private static final ObservableSet VALUE_2a = FXCollections.observableSet(OBJECT_2a_0, OBJECT_2a_1); - private static final ObservableSet VALUE_2b = FXCollections.observableSet(OBJECT_2b_0, OBJECT_2b_1, OBJECT_2b_2); - private SetPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock> changeListener; - private MockSetObserver setChangeListener; - - @Before - public void setUp() throws Exception { - property = new SetPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock>(UNDEFINED); - setChangeListener = new MockSetObserver(); - } - - private void attachInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - } - - private void attachChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - } - - private void attachSetChangeListener() { - property.addListener(setChangeListener); - property.get(); - setChangeListener.clear(); - } - - @Test - public void testConstructor() { - final SetProperty p1 = new SimpleSetProperty(); - assertEquals(null, p1.get()); - assertEquals(null, p1.getValue()); - assertFalse(property.isBound()); - - final SetProperty p2 = new SimpleSetProperty(VALUE_1b); - assertEquals(VALUE_1b, p2.get()); - assertEquals(VALUE_1b, p2.getValue()); - assertFalse(property.isBound()); - } - - @Test - public void testEmptyProperty() { - assertEquals("empty", property.emptyProperty().getName()); - assertEquals(property, property.emptyProperty().getBean()); - assertTrue(property.emptyProperty().get()); - - property.set(VALUE_2a); - assertFalse(property.emptyProperty().get()); - property.set(VALUE_1a); - assertTrue(property.emptyProperty().get()); - } - - @Test - public void testSizeProperty() { - assertEquals("size", property.sizeProperty().getName()); - assertEquals(property, property.sizeProperty().getBean()); - assertEquals(0, property.sizeProperty().get()); - - property.set(VALUE_2a); - assertEquals(2, property.sizeProperty().get()); - property.set(VALUE_1a); - assertEquals(0, property.sizeProperty().get()); - } - - @Test - public void testInvalidationListener() { - attachInvalidationListener(); - property.set(VALUE_2a); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_1a); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - attachChangeListener(); - property.set(VALUE_2a); - changeListener.check(property, null, VALUE_2a, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_1a); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testSetChangeListener() { - attachSetChangeListener(); - property.set(VALUE_2a); - setChangeListener.assertMultipleCalls(new Call[]{new Call(null, OBJECT_2a_0), new Call(null, OBJECT_2a_1)}); - property.removeListener(setChangeListener); - setChangeListener.clear(); - property.set(VALUE_1a); - assertEquals(0, setChangeListener.getCallsNumber()); - } - - @Test - public void testSourceSet_Invalidation() { - final ObservableSet source1 = FXCollections.observableSet(); - final ObservableSet source2 = FXCollections.observableSet(); - final Object value = new Object(); - - // constructor - property = new SetPropertyBaseTest.SetPropertyMock(source1); - property.reset(); - attachInvalidationListener(); - - // add element - source1.add(value); - assertTrue(property.contains(value)); - property.check(1); - invalidationListener.check(property, 1); - - // remove element - source1.remove(value); - assertFalse(property.contains(value)); - property.check(1); - invalidationListener.check(property, 1); - - // set - property.set(source2); - property.get(); - property.reset(); - invalidationListener.reset(); - - // add element - source2.add(value); - assertTrue(property.contains(value)); - property.check(1); - invalidationListener.check(property, 1); - - // remove element - source2.remove(value); - assertFalse(property.contains(value)); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testSourceSet_Change() { - final ObservableSet source1 = FXCollections.observableSet(); - final ObservableSet source2 = FXCollections.observableSet(); - final Object value = new Object(); - - // constructor - property = new SetPropertyBaseTest.SetPropertyMock(source1); - property.reset(); - attachChangeListener(); - - // add element - source1.add(value); - assertTrue(property.contains(value)); - property.check(1); - changeListener.check(property, source1, source1, 1); - - // remove element - source1.remove(value); - assertFalse(property.contains(value)); - property.check(1); - changeListener.check(property, source1, source1, 1); - - // set - property.set(source2); - property.get(); - property.reset(); - changeListener.reset(); - - // add element - source2.add(value); - assertTrue(property.contains(value)); - property.check(1); - changeListener.check(property, source2, source2, 1); - - // remove element - source2.remove(value); - assertFalse(property.contains(value)); - property.check(1); - changeListener.check(property, source2, source2, 1); - } - - @Test - public void testSourceSet_SetChange() { - final ObservableSet source1 = FXCollections.observableSet(); - final ObservableSet source2 = FXCollections.observableSet(); - final Object value = new Object(); - - // constructor - property = new SetPropertyBaseTest.SetPropertyMock(source1); - property.reset(); - attachSetChangeListener(); - - // add element - source1.add(value); - assertTrue(property.contains(value)); - property.check(1); - setChangeListener.assertAdded(Tuple.tup(value)); - setChangeListener.clear(); - - // remove element - source1.remove(value); - assertFalse(property.contains(value)); - property.check(1); - setChangeListener.assertRemoved(Tuple.tup(value)); - setChangeListener.clear(); - - // set - property.set(source2); - property.get(); - property.reset(); - setChangeListener.clear(); - - // add element - source2.add(value); - assertTrue(property.contains(value)); - property.check(1); - setChangeListener.assertAdded(Tuple.tup(value)); - setChangeListener.clear(); - - // remove element - source2.remove(value); - assertFalse(property.contains(value)); - property.check(1); - setChangeListener.assertRemoved(Tuple.tup(value)); - setChangeListener.clear(); - } - - @Test - public void testSet_Invalidation() { - attachInvalidationListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_1a); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testSet_Change() { - attachChangeListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, null, VALUE_2a, 1); - - // set same value again - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_1a); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - } - - @Test - public void testSet_SetChange() { - attachSetChangeListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - setChangeListener.assertMultipleCalls(new Call[]{new Call(null, OBJECT_2a_0), new Call(null, OBJECT_2a_1)}); - - // set same value again - setChangeListener.clear(); - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - assertEquals(0, setChangeListener.getCallsNumber()); - - // set value twice without reading - property.set(VALUE_1a); - setChangeListener.clear(); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - setChangeListener.assertAdded(MockSetObserver.Tuple.tup(OBJECT_1b)); - } - - @Test - public void testSetValue_Invalidation() { - attachInvalidationListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_1a); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testSetValue_Change() { - attachChangeListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, null, VALUE_2a, 1); - - // set same value again - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_1a); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - } - - @Test - public void testSetValue_SetChange() { - attachSetChangeListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - setChangeListener.assertMultipleCalls(new Call[]{new Call(null, OBJECT_2a_0), new Call(null, OBJECT_2a_1)}); - - // set same value again - setChangeListener.clear(); - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - assertEquals(0, setChangeListener.getCallsNumber()); - - // set value twice without reading - property.setValue(VALUE_1a); - setChangeListener.clear(); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - setChangeListener.assertAdded(MockSetObserver.Tuple.tup(OBJECT_1b)); - } - - @Test(expected = RuntimeException.class) - public void testSetBoundValue() { - final SetProperty v = new SimpleSetProperty(VALUE_1a); - property.bind(v); - property.set(VALUE_1a); - } - - @Test - public void testBind_Invalidation() { - attachInvalidationListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableSet(VALUE_1a)); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(VALUE_1a); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(VALUE_1a); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testBind_Change() { - attachChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableSet(VALUE_1a)); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, null, VALUE_1a, 1); - - // change binding once - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, VALUE_1a, VALUE_2a, 1); - - // change binding twice without reading - v.set(VALUE_1a); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - - // change binding twice to same value - v.set(VALUE_1a); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(2); - changeListener.check(property, VALUE_1b, VALUE_1a, 1); - } - - @Test - public void testBind_SetChange() { - attachSetChangeListener(); - final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableSet(VALUE_1a)); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - assertEquals(0, setChangeListener.getCallsNumber()); - - // change binding once - setChangeListener.clear(); - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - setChangeListener.assertMultipleCalls(new Call[]{new Call(null, OBJECT_2a_0), new Call(null, OBJECT_2a_1)}); - - // change binding twice without reading - v.set(VALUE_1a); - setChangeListener.clear(); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - setChangeListener.assertAdded(MockSetObserver.Tuple.tup(OBJECT_1b)); - - // change binding twice to same value - v.set(VALUE_1a); - setChangeListener.clear(); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(2); - assertEquals(0, setChangeListener.getCallsNumber()); - } - - @Test(expected = NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListener(); - final SetProperty v1 = new SimpleSetProperty(VALUE_1a); - final SetProperty v2 = new SimpleSetProperty(VALUE_2a); - property.bind(v1); - property.get(); - property.reset(); - invalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2a, property.get()); - assertTrue(property.isBound()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // change old binding - v1.set(VALUE_1b); - assertEquals(VALUE_2a, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // change new binding - v2.set(VALUE_2b); - assertEquals(VALUE_2b, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_2b, property.get()); - assertTrue(property.isBound()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListener(); - final SetProperty v = new SimpleSetProperty(VALUE_1a); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1a, property.get()); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(VALUE_2a); - assertEquals(VALUE_1a, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final SetProperty v = new SimpleSetProperty(VALUE_1a); - final InvalidationListenerMock listener2 = new InvalidationListenerMock(); - final InvalidationListenerMock listener3 = new InvalidationListenerMock(); - - // setting the property - property.set(VALUE_1a); - property.addListener(listener2); - listener2.reset(); - property.set(VALUE_1b); - listener2.check(property, 1); - - // binding the property - property.bind(v); - v.set(VALUE_2a); - property.addListener(listener3); - v.get(); - listener3.reset(); - v.set(VALUE_2b); - listener3.check(property, 1); - } - - @Test - public void testToString() { - final ObservableSet value0 = null; - final ObservableSet value1 = FXCollections.observableSet(new Object(), new Object()); - final ObservableSet value2 = FXCollections.observableSet(); - final SetProperty v = new SimpleSetProperty(value2); - - property.set(value1); - assertEquals("SetProperty [value: " + value1 + "]", property.toString()); - - property.bind(v); - assertEquals("SetProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("SetProperty [bound, value: " + value2 + "]", property.toString()); - v.set(value1); - assertEquals("SetProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("SetProperty [bound, value: " + value1 + "]", property.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final SetProperty v1 = new SetPropertyMock(bean, name); - assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + null + "]", v1.toString()); - v1.set(value1); - assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); - v1.set(value0); - assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - - final SetProperty v2 = new SetPropertyMock(bean, NO_NAME_1); - assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + null + "]", v2.toString()); - v2.set(value1); - assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); - v1.set(value0); - assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - - final SetProperty v3 = new SetPropertyMock(bean, NO_NAME_2); - assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + null + "]", v3.toString()); - v3.set(value1); - assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); - v1.set(value0); - assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - - final SetProperty v4 = new SetPropertyMock(NO_BEAN, name); - assertEquals("SetProperty [name: My name, value: " + null + "]", v4.toString()); - v4.set(value1); - v1.set(value0); - assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); - assertEquals("SetProperty [name: My name, value: " + value1 + "]", v4.toString()); - } - - private static class SetPropertyMock extends SetPropertyBase { - - private final Object bean; - private final String name; - private int counter; - - private SetPropertyMock() { - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - private SetPropertyMock(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - private SetPropertyMock(ObservableSet initialValue) { - super(initialValue); - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/SetPropertyBaseTest.java 2015-08-31 10:23:53.257217184 -0400 @@ -0,0 +1,734 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import test.javafx.collections.MockSetObserver; +import java.util.HashSet; +import javafx.beans.property.SetProperty; +import javafx.beans.property.SetPropertyBase; +import javafx.beans.property.SimpleSetProperty; +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableObjectValueStub; +import javafx.collections.*; +import org.junit.Before; +import org.junit.Test; + +import static test.javafx.collections.MockSetObserver.Call; +import test.javafx.collections.MockSetObserver.Tuple; +import static org.junit.Assert.*; + +public class SetPropertyBaseTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final Object OBJECT_1b = new Object(); + private static final Object OBJECT_2a_0 = new Object(); + private static final Object OBJECT_2a_1 = new Object(); + private static final Object OBJECT_2b_0 = new Object(); + private static final Object OBJECT_2b_1 = new Object(); + private static final Object OBJECT_2b_2 = new Object(); + private static final ObservableSet UNDEFINED = FXCollections.observableSet(); + private static final ObservableSet VALUE_1a = FXCollections.observableSet(); + private static final ObservableSet VALUE_1b = FXCollections.observableSet(OBJECT_1b); + private static final ObservableSet VALUE_2a = FXCollections.observableSet(OBJECT_2a_0, OBJECT_2a_1); + private static final ObservableSet VALUE_2b = FXCollections.observableSet(OBJECT_2b_0, OBJECT_2b_1, OBJECT_2b_2); + private SetPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock> changeListener; + private MockSetObserver setChangeListener; + + @Before + public void setUp() throws Exception { + property = new SetPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock>(UNDEFINED); + setChangeListener = new MockSetObserver(); + } + + private void attachInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + } + + private void attachChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + } + + private void attachSetChangeListener() { + property.addListener(setChangeListener); + property.get(); + setChangeListener.clear(); + } + + @Test + public void testConstructor() { + final SetProperty p1 = new SimpleSetProperty(); + assertEquals(null, p1.get()); + assertEquals(null, p1.getValue()); + assertFalse(property.isBound()); + + final SetProperty p2 = new SimpleSetProperty(VALUE_1b); + assertEquals(VALUE_1b, p2.get()); + assertEquals(VALUE_1b, p2.getValue()); + assertFalse(property.isBound()); + } + + @Test + public void testEmptyProperty() { + assertEquals("empty", property.emptyProperty().getName()); + assertEquals(property, property.emptyProperty().getBean()); + assertTrue(property.emptyProperty().get()); + + property.set(VALUE_2a); + assertFalse(property.emptyProperty().get()); + property.set(VALUE_1a); + assertTrue(property.emptyProperty().get()); + } + + @Test + public void testSizeProperty() { + assertEquals("size", property.sizeProperty().getName()); + assertEquals(property, property.sizeProperty().getBean()); + assertEquals(0, property.sizeProperty().get()); + + property.set(VALUE_2a); + assertEquals(2, property.sizeProperty().get()); + property.set(VALUE_1a); + assertEquals(0, property.sizeProperty().get()); + } + + @Test + public void testInvalidationListener() { + attachInvalidationListener(); + property.set(VALUE_2a); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_1a); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + attachChangeListener(); + property.set(VALUE_2a); + changeListener.check(property, null, VALUE_2a, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_1a); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testSetChangeListener() { + attachSetChangeListener(); + property.set(VALUE_2a); + setChangeListener.assertMultipleCalls(new Call[]{new Call(null, OBJECT_2a_0), new Call(null, OBJECT_2a_1)}); + property.removeListener(setChangeListener); + setChangeListener.clear(); + property.set(VALUE_1a); + assertEquals(0, setChangeListener.getCallsNumber()); + } + + @Test + public void testSourceSet_Invalidation() { + final ObservableSet source1 = FXCollections.observableSet(); + final ObservableSet source2 = FXCollections.observableSet(); + final Object value = new Object(); + + // constructor + property = new SetPropertyBaseTest.SetPropertyMock(source1); + property.reset(); + attachInvalidationListener(); + + // add element + source1.add(value); + assertTrue(property.contains(value)); + property.check(1); + invalidationListener.check(property, 1); + + // remove element + source1.remove(value); + assertFalse(property.contains(value)); + property.check(1); + invalidationListener.check(property, 1); + + // set + property.set(source2); + property.get(); + property.reset(); + invalidationListener.reset(); + + // add element + source2.add(value); + assertTrue(property.contains(value)); + property.check(1); + invalidationListener.check(property, 1); + + // remove element + source2.remove(value); + assertFalse(property.contains(value)); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testSourceSet_Change() { + final ObservableSet source1 = FXCollections.observableSet(); + final ObservableSet source2 = FXCollections.observableSet(); + final Object value = new Object(); + + // constructor + property = new SetPropertyBaseTest.SetPropertyMock(source1); + property.reset(); + attachChangeListener(); + + // add element + source1.add(value); + assertTrue(property.contains(value)); + property.check(1); + changeListener.check(property, source1, source1, 1); + + // remove element + source1.remove(value); + assertFalse(property.contains(value)); + property.check(1); + changeListener.check(property, source1, source1, 1); + + // set + property.set(source2); + property.get(); + property.reset(); + changeListener.reset(); + + // add element + source2.add(value); + assertTrue(property.contains(value)); + property.check(1); + changeListener.check(property, source2, source2, 1); + + // remove element + source2.remove(value); + assertFalse(property.contains(value)); + property.check(1); + changeListener.check(property, source2, source2, 1); + } + + @Test + public void testSourceSet_SetChange() { + final ObservableSet source1 = FXCollections.observableSet(); + final ObservableSet source2 = FXCollections.observableSet(); + final Object value = new Object(); + + // constructor + property = new SetPropertyBaseTest.SetPropertyMock(source1); + property.reset(); + attachSetChangeListener(); + + // add element + source1.add(value); + assertTrue(property.contains(value)); + property.check(1); + setChangeListener.assertAdded(Tuple.tup(value)); + setChangeListener.clear(); + + // remove element + source1.remove(value); + assertFalse(property.contains(value)); + property.check(1); + setChangeListener.assertRemoved(Tuple.tup(value)); + setChangeListener.clear(); + + // set + property.set(source2); + property.get(); + property.reset(); + setChangeListener.clear(); + + // add element + source2.add(value); + assertTrue(property.contains(value)); + property.check(1); + setChangeListener.assertAdded(Tuple.tup(value)); + setChangeListener.clear(); + + // remove element + source2.remove(value); + assertFalse(property.contains(value)); + property.check(1); + setChangeListener.assertRemoved(Tuple.tup(value)); + setChangeListener.clear(); + } + + @Test + public void testSet_Invalidation() { + attachInvalidationListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_1a); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testSet_Change() { + attachChangeListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, null, VALUE_2a, 1); + + // set same value again + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_1a); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + } + + @Test + public void testSet_SetChange() { + attachSetChangeListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + setChangeListener.assertMultipleCalls(new Call[]{new Call(null, OBJECT_2a_0), new Call(null, OBJECT_2a_1)}); + + // set same value again + setChangeListener.clear(); + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + assertEquals(0, setChangeListener.getCallsNumber()); + + // set value twice without reading + property.set(VALUE_1a); + setChangeListener.clear(); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + setChangeListener.assertAdded(MockSetObserver.Tuple.tup(OBJECT_1b)); + } + + @Test + public void testSetValue_Invalidation() { + attachInvalidationListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_1a); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testSetValue_Change() { + attachChangeListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, null, VALUE_2a, 1); + + // set same value again + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_1a); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + } + + @Test + public void testSetValue_SetChange() { + attachSetChangeListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + setChangeListener.assertMultipleCalls(new Call[]{new Call(null, OBJECT_2a_0), new Call(null, OBJECT_2a_1)}); + + // set same value again + setChangeListener.clear(); + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + assertEquals(0, setChangeListener.getCallsNumber()); + + // set value twice without reading + property.setValue(VALUE_1a); + setChangeListener.clear(); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + setChangeListener.assertAdded(MockSetObserver.Tuple.tup(OBJECT_1b)); + } + + @Test(expected = RuntimeException.class) + public void testSetBoundValue() { + final SetProperty v = new SimpleSetProperty(VALUE_1a); + property.bind(v); + property.set(VALUE_1a); + } + + @Test + public void testBind_Invalidation() { + attachInvalidationListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableSet(VALUE_1a)); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(VALUE_1a); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(VALUE_1a); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testBind_Change() { + attachChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableSet(VALUE_1a)); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, null, VALUE_1a, 1); + + // change binding once + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, VALUE_1a, VALUE_2a, 1); + + // change binding twice without reading + v.set(VALUE_1a); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + + // change binding twice to same value + v.set(VALUE_1a); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(2); + changeListener.check(property, VALUE_1b, VALUE_1a, 1); + } + + @Test + public void testBind_SetChange() { + attachSetChangeListener(); + final ObservableObjectValueStub> v = new ObservableObjectValueStub>(FXCollections.observableSet(VALUE_1a)); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + assertEquals(0, setChangeListener.getCallsNumber()); + + // change binding once + setChangeListener.clear(); + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + setChangeListener.assertMultipleCalls(new Call[]{new Call(null, OBJECT_2a_0), new Call(null, OBJECT_2a_1)}); + + // change binding twice without reading + v.set(VALUE_1a); + setChangeListener.clear(); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + setChangeListener.assertAdded(MockSetObserver.Tuple.tup(OBJECT_1b)); + + // change binding twice to same value + v.set(VALUE_1a); + setChangeListener.clear(); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(2); + assertEquals(0, setChangeListener.getCallsNumber()); + } + + @Test(expected = NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListener(); + final SetProperty v1 = new SimpleSetProperty(VALUE_1a); + final SetProperty v2 = new SimpleSetProperty(VALUE_2a); + property.bind(v1); + property.get(); + property.reset(); + invalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2a, property.get()); + assertTrue(property.isBound()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // change old binding + v1.set(VALUE_1b); + assertEquals(VALUE_2a, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // change new binding + v2.set(VALUE_2b); + assertEquals(VALUE_2b, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_2b, property.get()); + assertTrue(property.isBound()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListener(); + final SetProperty v = new SimpleSetProperty(VALUE_1a); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1a, property.get()); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(VALUE_2a); + assertEquals(VALUE_1a, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final SetProperty v = new SimpleSetProperty(VALUE_1a); + final InvalidationListenerMock listener2 = new InvalidationListenerMock(); + final InvalidationListenerMock listener3 = new InvalidationListenerMock(); + + // setting the property + property.set(VALUE_1a); + property.addListener(listener2); + listener2.reset(); + property.set(VALUE_1b); + listener2.check(property, 1); + + // binding the property + property.bind(v); + v.set(VALUE_2a); + property.addListener(listener3); + v.get(); + listener3.reset(); + v.set(VALUE_2b); + listener3.check(property, 1); + } + + @Test + public void testToString() { + final ObservableSet value0 = null; + final ObservableSet value1 = FXCollections.observableSet(new Object(), new Object()); + final ObservableSet value2 = FXCollections.observableSet(); + final SetProperty v = new SimpleSetProperty(value2); + + property.set(value1); + assertEquals("SetProperty [value: " + value1 + "]", property.toString()); + + property.bind(v); + assertEquals("SetProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("SetProperty [bound, value: " + value2 + "]", property.toString()); + v.set(value1); + assertEquals("SetProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("SetProperty [bound, value: " + value1 + "]", property.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final SetProperty v1 = new SetPropertyMock(bean, name); + assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + null + "]", v1.toString()); + v1.set(value1); + assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); + v1.set(value0); + assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + + final SetProperty v2 = new SetPropertyMock(bean, NO_NAME_1); + assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + null + "]", v2.toString()); + v2.set(value1); + assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); + v1.set(value0); + assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + + final SetProperty v3 = new SetPropertyMock(bean, NO_NAME_2); + assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + null + "]", v3.toString()); + v3.set(value1); + assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); + v1.set(value0); + assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + + final SetProperty v4 = new SetPropertyMock(NO_BEAN, name); + assertEquals("SetProperty [name: My name, value: " + null + "]", v4.toString()); + v4.set(value1); + v1.set(value0); + assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + value0 + "]", v1.toString()); + assertEquals("SetProperty [name: My name, value: " + value1 + "]", v4.toString()); + } + + private static class SetPropertyMock extends SetPropertyBase { + + private final Object bean; + private final String name; + private int counter; + + private SetPropertyMock() { + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + private SetPropertyMock(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + private SetPropertyMock(ObservableSet initialValue) { + super(initialValue); + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/SetPropertyTest.java 2015-08-31 10:23:54.105217174 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.collections.FXCollections; -import javafx.collections.ObservableSet; -import javafx.collections.SetChangeListener; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -public class SetPropertyTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final ObservableSet VALUE_1 = FXCollections.observableSet(); - private static final ObservableSet VALUE_2 = FXCollections.observableSet(new Object()); - private static final Object DEFAULT = null; - - @Test - public void testBindBidirectional() { - final SetProperty p1 = new SimpleSetProperty(VALUE_2); - final SetProperty p2 = new SimpleSetProperty(VALUE_1); - - p1.bindBidirectional(p2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_2, p2.get()); - - p2.set(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.unbindBidirectional(p2); - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_1); - p2.set(VALUE_2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_2, p2.get()); - } - - @Test - public void testToString() { - final SetProperty v0 = new SetPropertyStub(NO_BEAN, NO_NAME_1); - assertEquals("SetProperty [value: " + DEFAULT + "]", v0.toString()); - - final SetProperty v1 = new SetPropertyStub(NO_BEAN, NO_NAME_2); - assertEquals("SetProperty [value: " + DEFAULT + "]", v1.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final SetProperty v2 = new SetPropertyStub(bean, name); - assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - v2.set(VALUE_1); - assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); - - final SetProperty v3 = new SetPropertyStub(bean, NO_NAME_1); - assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - v3.set(VALUE_1); - assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); - - final SetProperty v4 = new SetPropertyStub(bean, NO_NAME_2); - assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - v4.set(VALUE_1); - assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); - - final SetProperty v5 = new SetPropertyStub(NO_BEAN, name); - assertEquals("SetProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); - v5.set(VALUE_1); - assertEquals("SetProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); - } - - private class SetPropertyStub extends SetProperty { - - private final Object bean; - private final String name; - private ObservableSet value; - - private SetPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - - @Override - public ObservableSet get() { - return value; - } - - @Override - public void set(ObservableSet value) { - this.value = value; - } - - @Override - public void bind(ObservableValue> observable) { - fail("Not in use"); - } - - @Override - public void unbind() { - fail("Not in use"); - } - - @Override - public boolean isBound() { - fail("Not in use"); - return false; - } - - @Override - public void addListener(ChangeListener> listener) { - fail("Not in use"); - } - - @Override - public void removeListener(ChangeListener> listener) { - fail("Not in use"); - } - - @Override - public void addListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void addListener(SetChangeListener listChangeListener) { - fail("Not in use"); - } - - @Override - public void removeListener(SetChangeListener listChangeListener) { - fail("Not in use"); - } - - @Override - public ReadOnlyIntegerProperty sizeProperty() { - fail("Not in use"); - return null; - } - - @Override - public ReadOnlyBooleanProperty emptyProperty() { - fail("Not in use"); - return null; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/SetPropertyTest.java 2015-08-31 10:23:53.941217176 -0400 @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.InvalidationListener; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import javafx.beans.property.SetProperty; +import javafx.beans.property.SimpleSetProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ObservableSet; +import javafx.collections.SetChangeListener; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class SetPropertyTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final ObservableSet VALUE_1 = FXCollections.observableSet(); + private static final ObservableSet VALUE_2 = FXCollections.observableSet(new Object()); + private static final Object DEFAULT = null; + + @Test + public void testBindBidirectional() { + final SetProperty p1 = new SimpleSetProperty(VALUE_2); + final SetProperty p2 = new SimpleSetProperty(VALUE_1); + + p1.bindBidirectional(p2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_2, p2.get()); + + p2.set(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.unbindBidirectional(p2); + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_1); + p2.set(VALUE_2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_2, p2.get()); + } + + @Test + public void testToString() { + final SetProperty v0 = new SetPropertyStub(NO_BEAN, NO_NAME_1); + assertEquals("SetProperty [value: " + DEFAULT + "]", v0.toString()); + + final SetProperty v1 = new SetPropertyStub(NO_BEAN, NO_NAME_2); + assertEquals("SetProperty [value: " + DEFAULT + "]", v1.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final SetProperty v2 = new SetPropertyStub(bean, name); + assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + v2.set(VALUE_1); + assertEquals("SetProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); + + final SetProperty v3 = new SetPropertyStub(bean, NO_NAME_1); + assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + v3.set(VALUE_1); + assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); + + final SetProperty v4 = new SetPropertyStub(bean, NO_NAME_2); + assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + v4.set(VALUE_1); + assertEquals("SetProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); + + final SetProperty v5 = new SetPropertyStub(NO_BEAN, name); + assertEquals("SetProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); + v5.set(VALUE_1); + assertEquals("SetProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); + } + + private class SetPropertyStub extends SetProperty { + + private final Object bean; + private final String name; + private ObservableSet value; + + private SetPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + + @Override + public ObservableSet get() { + return value; + } + + @Override + public void set(ObservableSet value) { + this.value = value; + } + + @Override + public void bind(ObservableValue> observable) { + fail("Not in use"); + } + + @Override + public void unbind() { + fail("Not in use"); + } + + @Override + public boolean isBound() { + fail("Not in use"); + return false; + } + + @Override + public void addListener(ChangeListener> listener) { + fail("Not in use"); + } + + @Override + public void removeListener(ChangeListener> listener) { + fail("Not in use"); + } + + @Override + public void addListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void addListener(SetChangeListener listChangeListener) { + fail("Not in use"); + } + + @Override + public void removeListener(SetChangeListener listChangeListener) { + fail("Not in use"); + } + + @Override + public ReadOnlyIntegerProperty sizeProperty() { + fail("Not in use"); + return null; + } + + @Override + public ReadOnlyBooleanProperty emptyProperty() { + fail("Not in use"); + return null; + } + } +} --- old/modules/base/src/test/java/javafx/beans/property/SimpleBooleanPropertyTest.java 2015-08-31 10:23:54.705217167 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class SimpleBooleanPropertyTest { - - private static final Object DEFAULT_BEAN = null; - private static final String DEFAULT_NAME = ""; - private static final boolean DEFAULT_VALUE = false; - private static final boolean VALUE_1 = true; - - @Test - public void testConstructor_NoArguments() { - final BooleanProperty v = new SimpleBooleanProperty(); - assertEquals(DEFAULT_BEAN, v.getBean()); - assertEquals(DEFAULT_NAME, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - } - - @Test - public void testConstructor_InitialValue() { - final BooleanProperty v1 = new SimpleBooleanProperty(VALUE_1); - assertEquals(DEFAULT_BEAN, v1.getBean()); - assertEquals(DEFAULT_NAME, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final BooleanProperty v2 = new SimpleBooleanProperty(DEFAULT_VALUE); - assertEquals(DEFAULT_BEAN, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final BooleanProperty v = new SimpleBooleanProperty(bean, name); - assertEquals(bean, v.getBean()); - assertEquals(name, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - - final BooleanProperty v2 = new SimpleBooleanProperty(bean, null); - assertEquals(bean, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final BooleanProperty v1 = new SimpleBooleanProperty(bean, name, VALUE_1); - assertEquals(bean, v1.getBean()); - assertEquals(name, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final BooleanProperty v2 = new SimpleBooleanProperty(bean, name, DEFAULT_VALUE); - assertEquals(bean, v2.getBean()); - assertEquals(name, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - - final BooleanProperty v3 = new SimpleBooleanProperty(bean, null, VALUE_1); - assertEquals(bean, v3.getBean()); - assertEquals(DEFAULT_NAME, v3.getName()); - assertEquals(VALUE_1, v3.get()); - - final BooleanProperty v4 = new SimpleBooleanProperty(bean, null, DEFAULT_VALUE); - assertEquals(bean, v4.getBean()); - assertEquals(DEFAULT_NAME, v4.getName()); - assertEquals(DEFAULT_VALUE, v4.get()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/SimpleBooleanPropertyTest.java 2015-08-31 10:23:54.573217169 -0400 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class SimpleBooleanPropertyTest { + + private static final Object DEFAULT_BEAN = null; + private static final String DEFAULT_NAME = ""; + private static final boolean DEFAULT_VALUE = false; + private static final boolean VALUE_1 = true; + + @Test + public void testConstructor_NoArguments() { + final BooleanProperty v = new SimpleBooleanProperty(); + assertEquals(DEFAULT_BEAN, v.getBean()); + assertEquals(DEFAULT_NAME, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + } + + @Test + public void testConstructor_InitialValue() { + final BooleanProperty v1 = new SimpleBooleanProperty(VALUE_1); + assertEquals(DEFAULT_BEAN, v1.getBean()); + assertEquals(DEFAULT_NAME, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final BooleanProperty v2 = new SimpleBooleanProperty(DEFAULT_VALUE); + assertEquals(DEFAULT_BEAN, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final BooleanProperty v = new SimpleBooleanProperty(bean, name); + assertEquals(bean, v.getBean()); + assertEquals(name, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + + final BooleanProperty v2 = new SimpleBooleanProperty(bean, null); + assertEquals(bean, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final BooleanProperty v1 = new SimpleBooleanProperty(bean, name, VALUE_1); + assertEquals(bean, v1.getBean()); + assertEquals(name, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final BooleanProperty v2 = new SimpleBooleanProperty(bean, name, DEFAULT_VALUE); + assertEquals(bean, v2.getBean()); + assertEquals(name, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + + final BooleanProperty v3 = new SimpleBooleanProperty(bean, null, VALUE_1); + assertEquals(bean, v3.getBean()); + assertEquals(DEFAULT_NAME, v3.getName()); + assertEquals(VALUE_1, v3.get()); + + final BooleanProperty v4 = new SimpleBooleanProperty(bean, null, DEFAULT_VALUE); + assertEquals(bean, v4.getBean()); + assertEquals(DEFAULT_NAME, v4.getName()); + assertEquals(DEFAULT_VALUE, v4.get()); + } +} --- old/modules/base/src/test/java/javafx/beans/property/SimpleDoublePropertyTest.java 2015-08-31 10:23:55.313217161 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class SimpleDoublePropertyTest { - - private static final Object DEFAULT_BEAN = null; - private static final String DEFAULT_NAME = ""; - private static final double DEFAULT_VALUE = 0.0; - private static final double VALUE_1 = -Math.E; - private static final double EPSILON = 1e-12; - - @Test - public void testConstructor_NoArguments() { - final DoubleProperty v = new SimpleDoubleProperty(); - assertEquals(DEFAULT_BEAN, v.getBean()); - assertEquals(DEFAULT_NAME, v.getName()); - assertEquals(DEFAULT_VALUE, v.get(), EPSILON); - } - - @Test - public void testConstructor_InitialValue() { - final DoubleProperty v1 = new SimpleDoubleProperty(VALUE_1); - assertEquals(DEFAULT_BEAN, v1.getBean()); - assertEquals(DEFAULT_NAME, v1.getName()); - assertEquals(VALUE_1, v1.get(), EPSILON); - - final DoubleProperty v2 = new SimpleDoubleProperty(DEFAULT_VALUE); - assertEquals(DEFAULT_BEAN, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final DoubleProperty v = new SimpleDoubleProperty(bean, name); - assertEquals(bean, v.getBean()); - assertEquals(name, v.getName()); - assertEquals(DEFAULT_VALUE, v.get(), EPSILON); - - final DoubleProperty v2 = new SimpleDoubleProperty(bean, null); - assertEquals(bean, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final DoubleProperty v1 = new SimpleDoubleProperty(bean, name, VALUE_1); - assertEquals(bean, v1.getBean()); - assertEquals(name, v1.getName()); - assertEquals(VALUE_1, v1.get(), EPSILON); - - final DoubleProperty v2 = new SimpleDoubleProperty(bean, name, DEFAULT_VALUE); - assertEquals(bean, v2.getBean()); - assertEquals(name, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); - - final DoubleProperty v3 = new SimpleDoubleProperty(bean, null, VALUE_1); - assertEquals(bean, v3.getBean()); - assertEquals(DEFAULT_NAME, v3.getName()); - assertEquals(VALUE_1, v3.get(), EPSILON); - - final DoubleProperty v4 = new SimpleDoubleProperty(bean, null, DEFAULT_VALUE); - assertEquals(bean, v4.getBean()); - assertEquals(DEFAULT_NAME, v4.getName()); - assertEquals(DEFAULT_VALUE, v4.get(), EPSILON); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/SimpleDoublePropertyTest.java 2015-08-31 10:23:55.181217162 -0400 @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.SimpleDoubleProperty; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class SimpleDoublePropertyTest { + + private static final Object DEFAULT_BEAN = null; + private static final String DEFAULT_NAME = ""; + private static final double DEFAULT_VALUE = 0.0; + private static final double VALUE_1 = -Math.E; + private static final double EPSILON = 1e-12; + + @Test + public void testConstructor_NoArguments() { + final DoubleProperty v = new SimpleDoubleProperty(); + assertEquals(DEFAULT_BEAN, v.getBean()); + assertEquals(DEFAULT_NAME, v.getName()); + assertEquals(DEFAULT_VALUE, v.get(), EPSILON); + } + + @Test + public void testConstructor_InitialValue() { + final DoubleProperty v1 = new SimpleDoubleProperty(VALUE_1); + assertEquals(DEFAULT_BEAN, v1.getBean()); + assertEquals(DEFAULT_NAME, v1.getName()); + assertEquals(VALUE_1, v1.get(), EPSILON); + + final DoubleProperty v2 = new SimpleDoubleProperty(DEFAULT_VALUE); + assertEquals(DEFAULT_BEAN, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final DoubleProperty v = new SimpleDoubleProperty(bean, name); + assertEquals(bean, v.getBean()); + assertEquals(name, v.getName()); + assertEquals(DEFAULT_VALUE, v.get(), EPSILON); + + final DoubleProperty v2 = new SimpleDoubleProperty(bean, null); + assertEquals(bean, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final DoubleProperty v1 = new SimpleDoubleProperty(bean, name, VALUE_1); + assertEquals(bean, v1.getBean()); + assertEquals(name, v1.getName()); + assertEquals(VALUE_1, v1.get(), EPSILON); + + final DoubleProperty v2 = new SimpleDoubleProperty(bean, name, DEFAULT_VALUE); + assertEquals(bean, v2.getBean()); + assertEquals(name, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); + + final DoubleProperty v3 = new SimpleDoubleProperty(bean, null, VALUE_1); + assertEquals(bean, v3.getBean()); + assertEquals(DEFAULT_NAME, v3.getName()); + assertEquals(VALUE_1, v3.get(), EPSILON); + + final DoubleProperty v4 = new SimpleDoubleProperty(bean, null, DEFAULT_VALUE); + assertEquals(bean, v4.getBean()); + assertEquals(DEFAULT_NAME, v4.getName()); + assertEquals(DEFAULT_VALUE, v4.get(), EPSILON); + } +} --- old/modules/base/src/test/java/javafx/beans/property/SimpleFloatPropertyTest.java 2015-08-31 10:23:56.065217152 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class SimpleFloatPropertyTest { - - private static final Object DEFAULT_BEAN = null; - private static final String DEFAULT_NAME = ""; - private static final float DEFAULT_VALUE = 0.0f; - private static final float VALUE_1 = (float) -Math.E; - private static final float EPSILON = 1e-6f; - - @Test - public void testConstructor_NoArguments() { - final FloatProperty v = new SimpleFloatProperty(); - assertEquals(DEFAULT_BEAN, v.getBean()); - assertEquals(DEFAULT_NAME, v.getName()); - assertEquals(DEFAULT_VALUE, v.get(), EPSILON); - } - - @Test - public void testConstructor_InitialValue() { - final FloatProperty v1 = new SimpleFloatProperty(VALUE_1); - assertEquals(DEFAULT_BEAN, v1.getBean()); - assertEquals(DEFAULT_NAME, v1.getName()); - assertEquals(VALUE_1, v1.get(), EPSILON); - - final FloatProperty v2 = new SimpleFloatProperty(DEFAULT_VALUE); - assertEquals(DEFAULT_BEAN, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final FloatProperty v = new SimpleFloatProperty(bean, name); - assertEquals(bean, v.getBean()); - assertEquals(name, v.getName()); - assertEquals(DEFAULT_VALUE, v.get(), EPSILON); - - final FloatProperty v2 = new SimpleFloatProperty(bean, null); - assertEquals(bean, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final FloatProperty v1 = new SimpleFloatProperty(bean, name, VALUE_1); - assertEquals(bean, v1.getBean()); - assertEquals(name, v1.getName()); - assertEquals(VALUE_1, v1.get(), EPSILON); - - final FloatProperty v2 = new SimpleFloatProperty(bean, name, DEFAULT_VALUE); - assertEquals(bean, v2.getBean()); - assertEquals(name, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); - - final FloatProperty v3 = new SimpleFloatProperty(bean, null, VALUE_1); - assertEquals(bean, v3.getBean()); - assertEquals(DEFAULT_NAME, v3.getName()); - assertEquals(VALUE_1, v3.get(), EPSILON); - - final FloatProperty v4 = new SimpleFloatProperty(bean, null, DEFAULT_VALUE); - assertEquals(bean, v4.getBean()); - assertEquals(DEFAULT_NAME, v4.getName()); - assertEquals(DEFAULT_VALUE, v4.get(), EPSILON); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/SimpleFloatPropertyTest.java 2015-08-31 10:23:55.861217154 -0400 @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.FloatProperty; +import javafx.beans.property.SimpleFloatProperty; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class SimpleFloatPropertyTest { + + private static final Object DEFAULT_BEAN = null; + private static final String DEFAULT_NAME = ""; + private static final float DEFAULT_VALUE = 0.0f; + private static final float VALUE_1 = (float) -Math.E; + private static final float EPSILON = 1e-6f; + + @Test + public void testConstructor_NoArguments() { + final FloatProperty v = new SimpleFloatProperty(); + assertEquals(DEFAULT_BEAN, v.getBean()); + assertEquals(DEFAULT_NAME, v.getName()); + assertEquals(DEFAULT_VALUE, v.get(), EPSILON); + } + + @Test + public void testConstructor_InitialValue() { + final FloatProperty v1 = new SimpleFloatProperty(VALUE_1); + assertEquals(DEFAULT_BEAN, v1.getBean()); + assertEquals(DEFAULT_NAME, v1.getName()); + assertEquals(VALUE_1, v1.get(), EPSILON); + + final FloatProperty v2 = new SimpleFloatProperty(DEFAULT_VALUE); + assertEquals(DEFAULT_BEAN, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final FloatProperty v = new SimpleFloatProperty(bean, name); + assertEquals(bean, v.getBean()); + assertEquals(name, v.getName()); + assertEquals(DEFAULT_VALUE, v.get(), EPSILON); + + final FloatProperty v2 = new SimpleFloatProperty(bean, null); + assertEquals(bean, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final FloatProperty v1 = new SimpleFloatProperty(bean, name, VALUE_1); + assertEquals(bean, v1.getBean()); + assertEquals(name, v1.getName()); + assertEquals(VALUE_1, v1.get(), EPSILON); + + final FloatProperty v2 = new SimpleFloatProperty(bean, name, DEFAULT_VALUE); + assertEquals(bean, v2.getBean()); + assertEquals(name, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get(), EPSILON); + + final FloatProperty v3 = new SimpleFloatProperty(bean, null, VALUE_1); + assertEquals(bean, v3.getBean()); + assertEquals(DEFAULT_NAME, v3.getName()); + assertEquals(VALUE_1, v3.get(), EPSILON); + + final FloatProperty v4 = new SimpleFloatProperty(bean, null, DEFAULT_VALUE); + assertEquals(bean, v4.getBean()); + assertEquals(DEFAULT_NAME, v4.getName()); + assertEquals(DEFAULT_VALUE, v4.get(), EPSILON); + } +} --- old/modules/base/src/test/java/javafx/beans/property/SimpleIntegerPropertyTest.java 2015-08-31 10:23:56.681217145 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class SimpleIntegerPropertyTest { - - private static final Object DEFAULT_BEAN = null; - private static final String DEFAULT_NAME = ""; - private static final int DEFAULT_VALUE = 0; - private static final int VALUE_1 = 13; - - @Test - public void testConstructor_NoArguments() { - final IntegerProperty v = new SimpleIntegerProperty(); - assertEquals(DEFAULT_BEAN, v.getBean()); - assertEquals(DEFAULT_NAME, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - } - - @Test - public void testConstructor_InitialValue() { - final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1); - assertEquals(DEFAULT_BEAN, v1.getBean()); - assertEquals(DEFAULT_NAME, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final IntegerProperty v2 = new SimpleIntegerProperty(DEFAULT_VALUE); - assertEquals(DEFAULT_BEAN, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final IntegerProperty v = new SimpleIntegerProperty(bean, name); - assertEquals(bean, v.getBean()); - assertEquals(name, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - - final IntegerProperty v2 = new SimpleIntegerProperty(bean, null); - assertEquals(bean, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final IntegerProperty v1 = new SimpleIntegerProperty(bean, name, VALUE_1); - assertEquals(bean, v1.getBean()); - assertEquals(name, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final IntegerProperty v2 = new SimpleIntegerProperty(bean, name, DEFAULT_VALUE); - assertEquals(bean, v2.getBean()); - assertEquals(name, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - - final IntegerProperty v3 = new SimpleIntegerProperty(bean, null, VALUE_1); - assertEquals(bean, v3.getBean()); - assertEquals(DEFAULT_NAME, v3.getName()); - assertEquals(VALUE_1, v3.get()); - - final IntegerProperty v4 = new SimpleIntegerProperty(bean, null, DEFAULT_VALUE); - assertEquals(bean, v4.getBean()); - assertEquals(DEFAULT_NAME, v4.getName()); - assertEquals(DEFAULT_VALUE, v4.get()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/SimpleIntegerPropertyTest.java 2015-08-31 10:23:56.549217147 -0400 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleIntegerProperty; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class SimpleIntegerPropertyTest { + + private static final Object DEFAULT_BEAN = null; + private static final String DEFAULT_NAME = ""; + private static final int DEFAULT_VALUE = 0; + private static final int VALUE_1 = 13; + + @Test + public void testConstructor_NoArguments() { + final IntegerProperty v = new SimpleIntegerProperty(); + assertEquals(DEFAULT_BEAN, v.getBean()); + assertEquals(DEFAULT_NAME, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + } + + @Test + public void testConstructor_InitialValue() { + final IntegerProperty v1 = new SimpleIntegerProperty(VALUE_1); + assertEquals(DEFAULT_BEAN, v1.getBean()); + assertEquals(DEFAULT_NAME, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final IntegerProperty v2 = new SimpleIntegerProperty(DEFAULT_VALUE); + assertEquals(DEFAULT_BEAN, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final IntegerProperty v = new SimpleIntegerProperty(bean, name); + assertEquals(bean, v.getBean()); + assertEquals(name, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + + final IntegerProperty v2 = new SimpleIntegerProperty(bean, null); + assertEquals(bean, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final IntegerProperty v1 = new SimpleIntegerProperty(bean, name, VALUE_1); + assertEquals(bean, v1.getBean()); + assertEquals(name, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final IntegerProperty v2 = new SimpleIntegerProperty(bean, name, DEFAULT_VALUE); + assertEquals(bean, v2.getBean()); + assertEquals(name, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + + final IntegerProperty v3 = new SimpleIntegerProperty(bean, null, VALUE_1); + assertEquals(bean, v3.getBean()); + assertEquals(DEFAULT_NAME, v3.getName()); + assertEquals(VALUE_1, v3.get()); + + final IntegerProperty v4 = new SimpleIntegerProperty(bean, null, DEFAULT_VALUE); + assertEquals(bean, v4.getBean()); + assertEquals(DEFAULT_NAME, v4.getName()); + assertEquals(DEFAULT_VALUE, v4.get()); + } +} --- old/modules/base/src/test/java/javafx/beans/property/SimpleListPropertyTest.java 2015-08-31 10:23:57.309217138 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class SimpleListPropertyTest { - - private static final Object DEFAULT_BEAN = null; - private static final String DEFAULT_NAME = ""; - private static final ObservableList DEFAULT_VALUE = null; - private static final ObservableList VALUE_1 = FXCollections.observableArrayList(new Object()); - - @Test - public void testConstructor_NoArguments() { - final ListProperty v = new SimpleListProperty(); - assertEquals(DEFAULT_BEAN, v.getBean()); - assertEquals(DEFAULT_NAME, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - } - - @Test - public void testConstructor_InitialValue() { - final ListProperty v1 = new SimpleListProperty(VALUE_1); - assertEquals(DEFAULT_BEAN, v1.getBean()); - assertEquals(DEFAULT_NAME, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final ListProperty v2 = new SimpleListProperty(DEFAULT_VALUE); - assertEquals(DEFAULT_BEAN, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ListProperty v = new SimpleListProperty(bean, name); - assertEquals(bean, v.getBean()); - assertEquals(name, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - - final ListProperty v2 = new SimpleListProperty(bean, null); - assertEquals(bean, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ListProperty v1 = new SimpleListProperty(bean, name, VALUE_1); - assertEquals(bean, v1.getBean()); - assertEquals(name, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final ListProperty v2 = new SimpleListProperty(bean, name, DEFAULT_VALUE); - assertEquals(bean, v2.getBean()); - assertEquals(name, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - - final ListProperty v3 = new SimpleListProperty(bean, null, VALUE_1); - assertEquals(bean, v3.getBean()); - assertEquals(DEFAULT_NAME, v3.getName()); - assertEquals(VALUE_1, v3.get()); - - final ListProperty v4 = new SimpleListProperty(bean, null, DEFAULT_VALUE); - assertEquals(bean, v4.getBean()); - assertEquals(DEFAULT_NAME, v4.getName()); - assertEquals(DEFAULT_VALUE, v4.get()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/SimpleListPropertyTest.java 2015-08-31 10:23:57.177217140 -0400 @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class SimpleListPropertyTest { + + private static final Object DEFAULT_BEAN = null; + private static final String DEFAULT_NAME = ""; + private static final ObservableList DEFAULT_VALUE = null; + private static final ObservableList VALUE_1 = FXCollections.observableArrayList(new Object()); + + @Test + public void testConstructor_NoArguments() { + final ListProperty v = new SimpleListProperty(); + assertEquals(DEFAULT_BEAN, v.getBean()); + assertEquals(DEFAULT_NAME, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + } + + @Test + public void testConstructor_InitialValue() { + final ListProperty v1 = new SimpleListProperty(VALUE_1); + assertEquals(DEFAULT_BEAN, v1.getBean()); + assertEquals(DEFAULT_NAME, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final ListProperty v2 = new SimpleListProperty(DEFAULT_VALUE); + assertEquals(DEFAULT_BEAN, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ListProperty v = new SimpleListProperty(bean, name); + assertEquals(bean, v.getBean()); + assertEquals(name, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + + final ListProperty v2 = new SimpleListProperty(bean, null); + assertEquals(bean, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ListProperty v1 = new SimpleListProperty(bean, name, VALUE_1); + assertEquals(bean, v1.getBean()); + assertEquals(name, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final ListProperty v2 = new SimpleListProperty(bean, name, DEFAULT_VALUE); + assertEquals(bean, v2.getBean()); + assertEquals(name, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + + final ListProperty v3 = new SimpleListProperty(bean, null, VALUE_1); + assertEquals(bean, v3.getBean()); + assertEquals(DEFAULT_NAME, v3.getName()); + assertEquals(VALUE_1, v3.get()); + + final ListProperty v4 = new SimpleListProperty(bean, null, DEFAULT_VALUE); + assertEquals(bean, v4.getBean()); + assertEquals(DEFAULT_NAME, v4.getName()); + assertEquals(DEFAULT_VALUE, v4.get()); + } +} --- old/modules/base/src/test/java/javafx/beans/property/SimpleLongPropertyTest.java 2015-08-31 10:23:57.969217131 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class SimpleLongPropertyTest { - - private static final Object DEFAULT_BEAN = null; - private static final String DEFAULT_NAME = ""; - private static final long DEFAULT_VALUE = 0L; - private static final long VALUE_1 = -123456789012345L; - - @Test - public void testConstructor_NoArguments() { - final LongProperty v = new SimpleLongProperty(); - assertEquals(DEFAULT_BEAN, v.getBean()); - assertEquals(DEFAULT_NAME, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - } - - @Test - public void testConstructor_InitialValue() { - final LongProperty v1 = new SimpleLongProperty(VALUE_1); - assertEquals(DEFAULT_BEAN, v1.getBean()); - assertEquals(DEFAULT_NAME, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final LongProperty v2 = new SimpleLongProperty(DEFAULT_VALUE); - assertEquals(DEFAULT_BEAN, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final LongProperty v = new SimpleLongProperty(bean, name); - assertEquals(bean, v.getBean()); - assertEquals(name, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - - final LongProperty v2 = new SimpleLongProperty(bean, null); - assertEquals(bean, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final LongProperty v1 = new SimpleLongProperty(bean, name, VALUE_1); - assertEquals(bean, v1.getBean()); - assertEquals(name, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final LongProperty v2 = new SimpleLongProperty(bean, name, DEFAULT_VALUE); - assertEquals(bean, v2.getBean()); - assertEquals(name, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - - final LongProperty v3 = new SimpleLongProperty(bean, null, VALUE_1); - assertEquals(bean, v3.getBean()); - assertEquals(DEFAULT_NAME, v3.getName()); - assertEquals(VALUE_1, v3.get()); - - final LongProperty v4 = new SimpleLongProperty(bean, null, DEFAULT_VALUE); - assertEquals(bean, v4.getBean()); - assertEquals(DEFAULT_NAME, v4.getName()); - assertEquals(DEFAULT_VALUE, v4.get()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/SimpleLongPropertyTest.java 2015-08-31 10:23:57.833217132 -0400 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.LongProperty; +import javafx.beans.property.SimpleLongProperty; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class SimpleLongPropertyTest { + + private static final Object DEFAULT_BEAN = null; + private static final String DEFAULT_NAME = ""; + private static final long DEFAULT_VALUE = 0L; + private static final long VALUE_1 = -123456789012345L; + + @Test + public void testConstructor_NoArguments() { + final LongProperty v = new SimpleLongProperty(); + assertEquals(DEFAULT_BEAN, v.getBean()); + assertEquals(DEFAULT_NAME, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + } + + @Test + public void testConstructor_InitialValue() { + final LongProperty v1 = new SimpleLongProperty(VALUE_1); + assertEquals(DEFAULT_BEAN, v1.getBean()); + assertEquals(DEFAULT_NAME, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final LongProperty v2 = new SimpleLongProperty(DEFAULT_VALUE); + assertEquals(DEFAULT_BEAN, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final LongProperty v = new SimpleLongProperty(bean, name); + assertEquals(bean, v.getBean()); + assertEquals(name, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + + final LongProperty v2 = new SimpleLongProperty(bean, null); + assertEquals(bean, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final LongProperty v1 = new SimpleLongProperty(bean, name, VALUE_1); + assertEquals(bean, v1.getBean()); + assertEquals(name, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final LongProperty v2 = new SimpleLongProperty(bean, name, DEFAULT_VALUE); + assertEquals(bean, v2.getBean()); + assertEquals(name, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + + final LongProperty v3 = new SimpleLongProperty(bean, null, VALUE_1); + assertEquals(bean, v3.getBean()); + assertEquals(DEFAULT_NAME, v3.getName()); + assertEquals(VALUE_1, v3.get()); + + final LongProperty v4 = new SimpleLongProperty(bean, null, DEFAULT_VALUE); + assertEquals(bean, v4.getBean()); + assertEquals(DEFAULT_NAME, v4.getName()); + assertEquals(DEFAULT_VALUE, v4.get()); + } +} --- old/modules/base/src/test/java/javafx/beans/property/SimpleObjectPropertyTest.java 2015-08-31 10:23:58.749217122 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class SimpleObjectPropertyTest { - - private static final Object DEFAULT_BEAN = null; - private static final String DEFAULT_NAME = ""; - private static final Object DEFAULT_VALUE = null; - private static final Object VALUE_1 = new Object(); - - @Test - public void testConstructor_NoArguments() { - final ObjectProperty v = new SimpleObjectProperty(); - assertEquals(DEFAULT_BEAN, v.getBean()); - assertEquals(DEFAULT_NAME, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - } - - @Test - public void testConstructor_InitialValue() { - final ObjectProperty v1 = new SimpleObjectProperty(VALUE_1); - assertEquals(DEFAULT_BEAN, v1.getBean()); - assertEquals(DEFAULT_NAME, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final ObjectProperty v2 = new SimpleObjectProperty(DEFAULT_VALUE); - assertEquals(DEFAULT_BEAN, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final ObjectProperty v = new SimpleObjectProperty(bean, name); - assertEquals(bean, v.getBean()); - assertEquals(name, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - - final ObjectProperty v2 = new SimpleObjectProperty(bean, null); - assertEquals(bean, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final ObjectProperty v1 = new SimpleObjectProperty(bean, name, VALUE_1); - assertEquals(bean, v1.getBean()); - assertEquals(name, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final ObjectProperty v2 = new SimpleObjectProperty(bean, name, DEFAULT_VALUE); - assertEquals(bean, v2.getBean()); - assertEquals(name, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - - final ObjectProperty v3 = new SimpleObjectProperty(bean, null, VALUE_1); - assertEquals(bean, v3.getBean()); - assertEquals(DEFAULT_NAME, v3.getName()); - assertEquals(VALUE_1, v3.get()); - - final ObjectProperty v4 = new SimpleObjectProperty(bean, null, DEFAULT_VALUE); - assertEquals(bean, v4.getBean()); - assertEquals(DEFAULT_NAME, v4.getName()); - assertEquals(DEFAULT_VALUE, v4.get()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/SimpleObjectPropertyTest.java 2015-08-31 10:23:58.545217124 -0400 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class SimpleObjectPropertyTest { + + private static final Object DEFAULT_BEAN = null; + private static final String DEFAULT_NAME = ""; + private static final Object DEFAULT_VALUE = null; + private static final Object VALUE_1 = new Object(); + + @Test + public void testConstructor_NoArguments() { + final ObjectProperty v = new SimpleObjectProperty(); + assertEquals(DEFAULT_BEAN, v.getBean()); + assertEquals(DEFAULT_NAME, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + } + + @Test + public void testConstructor_InitialValue() { + final ObjectProperty v1 = new SimpleObjectProperty(VALUE_1); + assertEquals(DEFAULT_BEAN, v1.getBean()); + assertEquals(DEFAULT_NAME, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final ObjectProperty v2 = new SimpleObjectProperty(DEFAULT_VALUE); + assertEquals(DEFAULT_BEAN, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final ObjectProperty v = new SimpleObjectProperty(bean, name); + assertEquals(bean, v.getBean()); + assertEquals(name, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + + final ObjectProperty v2 = new SimpleObjectProperty(bean, null); + assertEquals(bean, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final ObjectProperty v1 = new SimpleObjectProperty(bean, name, VALUE_1); + assertEquals(bean, v1.getBean()); + assertEquals(name, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final ObjectProperty v2 = new SimpleObjectProperty(bean, name, DEFAULT_VALUE); + assertEquals(bean, v2.getBean()); + assertEquals(name, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + + final ObjectProperty v3 = new SimpleObjectProperty(bean, null, VALUE_1); + assertEquals(bean, v3.getBean()); + assertEquals(DEFAULT_NAME, v3.getName()); + assertEquals(VALUE_1, v3.get()); + + final ObjectProperty v4 = new SimpleObjectProperty(bean, null, DEFAULT_VALUE); + assertEquals(bean, v4.getBean()); + assertEquals(DEFAULT_NAME, v4.getName()); + assertEquals(DEFAULT_VALUE, v4.get()); + } +} --- old/modules/base/src/test/java/javafx/beans/property/SimpleStringPropertyTest.java 2015-08-31 10:23:59.425217114 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class SimpleStringPropertyTest { - - private static final Object DEFAULT_BEAN = null; - private static final String DEFAULT_NAME = ""; - private static final String DEFAULT_VALUE = null; - private static final String VALUE_1 = "Hello World"; - - @Test - public void testConstructor_NoArguments() { - final StringProperty v = new SimpleStringProperty(); - assertEquals(DEFAULT_BEAN, v.getBean()); - assertEquals(DEFAULT_NAME, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - } - - @Test - public void testConstructor_InitialValue() { - final StringProperty v1 = new SimpleStringProperty(VALUE_1); - assertEquals(DEFAULT_BEAN, v1.getBean()); - assertEquals(DEFAULT_NAME, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final StringProperty v2 = new SimpleStringProperty(DEFAULT_VALUE); - assertEquals(DEFAULT_BEAN, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name() { - final Object bean = new Object(); - final String name = "My name"; - final StringProperty v = new SimpleStringProperty(bean, name); - assertEquals(bean, v.getBean()); - assertEquals(name, v.getName()); - assertEquals(DEFAULT_VALUE, v.get()); - - final StringProperty v2 = new SimpleStringProperty(bean, null); - assertEquals(bean, v2.getBean()); - assertEquals(DEFAULT_NAME, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - } - - @Test - public void testConstructor_Bean_Name_InitialValue() { - final Object bean = new Object(); - final String name = "My name"; - final StringProperty v1 = new SimpleStringProperty(bean, name, VALUE_1); - assertEquals(bean, v1.getBean()); - assertEquals(name, v1.getName()); - assertEquals(VALUE_1, v1.get()); - - final StringProperty v2 = new SimpleStringProperty(bean, name, DEFAULT_VALUE); - assertEquals(bean, v2.getBean()); - assertEquals(name, v2.getName()); - assertEquals(DEFAULT_VALUE, v2.get()); - - final StringProperty v3 = new SimpleStringProperty(bean, null, VALUE_1); - assertEquals(bean, v3.getBean()); - assertEquals(DEFAULT_NAME, v3.getName()); - assertEquals(VALUE_1, v3.get()); - - final StringProperty v4 = new SimpleStringProperty(bean, null, DEFAULT_VALUE); - assertEquals(bean, v4.getBean()); - assertEquals(DEFAULT_NAME, v4.getName()); - assertEquals(DEFAULT_VALUE, v4.get()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/SimpleStringPropertyTest.java 2015-08-31 10:23:59.217217117 -0400 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class SimpleStringPropertyTest { + + private static final Object DEFAULT_BEAN = null; + private static final String DEFAULT_NAME = ""; + private static final String DEFAULT_VALUE = null; + private static final String VALUE_1 = "Hello World"; + + @Test + public void testConstructor_NoArguments() { + final StringProperty v = new SimpleStringProperty(); + assertEquals(DEFAULT_BEAN, v.getBean()); + assertEquals(DEFAULT_NAME, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + } + + @Test + public void testConstructor_InitialValue() { + final StringProperty v1 = new SimpleStringProperty(VALUE_1); + assertEquals(DEFAULT_BEAN, v1.getBean()); + assertEquals(DEFAULT_NAME, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final StringProperty v2 = new SimpleStringProperty(DEFAULT_VALUE); + assertEquals(DEFAULT_BEAN, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name() { + final Object bean = new Object(); + final String name = "My name"; + final StringProperty v = new SimpleStringProperty(bean, name); + assertEquals(bean, v.getBean()); + assertEquals(name, v.getName()); + assertEquals(DEFAULT_VALUE, v.get()); + + final StringProperty v2 = new SimpleStringProperty(bean, null); + assertEquals(bean, v2.getBean()); + assertEquals(DEFAULT_NAME, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + } + + @Test + public void testConstructor_Bean_Name_InitialValue() { + final Object bean = new Object(); + final String name = "My name"; + final StringProperty v1 = new SimpleStringProperty(bean, name, VALUE_1); + assertEquals(bean, v1.getBean()); + assertEquals(name, v1.getName()); + assertEquals(VALUE_1, v1.get()); + + final StringProperty v2 = new SimpleStringProperty(bean, name, DEFAULT_VALUE); + assertEquals(bean, v2.getBean()); + assertEquals(name, v2.getName()); + assertEquals(DEFAULT_VALUE, v2.get()); + + final StringProperty v3 = new SimpleStringProperty(bean, null, VALUE_1); + assertEquals(bean, v3.getBean()); + assertEquals(DEFAULT_NAME, v3.getName()); + assertEquals(VALUE_1, v3.get()); + + final StringProperty v4 = new SimpleStringProperty(bean, null, DEFAULT_VALUE); + assertEquals(bean, v4.getBean()); + assertEquals(DEFAULT_NAME, v4.getName()); + assertEquals(DEFAULT_VALUE, v4.get()); + } +} --- old/modules/base/src/test/java/javafx/beans/property/StringPropertyBaseTest.java 2015-08-31 10:24:00.101217107 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,443 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableStringValueStub; - -import org.junit.Before; -import org.junit.Test; - -public class StringPropertyBaseTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final String UNDEFINED = "UNDEFINED"; - private static final String VALUE_1a = "Hello World"; - private static final String VALUE_1b = "HELLO WORLD"; - private static final String VALUE_2a = "Goodbye"; - private static final String VALUE_2b = "GOODBYE"; - - private StringPropertyMock property; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() throws Exception { - property = new StringPropertyMock(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - } - - private void attachInvalidationListener() { - property.addListener(invalidationListener); - property.get(); - invalidationListener.reset(); - } - - private void attachChangeListener() { - property.addListener(changeListener); - property.get(); - changeListener.reset(); - } - - @Test - public void testConstructor() { - final StringProperty p1 = new SimpleStringProperty(); - assertEquals(null, p1.get()); - assertEquals(null, p1.getValue()); - assertFalse(property.isBound()); - - final StringProperty p2 = new SimpleStringProperty(VALUE_1b); - assertEquals(VALUE_1b, p2.get()); - assertEquals(VALUE_1b, p2.getValue()); - assertFalse(property.isBound()); - } - - public void testInvalidationListener() { - attachInvalidationListener(); - property.set(VALUE_2a); - invalidationListener.check(property, 1); - property.removeListener(invalidationListener); - invalidationListener.reset(); - property.set(VALUE_1a); - invalidationListener.check(null, 0); - } - - @Test - public void testChangeListener() { - attachChangeListener(); - property.set(VALUE_2a); - changeListener.check(property, null, VALUE_2a, 1); - property.removeListener(changeListener); - changeListener.reset(); - property.set(VALUE_1a); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - } - - @Test - public void testLazySet() { - attachInvalidationListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.set(VALUE_1a); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSet() { - attachChangeListener(); - - // set value once - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, null, VALUE_2a, 1); - - // set same value again - property.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.set(VALUE_1a); - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - } - - @Test - public void testLazySetValue() { - attachInvalidationListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // set same value again - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - invalidationListener.check(null, 0); - - // set value twice without reading - property.setValue(VALUE_1a); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerSetValue() { - attachChangeListener(); - - // set value once - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, null, VALUE_2a, 1); - - // set same value again - property.setValue(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(0); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - - // set value twice without reading - property.setValue(VALUE_1a); - property.setValue(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - } - - @Test(expected=RuntimeException.class) - public void testSetBoundValue() { - final StringProperty v = new SimpleStringProperty(VALUE_1a); - property.bind(v); - property.set(VALUE_1a); - } - - @Test - public void testLazyBind() { - attachInvalidationListener(); - final ObservableStringValueStub v = new ObservableStringValueStub(VALUE_1a); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding once - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice without reading - v.set(VALUE_1a); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(1); - invalidationListener.check(property, 1); - - // change binding twice to same value - v.set(VALUE_1a); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(1); - invalidationListener.check(property, 1); - } - - @Test - public void testEagerBind() { - attachChangeListener(); - final ObservableStringValueStub v = new ObservableStringValueStub(VALUE_1a); - - property.bind(v); - assertEquals(VALUE_1a, property.get()); - assertTrue(property.isBound()); - property.check(1); - changeListener.check(property, null, VALUE_1a, 1); - - // change binding once - v.set(VALUE_2a); - assertEquals(VALUE_2a, property.get()); - property.check(1); - changeListener.check(property, VALUE_1a, VALUE_2a, 1); - - // change binding twice without reading - v.set(VALUE_1a); - v.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - property.check(2); - changeListener.check(property, VALUE_1a, VALUE_1b, 2); - - // change binding twice to same value - v.set(VALUE_1a); - v.set(VALUE_1a); - assertEquals(VALUE_1a, property.get()); - property.check(2); - changeListener.check(property, VALUE_1b, VALUE_1a, 1); - } - - @Test(expected=NullPointerException.class) - public void testBindToNull() { - property.bind(null); - } - - @Test - public void testRebind() { - attachInvalidationListener(); - final StringProperty v1 = new SimpleStringProperty(VALUE_1a); - final StringProperty v2 = new SimpleStringProperty(VALUE_2a); - property.bind(v1); - property.get(); - property.reset(); - invalidationListener.reset(); - - // rebind causes invalidation event - property.bind(v2); - assertEquals(VALUE_2a, property.get()); - assertTrue(property.isBound()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // change old binding - v1.set(VALUE_1b); - assertEquals(VALUE_2a, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // change new binding - v2.set(VALUE_2b); - assertEquals(VALUE_2b, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - property.reset(); - - // rebind to same observable should have no effect - property.bind(v2); - assertEquals(VALUE_2b, property.get()); - assertTrue(property.isBound()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - } - - @Test - public void testUnbind() { - attachInvalidationListener(); - final StringProperty v = new SimpleStringProperty(VALUE_1a); - property.bind(v); - property.unbind(); - assertEquals(VALUE_1a, property.get()); - assertFalse(property.isBound()); - property.reset(); - invalidationListener.reset(); - - // change binding - v.set(VALUE_2a); - assertEquals(VALUE_1a, property.get()); - assertEquals(0, property.counter); - invalidationListener.check(null, 0); - property.reset(); - - // set value - property.set(VALUE_1b); - assertEquals(VALUE_1b, property.get()); - assertEquals(1, property.counter); - invalidationListener.check(property, 1); - } - - @Test - public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { - final StringProperty v = new SimpleStringProperty(VALUE_1a); - final InvalidationListenerMock listener2 = new InvalidationListenerMock(); - final InvalidationListenerMock listener3 = new InvalidationListenerMock(); - - // setting the property - property.set(VALUE_1a); - property.addListener(listener2); - listener2.reset(); - property.set(VALUE_1b); - listener2.check(property, 1); - - // binding the property - property.bind(v); - v.set(VALUE_2a); - property.addListener(listener3); - v.get(); - listener3.reset(); - v.set(VALUE_2b); - listener3.check(property, 1); - } - - @Test - public void testToString() { - final String value1 = "Hello World"; - final String value2 = "Goodbye"; - final StringProperty v = new SimpleStringProperty(value2); - - property.set(value1); - assertEquals("StringProperty [value: " + value1 + "]", property.toString()); - - property.bind(v); - assertEquals("StringProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("StringProperty [bound, value: " + value2 + "]", property.toString()); - v.set(value1); - assertEquals("StringProperty [bound, invalid]", property.toString()); - property.get(); - assertEquals("StringProperty [bound, value: " + value1 + "]", property.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final StringProperty v1 = new StringPropertyMock(bean, name); - assertEquals("StringProperty [bean: " + bean.toString() + ", name: My name, value: " + null + "]", v1.toString()); - v1.set(value1); - assertEquals("StringProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); - - final StringProperty v2 = new StringPropertyMock(bean, NO_NAME_1); - assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + null + "]", v2.toString()); - v2.set(value1); - assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); - - final StringProperty v3 = new StringPropertyMock(bean, NO_NAME_2); - assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + null + "]", v3.toString()); - v3.set(value1); - assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); - - final StringProperty v4 = new StringPropertyMock(NO_BEAN, name); - assertEquals("StringProperty [name: My name, value: " + null + "]", v4.toString()); - v4.set(value1); - assertEquals("StringProperty [name: My name, value: " + value1 + "]", v4.toString()); - } - - private static class StringPropertyMock extends StringPropertyBase { - - private final Object bean; - private final String name; - private int counter; - - private StringPropertyMock() { - this.bean = NO_BEAN; - this.name = NO_NAME_1; - } - - private StringPropertyMock(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - protected void invalidated() { - counter++; - } - - private void check(int expected) { - assertEquals(expected, counter); - reset(); - } - - private void reset() { - counter = 0; - } - - @Override public Object getBean() { return bean; } - - @Override public String getName() { return name; } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/StringPropertyBaseTest.java 2015-08-31 10:23:59.893217109 -0400 @@ -0,0 +1,446 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.beans.property.StringPropertyBase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableStringValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class StringPropertyBaseTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final String UNDEFINED = "UNDEFINED"; + private static final String VALUE_1a = "Hello World"; + private static final String VALUE_1b = "HELLO WORLD"; + private static final String VALUE_2a = "Goodbye"; + private static final String VALUE_2b = "GOODBYE"; + + private StringPropertyMock property; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() throws Exception { + property = new StringPropertyMock(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + } + + private void attachInvalidationListener() { + property.addListener(invalidationListener); + property.get(); + invalidationListener.reset(); + } + + private void attachChangeListener() { + property.addListener(changeListener); + property.get(); + changeListener.reset(); + } + + @Test + public void testConstructor() { + final StringProperty p1 = new SimpleStringProperty(); + assertEquals(null, p1.get()); + assertEquals(null, p1.getValue()); + assertFalse(property.isBound()); + + final StringProperty p2 = new SimpleStringProperty(VALUE_1b); + assertEquals(VALUE_1b, p2.get()); + assertEquals(VALUE_1b, p2.getValue()); + assertFalse(property.isBound()); + } + + public void testInvalidationListener() { + attachInvalidationListener(); + property.set(VALUE_2a); + invalidationListener.check(property, 1); + property.removeListener(invalidationListener); + invalidationListener.reset(); + property.set(VALUE_1a); + invalidationListener.check(null, 0); + } + + @Test + public void testChangeListener() { + attachChangeListener(); + property.set(VALUE_2a); + changeListener.check(property, null, VALUE_2a, 1); + property.removeListener(changeListener); + changeListener.reset(); + property.set(VALUE_1a); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + } + + @Test + public void testLazySet() { + attachInvalidationListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.set(VALUE_1a); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSet() { + attachChangeListener(); + + // set value once + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, null, VALUE_2a, 1); + + // set same value again + property.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.set(VALUE_1a); + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + } + + @Test + public void testLazySetValue() { + attachInvalidationListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // set same value again + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + invalidationListener.check(null, 0); + + // set value twice without reading + property.setValue(VALUE_1a); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerSetValue() { + attachChangeListener(); + + // set value once + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, null, VALUE_2a, 1); + + // set same value again + property.setValue(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(0); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + + // set value twice without reading + property.setValue(VALUE_1a); + property.setValue(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + } + + @Test(expected=RuntimeException.class) + public void testSetBoundValue() { + final StringProperty v = new SimpleStringProperty(VALUE_1a); + property.bind(v); + property.set(VALUE_1a); + } + + @Test + public void testLazyBind() { + attachInvalidationListener(); + final ObservableStringValueStub v = new ObservableStringValueStub(VALUE_1a); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding once + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice without reading + v.set(VALUE_1a); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(1); + invalidationListener.check(property, 1); + + // change binding twice to same value + v.set(VALUE_1a); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(1); + invalidationListener.check(property, 1); + } + + @Test + public void testEagerBind() { + attachChangeListener(); + final ObservableStringValueStub v = new ObservableStringValueStub(VALUE_1a); + + property.bind(v); + assertEquals(VALUE_1a, property.get()); + assertTrue(property.isBound()); + property.check(1); + changeListener.check(property, null, VALUE_1a, 1); + + // change binding once + v.set(VALUE_2a); + assertEquals(VALUE_2a, property.get()); + property.check(1); + changeListener.check(property, VALUE_1a, VALUE_2a, 1); + + // change binding twice without reading + v.set(VALUE_1a); + v.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + property.check(2); + changeListener.check(property, VALUE_1a, VALUE_1b, 2); + + // change binding twice to same value + v.set(VALUE_1a); + v.set(VALUE_1a); + assertEquals(VALUE_1a, property.get()); + property.check(2); + changeListener.check(property, VALUE_1b, VALUE_1a, 1); + } + + @Test(expected=NullPointerException.class) + public void testBindToNull() { + property.bind(null); + } + + @Test + public void testRebind() { + attachInvalidationListener(); + final StringProperty v1 = new SimpleStringProperty(VALUE_1a); + final StringProperty v2 = new SimpleStringProperty(VALUE_2a); + property.bind(v1); + property.get(); + property.reset(); + invalidationListener.reset(); + + // rebind causes invalidation event + property.bind(v2); + assertEquals(VALUE_2a, property.get()); + assertTrue(property.isBound()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // change old binding + v1.set(VALUE_1b); + assertEquals(VALUE_2a, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // change new binding + v2.set(VALUE_2b); + assertEquals(VALUE_2b, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + property.reset(); + + // rebind to same observable should have no effect + property.bind(v2); + assertEquals(VALUE_2b, property.get()); + assertTrue(property.isBound()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + } + + @Test + public void testUnbind() { + attachInvalidationListener(); + final StringProperty v = new SimpleStringProperty(VALUE_1a); + property.bind(v); + property.unbind(); + assertEquals(VALUE_1a, property.get()); + assertFalse(property.isBound()); + property.reset(); + invalidationListener.reset(); + + // change binding + v.set(VALUE_2a); + assertEquals(VALUE_1a, property.get()); + assertEquals(0, property.counter); + invalidationListener.check(null, 0); + property.reset(); + + // set value + property.set(VALUE_1b); + assertEquals(VALUE_1b, property.get()); + assertEquals(1, property.counter); + invalidationListener.check(property, 1); + } + + @Test + public void testAddingListenerWillAlwaysReceiveInvalidationEvent() { + final StringProperty v = new SimpleStringProperty(VALUE_1a); + final InvalidationListenerMock listener2 = new InvalidationListenerMock(); + final InvalidationListenerMock listener3 = new InvalidationListenerMock(); + + // setting the property + property.set(VALUE_1a); + property.addListener(listener2); + listener2.reset(); + property.set(VALUE_1b); + listener2.check(property, 1); + + // binding the property + property.bind(v); + v.set(VALUE_2a); + property.addListener(listener3); + v.get(); + listener3.reset(); + v.set(VALUE_2b); + listener3.check(property, 1); + } + + @Test + public void testToString() { + final String value1 = "Hello World"; + final String value2 = "Goodbye"; + final StringProperty v = new SimpleStringProperty(value2); + + property.set(value1); + assertEquals("StringProperty [value: " + value1 + "]", property.toString()); + + property.bind(v); + assertEquals("StringProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("StringProperty [bound, value: " + value2 + "]", property.toString()); + v.set(value1); + assertEquals("StringProperty [bound, invalid]", property.toString()); + property.get(); + assertEquals("StringProperty [bound, value: " + value1 + "]", property.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final StringProperty v1 = new StringPropertyMock(bean, name); + assertEquals("StringProperty [bean: " + bean.toString() + ", name: My name, value: " + null + "]", v1.toString()); + v1.set(value1); + assertEquals("StringProperty [bean: " + bean.toString() + ", name: My name, value: " + value1 + "]", v1.toString()); + + final StringProperty v2 = new StringPropertyMock(bean, NO_NAME_1); + assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + null + "]", v2.toString()); + v2.set(value1); + assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v2.toString()); + + final StringProperty v3 = new StringPropertyMock(bean, NO_NAME_2); + assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + null + "]", v3.toString()); + v3.set(value1); + assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + value1 + "]", v3.toString()); + + final StringProperty v4 = new StringPropertyMock(NO_BEAN, name); + assertEquals("StringProperty [name: My name, value: " + null + "]", v4.toString()); + v4.set(value1); + assertEquals("StringProperty [name: My name, value: " + value1 + "]", v4.toString()); + } + + private static class StringPropertyMock extends StringPropertyBase { + + private final Object bean; + private final String name; + private int counter; + + private StringPropertyMock() { + this.bean = NO_BEAN; + this.name = NO_NAME_1; + } + + private StringPropertyMock(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + protected void invalidated() { + counter++; + } + + private void check(int expected) { + assertEquals(expected, counter); + reset(); + } + + private void reset() { + counter = 0; + } + + @Override public Object getBean() { return bean; } + + @Override public String getName() { return name; } + } + +} --- old/modules/base/src/test/java/javafx/beans/property/StringPropertyTest.java 2015-08-31 10:24:00.737217100 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.property; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import javafx.beans.InvalidationListener; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; - -import org.junit.Test; - -public class StringPropertyTest { - - private static final Object NO_BEAN = null; - private static final String NO_NAME_1 = null; - private static final String NO_NAME_2 = ""; - private static final String VALUE_1 = "Hello World"; - private static final String VALUE_2 = "Goodbye World"; - private static final String DEFAULT = null; - - @Test - public void testBindBidirectional() { - final StringProperty p1 = new SimpleStringProperty(VALUE_2); - final StringProperty p2 = new SimpleStringProperty(VALUE_1); - - p1.bindBidirectional(p2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_2, p2.get()); - - p2.set(VALUE_1); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.unbindBidirectional(p2); - p1.set(VALUE_2); - assertEquals(VALUE_2, p1.get()); - assertEquals(VALUE_1, p2.get()); - - p1.set(VALUE_1); - p2.set(VALUE_2); - assertEquals(VALUE_1, p1.get()); - assertEquals(VALUE_2, p2.get()); - } - - @Test - public void testToString() { - final StringProperty v0 = new StringPropertyStub(NO_BEAN, NO_NAME_1); - assertEquals("StringProperty [value: " + DEFAULT + "]", v0.toString()); - - final StringProperty v1 = new StringPropertyStub(NO_BEAN, NO_NAME_2); - assertEquals("StringProperty [value: " + DEFAULT + "]", v1.toString()); - - final Object bean = new Object(); - final String name = "My name"; - final StringProperty v2 = new StringPropertyStub(bean, name); - assertEquals("StringProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); - v2.set(VALUE_1); - assertEquals("StringProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); - - final StringProperty v3 = new StringPropertyStub(bean, NO_NAME_1); - assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); - v3.set(VALUE_1); - assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); - - final StringProperty v4 = new StringPropertyStub(bean, NO_NAME_2); - assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); - v4.set(VALUE_1); - assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); - - final StringProperty v5 = new StringPropertyStub(NO_BEAN, name); - assertEquals("StringProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); - v5.set(VALUE_1); - assertEquals("StringProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); - } - - private class StringPropertyStub extends StringProperty { - - private final Object bean; - private final String name; - private String value; - - private StringPropertyStub(Object bean, String name) { - this.bean = bean; - this.name = name; - } - - @Override - public Object getBean() { - return bean; - } - - @Override - public String getName() { - return name; - } - - @Override - public String get() { - return value; - } - - @Override - public void set(String value) { - this.value = value; - } - - @Override - public void bind(ObservableValue observable) { - fail("Not in use"); - } - - @Override - public void unbind() { - fail("Not in use"); - } - - @Override - public boolean isBound() { - fail("Not in use"); - return false; - } - - @Override - public void addListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(ChangeListener listener) { - fail("Not in use"); - } - - @Override - public void addListener(InvalidationListener listener) { - fail("Not in use"); - } - - @Override - public void removeListener(InvalidationListener listener) { - fail("Not in use"); - } - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/StringPropertyTest.java 2015-08-31 10:24:00.605217101 -0400 @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import javafx.beans.InvalidationListener; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; + +import org.junit.Test; + +public class StringPropertyTest { + + private static final Object NO_BEAN = null; + private static final String NO_NAME_1 = null; + private static final String NO_NAME_2 = ""; + private static final String VALUE_1 = "Hello World"; + private static final String VALUE_2 = "Goodbye World"; + private static final String DEFAULT = null; + + @Test + public void testBindBidirectional() { + final StringProperty p1 = new SimpleStringProperty(VALUE_2); + final StringProperty p2 = new SimpleStringProperty(VALUE_1); + + p1.bindBidirectional(p2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_2, p2.get()); + + p2.set(VALUE_1); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.unbindBidirectional(p2); + p1.set(VALUE_2); + assertEquals(VALUE_2, p1.get()); + assertEquals(VALUE_1, p2.get()); + + p1.set(VALUE_1); + p2.set(VALUE_2); + assertEquals(VALUE_1, p1.get()); + assertEquals(VALUE_2, p2.get()); + } + + @Test + public void testToString() { + final StringProperty v0 = new StringPropertyStub(NO_BEAN, NO_NAME_1); + assertEquals("StringProperty [value: " + DEFAULT + "]", v0.toString()); + + final StringProperty v1 = new StringPropertyStub(NO_BEAN, NO_NAME_2); + assertEquals("StringProperty [value: " + DEFAULT + "]", v1.toString()); + + final Object bean = new Object(); + final String name = "My name"; + final StringProperty v2 = new StringPropertyStub(bean, name); + assertEquals("StringProperty [bean: " + bean.toString() + ", name: My name, value: " + DEFAULT + "]", v2.toString()); + v2.set(VALUE_1); + assertEquals("StringProperty [bean: " + bean.toString() + ", name: My name, value: " + VALUE_1 + "]", v2.toString()); + + final StringProperty v3 = new StringPropertyStub(bean, NO_NAME_1); + assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v3.toString()); + v3.set(VALUE_1); + assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v3.toString()); + + final StringProperty v4 = new StringPropertyStub(bean, NO_NAME_2); + assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + DEFAULT + "]", v4.toString()); + v4.set(VALUE_1); + assertEquals("StringProperty [bean: " + bean.toString() + ", value: " + VALUE_1 + "]", v4.toString()); + + final StringProperty v5 = new StringPropertyStub(NO_BEAN, name); + assertEquals("StringProperty [name: My name, value: " + DEFAULT + "]", v5.toString()); + v5.set(VALUE_1); + assertEquals("StringProperty [name: My name, value: " + VALUE_1 + "]", v5.toString()); + } + + private class StringPropertyStub extends StringProperty { + + private final Object bean; + private final String name; + private String value; + + private StringPropertyStub(Object bean, String name) { + this.bean = bean; + this.name = name; + } + + @Override + public Object getBean() { + return bean; + } + + @Override + public String getName() { + return name; + } + + @Override + public String get() { + return value; + } + + @Override + public void set(String value) { + this.value = value; + } + + @Override + public void bind(ObservableValue observable) { + fail("Not in use"); + } + + @Override + public void unbind() { + fail("Not in use"); + } + + @Override + public boolean isBound() { + fail("Not in use"); + return false; + } + + @Override + public void addListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(ChangeListener listener) { + fail("Not in use"); + } + + @Override + public void addListener(InvalidationListener listener) { + fail("Not in use"); + } + + @Override + public void removeListener(InvalidationListener listener) { + fail("Not in use"); + } + + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanBooleanPropertyTest.java 2015-08-31 10:24:01.197217094 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleBooleanProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanBooleanPropertyBuilder; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanBooleanPropertyTest extends JavaBeanPropertyTestBase { + + private final static Boolean[] VALUES = new Boolean[] {true, false}; + + @Override + protected BeanStub createBean(Boolean initialValue) { + return new BooleanPOJO(initialValue); + } + + @Override + protected void check(Boolean actual, Boolean expected) { + assertEquals(actual, expected); + } + + @Override + protected Boolean getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(Boolean value) { + return new SimpleBooleanProperty(value); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanBooleanPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class BooleanPOJO extends BeanStub { + private Boolean x; + private boolean failureMode; + + public BooleanPOJO(Boolean x) { + this.x = x; + } + + public Boolean getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(Boolean x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public Boolean getValue() { + return getX(); + } + + @Override + public void setValue(Boolean value) throws PropertyVetoException { + setX(value); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanBooleanProperty_prim_Test.java 2015-08-31 10:24:01.781217088 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleBooleanProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanBooleanPropertyBuilder; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanBooleanProperty_prim_Test extends JavaBeanPropertyTestBase { + + private final static Boolean[] VALUES = new Boolean[] {true, false}; + + @Override + protected BeanStub createBean(Boolean initialValue) { + return new BooleanPOJO(initialValue); + } + + @Override + protected void check(Boolean actual, Boolean expected) { + assertEquals(actual, expected); + } + + @Override + protected Boolean getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(Boolean value) { + return new SimpleBooleanProperty(value); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanBooleanPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class BooleanPOJO extends BeanStub { + private boolean x; + private boolean failureMode; + + public BooleanPOJO(boolean x) { + this.x = x; + } + + public boolean isX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(boolean x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public Boolean getValue() { + return isX(); + } + + @Override + public void setValue(Boolean value) throws PropertyVetoException { + setX(value); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanDoublePropertyTest.java 2015-08-31 10:24:02.629217078 -0400 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleDoubleProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanDoublePropertyBuilder; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanDoublePropertyTest extends JavaBeanPropertyTestBase { + + private static final double EPSILON = 1e-12; + + private static final double[] VALUES = new double[] {Math.PI, -Math.E}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new DoublePOJO(initialValue.doubleValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.doubleValue(), expected.doubleValue(), EPSILON); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(Number value) { + return new SimpleDoubleProperty(value.doubleValue()); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanDoublePropertyBuilder.create().bean(bean).name("x").build(); + } + + public class DoublePOJO extends BeanStub { + private Double x; + private boolean failureMode; + + public DoublePOJO(Double x) { + this.x = x; + } + + public Double getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(Double x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public Double getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + setX(value.doubleValue()); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanDoubleProperty_prim_Test.java 2015-08-31 10:24:03.301217071 -0400 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleDoubleProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanDoublePropertyBuilder; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanDoubleProperty_prim_Test extends JavaBeanPropertyTestBase { + + private static final double EPSILON = 1e-12; + + private static final double[] VALUES = new double[] {Math.PI, -Math.E}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new DoublePOJO(initialValue.doubleValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.doubleValue(), expected.doubleValue(), EPSILON); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(Number value) { + return new SimpleDoubleProperty(value.doubleValue()); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanDoublePropertyBuilder.create().bean(bean).name("x").build(); + } + + public class DoublePOJO extends BeanStub { + private double x; + private boolean failureMode; + + public DoublePOJO(double x) { + this.x = x; + } + + public double getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(double x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public Double getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + setX(value.doubleValue()); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanFloatPropertyBuilderaTest.java 2015-08-31 10:24:03.941217064 -0400 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleFloatProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanFloatPropertyBuilder; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanFloatPropertyBuilderaTest extends JavaBeanPropertyTestBase { + + private static final float EPSILON = 1e-6f; + + private static final float[] VALUES = new float[] {(float)Math.PI, (float)-Math.E}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new FloatPOJO(initialValue.floatValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.floatValue(), expected.floatValue(), EPSILON); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(Number value) { + return new SimpleFloatProperty(value.floatValue()); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanFloatPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class FloatPOJO extends BeanStub { + private Float x; + private boolean failureMode; + + public FloatPOJO(Float x) { + this.x = x; + } + + public Float getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(Float x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public Float getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + setX(value.floatValue()); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanFloatProperty_prim_Test.java 2015-08-31 10:24:04.533217057 -0400 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleFloatProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanFloatPropertyBuilder; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanFloatProperty_prim_Test extends JavaBeanPropertyTestBase { + + private static final float EPSILON = 1e-6f; + + private static final float[] VALUES = new float[] {(float)Math.PI, (float)-Math.E}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new FloatPOJO(initialValue.floatValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.floatValue(), expected.floatValue(), EPSILON); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(Number value) { + return new SimpleFloatProperty(value.floatValue()); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanFloatPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class FloatPOJO extends BeanStub { + private float x; + private boolean failureMode; + + public FloatPOJO(float x) { + this.x = x; + } + + public float getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(float x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public Float getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + setX(value.floatValue()); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanIntegerPropertyTest.java 2015-08-31 10:24:05.121217050 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleIntegerProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanIntegerPropertyBuilder; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanIntegerPropertyTest extends JavaBeanPropertyTestBase { + + private static final int[] VALUES = new int[] {Integer.MAX_VALUE, Integer.MIN_VALUE}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new IntegerPOJO(initialValue.intValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.intValue(), expected.intValue()); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(Number value) { + return new SimpleIntegerProperty(value.intValue()); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanIntegerPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class IntegerPOJO extends BeanStub { + private Integer x; + private boolean failureMode; + + public IntegerPOJO(Integer x) { + this.x = x; + } + + public Integer getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(Integer x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public Integer getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + setX(value.intValue()); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanIntegerProperty_prim_Test.java 2015-08-31 10:24:05.921217041 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleIntegerProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanIntegerPropertyBuilder; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanIntegerProperty_prim_Test extends JavaBeanPropertyTestBase { + + private static final int[] VALUES = new int[] {Integer.MAX_VALUE, Integer.MIN_VALUE}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new IntegerPOJO(initialValue.intValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.intValue(), expected.intValue()); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(Number value) { + return new SimpleIntegerProperty(value.intValue()); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanIntegerPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class IntegerPOJO extends BeanStub { + private int x; + private boolean failureMode; + + public IntegerPOJO(int x) { + this.x = x; + } + + public int getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(int x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public Integer getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + setX(value.intValue()); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanLongPropertyTest.java 2015-08-31 10:24:06.513217035 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleLongProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanLongPropertyBuilder; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanLongPropertyTest extends JavaBeanPropertyTestBase { + + private static final long[] VALUES = new long[] {Long.MAX_VALUE, Long.MIN_VALUE}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new LongPOJO(initialValue.longValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.longValue(), expected.longValue()); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(Number value) { + return new SimpleLongProperty(value.longValue()); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanLongPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class LongPOJO extends BeanStub { + private Long x; + private boolean failureMode; + + public LongPOJO(Long x) { + this.x = x; + } + + public Long getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(Long x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public Long getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + setX(value.longValue()); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanLongProperty_prim_Test.java 2015-08-31 10:24:07.249217026 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleLongProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanLongPropertyBuilder; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanLongProperty_prim_Test extends JavaBeanPropertyTestBase { + + private static final long[] VALUES = new long[] {Long.MAX_VALUE, Long.MIN_VALUE}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new LongPOJO(initialValue.longValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.longValue(), expected.longValue()); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(Number value) { + return new SimpleLongProperty(value.longValue()); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanLongPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class LongPOJO extends BeanStub { + private long x; + private boolean failureMode; + + public LongPOJO(long x) { + this.x = x; + } + + public long getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(long x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public Long getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + setX(value.longValue()); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanObjectPropertyTest.java 2015-08-31 10:24:07.913217019 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleObjectProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanObjectPropertyBuilder; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanObjectPropertyTest extends JavaBeanPropertyTestBase { + + private final static Object[] VALUES = new Object[] {new Object(), new Object()}; + + @Override + protected BeanStub createBean(Object initialValue) { + return new ObjectPOJO(initialValue); + } + + @Override + protected void check(Object actual, Object expected) { + assertEquals(actual, expected); + } + + @Override + protected Object getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(Object value) { + return new SimpleObjectProperty(value); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanObjectPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class ObjectPOJO extends BeanStub { + private Object x; + private boolean failureMode; + + public ObjectPOJO(Object x) { + this.x = x; + } + + public Object getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(Object x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public Object getValue() { + return getX(); + } + + @Override + public void setValue(Object value) throws PropertyVetoException { + setX(value); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanPropertyTestBase.java 2015-08-31 10:24:08.645217011 -0400 @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.Property; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import org.junit.Before; +import org.junit.Test; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; +import java.beans.VetoableChangeListener; +import java.lang.reflect.UndeclaredThrowableException; +import javafx.beans.property.adapter.JavaBeanProperty; + +import static org.junit.Assert.*; + +/** +*/ +public abstract class JavaBeanPropertyTestBase { + private BeanStub bean; + private JavaBeanProperty property; + + protected abstract BeanStub createBean(T value); + protected abstract void check(T actual, T expected); + protected abstract T getValue(int index); + protected abstract Property createObservable(T value); + protected abstract JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException; + + @Before + public void setUp() { + this.bean = createBean(getValue(0)); + try { + this.property = extractProperty(bean); + } catch (NoSuchMethodException e) { + fail(); + } + } + + @Test(expected = NullPointerException.class) + public void testSetup_WithNull() { + try { + this.property = extractProperty(null); + } catch (NoSuchMethodException e) { + fail(); + } + } + + @Test + public void testContext() { + assertEquals("x", property.getName()); + assertEquals(bean, property.getBean()); + } + + @Test + public void testGetAndSet() { + check(property.getValue(), getValue(0)); + + try { + bean.setValue(getValue(1)); + assertEquals(property.getValue(), getValue(1)); + } catch (PropertyVetoException e) { + fail(); + } + + property.setValue(getValue(0)); + assertEquals(property.getValue(), getValue(0)); + assertEquals(bean.getValue(), getValue(0)); + } + + @Test(expected = UndeclaredThrowableException.class) + public void testGet_Exception() { + bean.setFailureMode(true); + property.getValue(); + } + + @Test(expected = UndeclaredThrowableException.class) + public void testSet_Exception() { + bean.setFailureMode(true); + property.setValue(getValue(1)); + } + + @Test(expected = RuntimeException.class) + public void testSet_Bound() { + final Property observable = createObservable(getValue(1)); + property.bind(observable); + property.setValue(getValue(0)); + } + + @Test + public void testInvalidationListener() { + final BooleanProperty fired = new SimpleBooleanProperty(false); + final InvalidationListener listener = observable -> { + fired.set(true); + }; + + property.addListener(listener); + fired.set(false); + property.setValue(getValue(1)); + assertTrue(fired.get()); + + property.removeListener(listener); + fired.set(false); + property.setValue(getValue(0)); + assertFalse(fired.get()); + } + + @Test + public void testChangeListener() { + final BooleanProperty fired = new SimpleBooleanProperty(false); + final ChangeListener listener = (observable, oldValue, newValue) -> { + fired.set(true); + }; + + property.addListener(listener); + fired.set(false); + property.setValue(getValue(1)); + assertTrue(fired.get()); + + property.removeListener(listener); + fired.set(false); + property.setValue(getValue(0)); + assertFalse(fired.get()); + } + + @Test + public void testDispose() { + assertTrue(bean.hasListeners()); + property.dispose(); + assertFalse(bean.hasListeners()); + } + + @Test + public void testBinding() { + assertFalse(property.isBound()); + + final Property observable1 = createObservable(getValue(1)); + property.bind(observable1); + + assertTrue(property.isBound()); + check(property.getValue(), getValue(1)); + check(bean.getValue(), getValue(1)); + + observable1.setValue(getValue(0)); + check(property.getValue(), getValue(0)); + check(bean.getValue(), getValue(0)); + + // bind again - should not have any effect + property.bind(observable1); + assertTrue(property.isBound()); + + // bind to another observable + final Property observable2 = createObservable(getValue(1)); + property.bind(observable2); + assertTrue(property.isBound()); + check(property.getValue(), getValue(1)); + check(bean.getValue(), getValue(1)); + + observable2.setValue(getValue(0)); + check(property.getValue(), getValue(0)); + check(bean.getValue(), getValue(0)); + + observable1.setValue(getValue(1)); + check(property.getValue(), getValue(0)); + check(bean.getValue(), getValue(0)); + + // unbind + property.unbind(); + assertFalse(property.isBound()); + observable2.setValue(getValue(1)); + check(property.getValue(), getValue(0)); + check(bean.getValue(), getValue(0)); + + // unbind again - should not have any effect + property.unbind(); + assertFalse(property.isBound()); + } + + @Test(expected = NullPointerException.class) + public void testBindWithNull() { + property.bind(null); + } + + public static abstract class BeanStub { + private int listenerCount; + + public abstract U getValue(); + public abstract void setValue(U value) throws PropertyVetoException; + public abstract void setFailureMode(boolean failureMode); + + private boolean hasListeners() { + return listenerCount > 0; + } + + public void addXListener(PropertyChangeListener listener) { + listenerCount++; + } + + public void removeXListener(PropertyChangeListener listener) { + listenerCount = Math.max(0, listenerCount-1); + } + + public void addXListener(VetoableChangeListener listener) { + listenerCount++; + } + + public void removeXListener(VetoableChangeListener listener) { + listenerCount = Math.max(0, listenerCount-1); + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/JavaBeanStringPropertyTest.java 2015-08-31 10:24:09.305217003 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.property.Property; +import javafx.beans.property.SimpleStringProperty; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.JavaBeanProperty; +import javafx.beans.property.adapter.JavaBeanStringPropertyBuilder; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class JavaBeanStringPropertyTest extends JavaBeanPropertyTestBase { + + private final static String[] VALUES = new String[] {"Hello World", "JavaFX is cool"}; + + @Override + protected BeanStub createBean(String initialValue) { + return new StringPOJO(initialValue); + } + + @Override + protected void check(String actual, String expected) { + assertEquals(actual, expected); + } + + @Override + protected String getValue(int index) { + return VALUES[index]; + } + + @Override + protected Property createObservable(String value) { + return new SimpleStringProperty(value); + } + + @Override + protected JavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return JavaBeanStringPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class StringPOJO extends BeanStub { + private String x; + private boolean failureMode; + + public StringPOJO(String x) { + this.x = x; + } + + public String getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + public void setX(String x) { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + this.x = x; + } + } + + @Override + public String getValue() { + return getX(); + } + + @Override + public void setValue(String value) throws PropertyVetoException { + setX(value); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanBooleanPropertyTest.java 2015-08-31 10:24:09.981216996 -0400 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanBooleanPropertyBuilder; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanBooleanPropertyTest extends ReadOnlyJavaBeanPropertyTestBase { + + private final static Boolean[] VALUES = new Boolean[] {true, false}; + + @Override + protected BeanStub createBean(Boolean initialValue) { + return new BooleanPOJO(initialValue); + } + + @Override + protected void check(Boolean actual, Boolean expected) { + assertEquals(actual, expected); + } + + @Override + protected Boolean getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanBooleanPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class BooleanPOJO extends BeanStub { + private Boolean x; + private boolean failureMode; + + public BooleanPOJO(Boolean x) { + this.x = x; + } + + public Boolean getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public Boolean getValue() { + return getX(); + } + + @Override + public void setValue(Boolean value) throws PropertyVetoException { + this.x = value; + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanBooleanProperty_prim_Test.java 2015-08-31 10:24:10.653216988 -0400 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanBooleanPropertyBuilder; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanBooleanProperty_prim_Test extends ReadOnlyJavaBeanPropertyTestBase { + + private final static Boolean[] VALUES = new Boolean[] {true, false}; + + @Override + protected BeanStub createBean(Boolean initialValue) { + return new BooleanPOJO(initialValue); + } + + @Override + protected void check(Boolean actual, Boolean expected) { + assertEquals(actual, expected); + } + + @Override + protected Boolean getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanBooleanPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class BooleanPOJO extends BeanStub { + private boolean x; + private boolean failureMode; + + public BooleanPOJO(boolean x) { + this.x = x; + } + + public boolean isX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public Boolean getValue() { + return isX(); + } + + @Override + public void setValue(Boolean value) throws PropertyVetoException { + this.x = value; + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanDoublePropertyTest.java 2015-08-31 10:24:11.373216980 -0400 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanDoublePropertyBuilder; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanDoublePropertyTest extends ReadOnlyJavaBeanPropertyTestBase { + + private static final double EPSILON = 1e-12; + + private final static Double[] VALUES = new Double[] {Math.PI, -Math.E}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new DoublePOJO(initialValue.doubleValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.doubleValue(), expected.doubleValue(), EPSILON); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanDoublePropertyBuilder.create().bean(bean).name("x").build(); + } + + public class DoublePOJO extends BeanStub { + private Double x; + private boolean failureMode; + + public DoublePOJO(Double x) { + this.x = x; + } + + public Double getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public Double getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + this.x = value.doubleValue(); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanDoubleProperty_prim_Test.java 2015-08-31 10:24:11.957216973 -0400 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanDoublePropertyBuilder; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanDoubleProperty_prim_Test extends ReadOnlyJavaBeanPropertyTestBase { + + private static final double EPSILON = 1e-12; + + private final static Double[] VALUES = new Double[] {Math.PI, -Math.E}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new DoublePOJO(initialValue.doubleValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.doubleValue(), expected.doubleValue(), EPSILON); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanDoublePropertyBuilder.create().bean(bean).name("x").build(); + } + + public class DoublePOJO extends BeanStub { + private double x; + private boolean failureMode; + + public DoublePOJO(double x) { + this.x = x; + } + + public double getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public Double getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + this.x = value.doubleValue(); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanFloatPropertyTest.java 2015-08-31 10:24:12.765216964 -0400 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanFloatPropertyBuilder; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanFloatPropertyTest extends ReadOnlyJavaBeanPropertyTestBase { + + private static final float EPSILON = 1e-6f; + + private final static Float[] VALUES = new Float[] {(float)Math.PI, (float)-Math.E}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new FloatPOJO(initialValue.floatValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.floatValue(), expected.floatValue(), EPSILON); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanFloatPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class FloatPOJO extends BeanStub { + private Float x; + private boolean failureMode; + + public FloatPOJO(Float x) { + this.x = x; + } + + public Float getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public Float getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + this.x = value.floatValue(); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanFloatProperty_prim_Test.java 2015-08-31 10:24:13.625216955 -0400 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanFloatPropertyBuilder; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanFloatProperty_prim_Test extends ReadOnlyJavaBeanPropertyTestBase { + + private static final float EPSILON = 1e-6f; + + private final static Float[] VALUES = new Float[] {(float)Math.PI, (float)-Math.E}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new FloatPOJO(initialValue.floatValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.floatValue(), expected.floatValue(), EPSILON); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanFloatPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class FloatPOJO extends BeanStub { + private float x; + private boolean failureMode; + + public FloatPOJO(float x) { + this.x = x; + } + + public float getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public Float getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + this.x = value.floatValue(); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanIntegerPropertyTest.java 2015-08-31 10:24:14.477216945 -0400 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanIntegerPropertyBuilder; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanIntegerPropertyTest extends ReadOnlyJavaBeanPropertyTestBase { + + private final static Integer[] VALUES = new Integer[] {Integer.MIN_VALUE, Integer.MAX_VALUE}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new IntegerPOJO(initialValue.intValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.intValue(), expected.intValue()); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanIntegerPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class IntegerPOJO extends BeanStub { + private Integer x; + private boolean failureMode; + + public IntegerPOJO(Integer x) { + this.x = x; + } + + public Integer getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public Integer getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + this.x = value.intValue(); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanIntegerProperty_prim_Test.java 2015-08-31 10:24:15.149216938 -0400 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanIntegerPropertyBuilder; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanIntegerProperty_prim_Test extends ReadOnlyJavaBeanPropertyTestBase { + + private final static Integer[] VALUES = new Integer[] {Integer.MIN_VALUE, Integer.MAX_VALUE}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new IntegerPOJO(initialValue.intValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.intValue(), expected.intValue()); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanIntegerPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class IntegerPOJO extends BeanStub { + private int x; + private boolean failureMode; + + public IntegerPOJO(int x) { + this.x = x; + } + + public int getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public Integer getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + this.x = value.intValue(); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanLongPropertyTest.java 2015-08-31 10:24:15.737216931 -0400 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanLongPropertyBuilder; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanLongPropertyTest extends ReadOnlyJavaBeanPropertyTestBase { + + private final static Long[] VALUES = new Long[] {Long.MIN_VALUE, Long.MAX_VALUE}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new LongPOJO(initialValue.longValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.longValue(), expected.longValue()); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanLongPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class LongPOJO extends BeanStub { + private Long x; + private boolean failureMode; + + public LongPOJO(Long x) { + this.x = x; + } + + public Long getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public Long getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + this.x = value.longValue(); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanLongProperty_prim_Test.java 2015-08-31 10:24:16.325216924 -0400 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanLongPropertyBuilder; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanLongProperty_prim_Test extends ReadOnlyJavaBeanPropertyTestBase { + + private final static Long[] VALUES = new Long[] {Long.MIN_VALUE, Long.MAX_VALUE}; + + @Override + protected BeanStub createBean(Number initialValue) { + return new LongPOJO(initialValue.longValue()); + } + + @Override + protected void check(Number actual, Number expected) { + assertEquals(actual.longValue(), expected.longValue()); + } + + @Override + protected Number getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanLongPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class LongPOJO extends BeanStub { + private long x; + private boolean failureMode; + + public LongPOJO(long x) { + this.x = x; + } + + public long getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public Long getValue() { + return getX(); + } + + @Override + public void setValue(Number value) throws PropertyVetoException { + this.x = value.longValue(); + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanObjectPropertyTest.java 2015-08-31 10:24:17.125216915 -0400 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanObjectPropertyBuilder; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanObjectPropertyTest extends ReadOnlyJavaBeanPropertyTestBase { + + private final static Object[] VALUES = new Object[] {new Object(), new Object()}; + + @Override + protected BeanStub createBean(Object initialValue) { + return new ObjectPOJO(initialValue); + } + + @Override + protected void check(Object actual, Object expected) { + assertEquals(actual, expected); + } + + @Override + protected Object getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanObjectPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class ObjectPOJO extends BeanStub { + private Object x; + private boolean failureMode; + + public ObjectPOJO(Object x) { + this.x = x; + } + + public Object getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public Object getValue() { + return getX(); + } + + @Override + public void setValue(Object value) throws PropertyVetoException { + this.x = value; + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanPropertyBuilder_General_Test.java 2015-08-31 10:24:17.781216908 -0400 @@ -0,0 +1,649 @@ +package test.javafx.beans.property.adapter; + +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +//package javafx.beans.property.adapter; +// +//import javafx.beans.InvalidationListener; +//import javafx.beans.Observable; +//import javafx.beans.property.BooleanProperty; +//import javafx.beans.property.ReadOnlyObjectProperty; +//import javafx.beans.property.SimpleBooleanProperty; +//import javafx.beans.value.ChangeListener; +//import javafx.beans.value.ObservableValue; +//import org.junit.Test; +// +//import java.beans.*; +//import java.lang.reflect.Method; +// +//import static org.junit.Assert.*; +// +///** +//*/ +//public class ReadOnlyJavaBeanPropertyBuilder_General_Test { +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNameIsNull() { +// try { +// new ReadOnlyJavaBeanPropertyBuilder(null, POJOBean.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void testSetup_WithNameIsEmpty() { +// try { +// new ReadOnlyJavaBeanPropertyBuilder("", POJOBean.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithBeanClassIsNull() { +// try { +// new ReadOnlyJavaBeanPropertyBuilder("x", null); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// } +// +// @Test +// public void testSetup_WithNonStandardNames() { +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", POJOBeanWithNonStandardNames.class, "readX"); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// final Object initialValue = new Object(); +// final Object secondValue = new Object(); +// final POJOBeanWithNonStandardNames bean = new POJOBeanWithNonStandardNames(initialValue); +// final ReadOnlyObjectProperty property = builder.createObjectProperty(bean); +// assertEquals(initialValue, property.get()); +// bean.updateX(secondValue); +// assertEquals(secondValue, bean.readX()); +// assertEquals(secondValue, property.get()); +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardNames_WithNameIsNull() { +// try { +// new ReadOnlyJavaBeanPropertyBuilder(null, POJOBeanWithNonStandardNames.class, "readX"); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardNames_WithBeanClassIsNull() { +// try { +// new ReadOnlyJavaBeanPropertyBuilder("x", null, "readX"); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardNames_WithGetterNameIsNull() { +// try { +// new ReadOnlyJavaBeanPropertyBuilder("x", POJOBeanWithNonStandardNames.class, (String)null); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void testSetup_WithNonStandardNames_WithNameIsEmpty() { +// try { +// new ReadOnlyJavaBeanPropertyBuilder("", POJOBeanWithNonStandardNames.class, "readX"); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void testSetup_WithNonStandardNames_WithGetterNameIsEmpty() { +// try { +// new ReadOnlyJavaBeanPropertyBuilder("x", POJOBeanWithNonStandardNames.class, ""); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// } +// +// @Test +// public void testSetup_WithNonStandardAccessors() { +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", POJOBeanWithNonStandardNames.class, getter); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// final Object initialValue = new Object(); +// final Object secondValue = new Object(); +// final POJOBeanWithNonStandardNames bean = new POJOBeanWithNonStandardNames(initialValue); +// final ReadOnlyObjectProperty property = builder.createObjectProperty(bean); +// assertEquals(initialValue, property.get()); +// bean.updateX(secondValue); +// assertEquals(secondValue, bean.readX()); +// assertEquals(secondValue, property.get()); +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardAccessors_WithNameIsNull() { +// try { +// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +// new ReadOnlyJavaBeanPropertyBuilder(null, POJOBeanWithNonStandardNames.class, getter); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardAccessors_WithBeanClassIsNull() { +// try { +// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +// new ReadOnlyJavaBeanPropertyBuilder("x", null, getter); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// } +// +// @Test(expected = NullPointerException.class) +// public void testSetup_WithNonStandardAccessors_WithGetterIsNull() { +// new ReadOnlyJavaBeanPropertyBuilder("x", POJOBeanWithNonStandardNames.class, (Method)null); +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void testSetup_WithNonStandardAccessors_WithNameIsEmpty() { +// try { +// final Method getter = POJOBeanWithNonStandardNames.class.getMethod("readX"); +// new ReadOnlyJavaBeanPropertyBuilder("", POJOBeanWithNonStandardNames.class, getter); +// } catch (NoSuchMethodException e) { +// fail("Error in test code. Should not happen."); +// } +// } +// +// @Test(expected = IllegalArgumentException.class) +// public void testCreatePropertyWithWrongType_Boolean() { +// final POJOBean bean = new POJOBean(new Object()); +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", POJOBean.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// builder.createBooleanProperty(bean); +// } +// +// @Test +// public void testDisposal_GeneralAddRemove() { +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// final Object value0 = new Object(); +// final Object value1 = new Object(); +// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +// ReadOnlyJavaBeanObjectProperty property = builder.createObjectProperty(bean); +// +// // initial state +// assertEquals(value0, property.get()); +// assertTrue(bean.hasChangeListeners()); +// +// // dispose +// property.dispose(); +// try { +// bean.updateX(value1); +// } catch (PropertyVetoException e) { +// e.printStackTrace(); +// fail(); +// } +// assertFalse(bean.hasChangeListeners()); +// } +// +// @Test +// public void testDisposal_ParameterizedAddRemove() { +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// final Object value0 = new Object(); +// final Object value1 = new Object(); +// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); +// ReadOnlyJavaBeanObjectProperty property = builder.createObjectProperty(bean); +// +// // initial state +// assertEquals(value0, property.get()); +// assertTrue(bean.hasChangeListeners()); +// +// // dispose +// property.dispose(); +// try { +// bean.updateX(value1); +// } catch (PropertyVetoException e) { +// e.printStackTrace(); +// fail(); +// } +// assertFalse(bean.hasChangeListeners()); +// } +// +// @Test +// public void testDisposal_NamedAddRemove() { +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// final Object value0 = new Object(); +// final Object value1 = new Object(); +// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); +// ReadOnlyJavaBeanObjectProperty property = builder.createObjectProperty(bean); +// +// // initial state +// assertEquals(value0, property.get()); +// assertTrue(bean.hasChangeListeners()); +// +// // dispose +// property.dispose(); +// try { +// bean.updateX(value1); +// } catch (PropertyVetoException e) { +// e.printStackTrace(); +// fail(); +// } +// assertFalse(bean.hasChangeListeners()); +// } +// +// @Test +// public void testInvalidationListener_GeneralAddRemove() { +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// final BooleanProperty fired = new SimpleBooleanProperty(false); +// final InvalidationListener listener = new InvalidationListener() { +// @Override +// public void invalidated(Observable observable) { +// fired.set(true); +// } +// }; +// final Object value0 = new Object(); +// final Object value1 = new Object(); +// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +// final ReadOnlyObjectProperty property = builder.createObjectProperty(bean); +// +// property.addListener(listener); +// fired.set(false); +// try { +// bean.updateX(value1); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertTrue(fired.get()); +// +// property.removeListener(listener); +// fired.set(false); +// try { +// bean.updateX(value0); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertFalse(fired.get()); +// } +// +// @Test +// public void testChangeListener_GeneralAddRemove() { +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", BeanWithGeneralAddRemove.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// final BooleanProperty fired = new SimpleBooleanProperty(false); +// final ChangeListener listener = new ChangeListener() { +// @Override +// public void changed(ObservableValue observable, Object oldValue, Object newValue) { +// fired.set(true); +// } +// }; +// final Object value0 = new Object(); +// final Object value1 = new Object(); +// final BeanWithGeneralAddRemove bean = new BeanWithGeneralAddRemove(value0); +// final ReadOnlyObjectProperty property = builder.createObjectProperty(bean); +// +// property.addListener(listener); +// fired.set(false); +// try { +// bean.updateX(value1); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertTrue(fired.get()); +// +// property.removeListener(listener); +// fired.set(false); +// try { +// bean.updateX(value0); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertFalse(fired.get()); +// } +// +// @Test +// public void testInvalidationListener_ParameterizedAddRemove() { +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// final BooleanProperty fired = new SimpleBooleanProperty(false); +// final InvalidationListener listener = new InvalidationListener() { +// @Override +// public void invalidated(Observable observable) { +// fired.set(true); +// } +// }; +// final Object value0 = new Object(); +// final Object value1 = new Object(); +// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); +// final ReadOnlyObjectProperty property = builder.createObjectProperty(bean); +// +// property.addListener(listener); +// fired.set(false); +// try { +// bean.updateX(value1); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertTrue(fired.get()); +// +// property.removeListener(listener); +// fired.set(false); +// try { +// bean.updateX(value0); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertFalse(fired.get()); +// } +// +// @Test +// public void testChangeListener_ParameterizedAddRemove() { +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", BeanWithParameterizedAddRemove.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// final BooleanProperty fired = new SimpleBooleanProperty(false); +// final ChangeListener listener = new ChangeListener() { +// @Override +// public void changed(ObservableValue observable, Object oldValue, Object newValue) { +// fired.set(true); +// } +// }; +// final Object value0 = new Object(); +// final Object value1 = new Object(); +// final BeanWithParameterizedAddRemove bean = new BeanWithParameterizedAddRemove(value0); +// final ReadOnlyObjectProperty property = builder.createObjectProperty(bean); +// +// property.addListener(listener); +// fired.set(false); +// try { +// bean.updateX(value1); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertTrue(fired.get()); +// +// property.removeListener(listener); +// fired.set(false); +// try { +// bean.updateX(value0); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertFalse(fired.get()); +// } +// +// @Test +// public void testInvalidationListener_NamedAddRemove() { +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// final BooleanProperty fired = new SimpleBooleanProperty(false); +// final InvalidationListener listener = new InvalidationListener() { +// @Override +// public void invalidated(Observable observable) { +// fired.set(true); +// } +// }; +// final Object value0 = new Object(); +// final Object value1 = new Object(); +// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); +// final ReadOnlyObjectProperty property = builder.createObjectProperty(bean); +// +// property.addListener(listener); +// fired.set(false); +// try { +// bean.updateX(value1); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertTrue(fired.get()); +// +// property.removeListener(listener); +// fired.set(false); +// try { +// bean.updateX(value0); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertFalse(fired.get()); +// } +// +// @Test +// public void testChangeListener_NamedAddRemove() { +// ReadOnlyJavaBeanPropertyBuilder builder = null; +// try { +// builder = new ReadOnlyJavaBeanPropertyBuilder("x", BeanWithNamedAddRemove.class); +// } catch (NoSuchMethodException e) { +// e.printStackTrace(); +// fail(); +// } +// final BooleanProperty fired = new SimpleBooleanProperty(false); +// final ChangeListener listener = new ChangeListener() { +// @Override +// public void changed(ObservableValue observable, Object oldValue, Object newValue) { +// fired.set(true); +// } +// }; +// final Object value0 = new Object(); +// final Object value1 = new Object(); +// final BeanWithNamedAddRemove bean = new BeanWithNamedAddRemove(value0); +// final ReadOnlyObjectProperty property = builder.createObjectProperty(bean); +// +// property.addListener(listener); +// fired.set(false); +// try { +// bean.updateX(value1); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertTrue(fired.get()); +// +// property.removeListener(listener); +// fired.set(false); +// try { +// bean.updateX(value0); +// } catch (PropertyVetoException e) { +// fail(); +// } +// assertFalse(fired.get()); +// } +// +// public static class POJOBean { +// private Object x; +// +// public POJOBean(Object x) {this.x = x;} +// +// public Object getX() {return x;} +// } +// +// public static class POJOBeanWithNonStandardNames { +// private Object x; +// +// public POJOBeanWithNonStandardNames(Object x) {this.x = x;} +// +// public Object readX() {return x;} +// private void updateX(Object x) {this.x = x;} +// } +// +// public static class BeanWithGeneralAddRemove { +// private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); +// +// private Object x; +// private int changeListenerCount; +// +// public Object getX() {return x;} +// private void updateX(Object x) throws PropertyVetoException { +// final Object oldX = this.x; +// this.x = x; +// propertyChangeSupport.firePropertyChange("x", oldX, x); +// } +// +// public BeanWithGeneralAddRemove(Object x) {this.x = x;} +// +// public boolean hasChangeListeners() { +// return changeListenerCount > 0; +// } +// +// public void addPropertyChangeListener(PropertyChangeListener listener) { +// changeListenerCount++; +// propertyChangeSupport.addPropertyChangeListener(listener); +// } +// +// public void removePropertyChangeListener(PropertyChangeListener listener) { +// changeListenerCount = Math.max(0, changeListenerCount-1); +// propertyChangeSupport.removePropertyChangeListener(listener); +// } +// } +// +// public static class BeanWithParameterizedAddRemove { +// private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); +// +// private Object x; +// private int changeListenerCount; +// +// public Object getX() {return x;} +// private void updateX(Object x) throws PropertyVetoException { +// final Object oldX = this.x; +// this.x = x; +// propertyChangeSupport.firePropertyChange("x", oldX, x); +// } +// +// public BeanWithParameterizedAddRemove(Object x) {this.x = x;} +// +// public boolean hasChangeListeners() { +// return changeListenerCount > 0; +// } +// +// public void addPropertyChangeListener(String name, PropertyChangeListener listener) { +// changeListenerCount++; +// propertyChangeSupport.addPropertyChangeListener(name, listener); +// } +// +// public void removePropertyChangeListener(String name, PropertyChangeListener listener) { +// changeListenerCount = Math.max(0, changeListenerCount-1); +// propertyChangeSupport.removePropertyChangeListener(name, listener); +// } +// } +// +// public static class BeanWithNamedAddRemove { +// private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); +// +// private Object x; +// private int changeListenerCount; +// +// public Object getX() {return x;} +// private void updateX(Object x) throws PropertyVetoException { +// final Object oldX = this.x; +// this.x = x; +// propertyChangeSupport.firePropertyChange("x", oldX, x); +// } +// +// public BeanWithNamedAddRemove(Object x) {this.x = x;} +// +// public boolean hasChangeListeners() { +// return changeListenerCount > 0; +// } +// +// public void addXListener(PropertyChangeListener listener) { +// changeListenerCount++; +// propertyChangeSupport.addPropertyChangeListener("x", listener); +// } +// +// public void removeXListener(PropertyChangeListener listener) { +// changeListenerCount = Math.max(0, changeListenerCount-1); +// propertyChangeSupport.removePropertyChangeListener("x", listener); +// } +// +// } +// +//} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanPropertyTestBase.java 2015-08-31 10:24:18.453216900 -0400 @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import org.junit.Before; +import org.junit.Test; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; +import java.beans.VetoableChangeListener; +import java.lang.reflect.UndeclaredThrowableException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; + +import static org.junit.Assert.*; + +/** +*/ +public abstract class ReadOnlyJavaBeanPropertyTestBase { + private BeanStub bean; + private ReadOnlyJavaBeanProperty property; + + protected abstract BeanStub createBean(T value); + protected abstract void check(T actual, T expected); + protected abstract T getValue(int index); + protected abstract ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException; + + @Before + public void setUp() { + this.bean = createBean(getValue(0)); + try { + this.property = extractProperty(bean); + } catch (NoSuchMethodException e) { + fail(); + } + } + + @Test(expected = NullPointerException.class) + public void testSetup_WithNull() { + try { + this.property = extractProperty(null); + } catch (NoSuchMethodException e) { + fail(); + } + } + + @Test + public void testContext() { + assertEquals("x", property.getName()); + assertEquals(bean, property.getBean()); + } + + @Test + public void testGetAndSet() { + check(property.getValue(), getValue(0)); + + try { + bean.setValue(getValue(1)); + assertEquals(property.getValue(), getValue(1)); + } catch (PropertyVetoException e) { + fail(); + } + } + + @Test(expected = UndeclaredThrowableException.class) + public void testGet_Exception() { + bean.setFailureMode(true); + property.getValue(); + } + + @Test + public void testInvalidationListener() { + final BooleanProperty fired = new SimpleBooleanProperty(false); + final InvalidationListener listener = observable -> { + fired.set(true); + }; + + property.addListener(listener); + fired.set(false); + try { + bean.setValue(getValue(1)); + } catch (PropertyVetoException e) { + fail(); + } + property.fireValueChangedEvent(); + assertTrue(fired.get()); + + property.removeListener(listener); + fired.set(false); + try { + bean.setValue(getValue(0)); + } catch (PropertyVetoException e) { + fail(); + } + property.fireValueChangedEvent(); + assertFalse(fired.get()); + } + + @Test + public void testChangeListener() { + final BooleanProperty fired = new SimpleBooleanProperty(false); + final ChangeListener listener = (observable, oldValue, newValue) -> { + fired.set(true); + }; + + property.addListener(listener); + fired.set(false); + try { + bean.setValue(getValue(1)); + } catch (PropertyVetoException e) { + fail(); + } + property.fireValueChangedEvent(); + assertTrue(fired.get()); + + property.removeListener(listener); + fired.set(false); + try { + bean.setValue(getValue(0)); + } catch (PropertyVetoException e) { + fail(); + } + property.fireValueChangedEvent(); + assertFalse(fired.get()); + } + + @Test + public void testDispose() { + assertTrue(bean.hasListeners()); + property.dispose(); + assertFalse(bean.hasListeners()); + } + + public static abstract class BeanStub { + int listenerCount; + + public abstract U getValue(); + public abstract void setValue(U value) throws PropertyVetoException; + public abstract void setFailureMode(boolean failureMode); + + private boolean hasListeners() { + return listenerCount > 0; + } + + public void addXListener(PropertyChangeListener listener) { + listenerCount++; + } + + public void removeXListener(PropertyChangeListener listener) { + listenerCount = Math.max(0, listenerCount-1); + } + + public void addXListener(VetoableChangeListener listener) { + listenerCount++; + } + + public void removeXListener(VetoableChangeListener listener) { + listenerCount = Math.max(0, listenerCount-1); + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/property/adapter/ReadOnlyJavaBeanStringPropertyTest.java 2015-08-31 10:24:19.101216893 -0400 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.property.adapter; + +import java.beans.PropertyVetoException; +import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty; +import javafx.beans.property.adapter.ReadOnlyJavaBeanStringPropertyBuilder; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class ReadOnlyJavaBeanStringPropertyTest extends ReadOnlyJavaBeanPropertyTestBase { + + private final static String[] VALUES = new String[] {"Hello World", "JavaFX is cool"}; + + @Override + protected BeanStub createBean(String initialValue) { + return new StringPOJO(initialValue); + } + + @Override + protected void check(String actual, String expected) { + assertEquals(actual, expected); + } + + @Override + protected String getValue(int index) { + return VALUES[index]; + } + + @Override + protected ReadOnlyJavaBeanProperty extractProperty(Object bean) throws NoSuchMethodException { + return ReadOnlyJavaBeanStringPropertyBuilder.create().bean(bean).name("x").build(); + } + + public class StringPOJO extends BeanStub { + private String x; + private boolean failureMode; + + public StringPOJO(String x) { + this.x = x; + } + + public String getX() { + if (failureMode) { + throw new RuntimeException("FailureMode activated"); + } else { + return x; + } + } + + @Override + public String getValue() { + return getX(); + } + + @Override + public void setValue(String value) throws PropertyVetoException { + this.x = value; + } + + @Override + public void setFailureMode(boolean failureMode) { + this.failureMode = failureMode; + } + } +} --- old/modules/base/src/test/java/javafx/beans/value/ChangeListenerMock.java 2015-08-31 10:24:19.821216885 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.value; - -import static org.junit.Assert.assertEquals; - -public class ChangeListenerMock implements ChangeListener { - - private final static double EPSILON_DOUBLE = 1e-12; - private final static float EPSILON_FLOAT = 1e-6f; - - private final T undefined; - - private ObservableValue valueModel = null; - private T oldValue; - private T newValue; - private int counter = 0; - - public ChangeListenerMock(T undefined) { - this.undefined = undefined; - this.oldValue = undefined; - this.newValue = undefined; - } - - @Override public void changed(ObservableValue valueModel, T oldValue, T newValue) { - this.valueModel = valueModel; - this.oldValue = oldValue; - this.newValue = newValue; - counter++; - } - - public void reset() { - valueModel = null; - oldValue = undefined; - newValue = undefined; - counter = 0; - } - - public void check(ObservableValue valueModel, T oldValue, T newValue, int counter) { - assertEquals(valueModel, this.valueModel); - if ((oldValue instanceof Double) && (this.oldValue instanceof Double)) { - assertEquals((Double)oldValue, (Double)this.oldValue, EPSILON_DOUBLE); - } else if ((oldValue instanceof Float) && (this.oldValue instanceof Float)) { - assertEquals((Float)oldValue, (Float)this.oldValue, EPSILON_FLOAT); - } else { - assertEquals(oldValue, this.oldValue); - } - if ((newValue instanceof Double) && (this.newValue instanceof Double)) { - assertEquals((Double)newValue, (Double)this.newValue, EPSILON_DOUBLE); - } else if ((newValue instanceof Float) && (this.newValue instanceof Float)) { - assertEquals((Float)newValue, (Float)this.newValue, EPSILON_FLOAT); - } else { - assertEquals(newValue, this.newValue); - } - assertEquals(counter, this.counter); - reset(); - } - - public void check0() { - assertEquals(0, counter); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/value/ChangeListenerMock.java 2015-08-31 10:24:19.685216887 -0400 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.value; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import static org.junit.Assert.assertEquals; + +public class ChangeListenerMock implements ChangeListener { + + private final static double EPSILON_DOUBLE = 1e-12; + private final static float EPSILON_FLOAT = 1e-6f; + + private final T undefined; + + private ObservableValue valueModel = null; + private T oldValue; + private T newValue; + private int counter = 0; + + public ChangeListenerMock(T undefined) { + this.undefined = undefined; + this.oldValue = undefined; + this.newValue = undefined; + } + + @Override public void changed(ObservableValue valueModel, T oldValue, T newValue) { + this.valueModel = valueModel; + this.oldValue = oldValue; + this.newValue = newValue; + counter++; + } + + public void reset() { + valueModel = null; + oldValue = undefined; + newValue = undefined; + counter = 0; + } + + public void check(ObservableValue valueModel, T oldValue, T newValue, int counter) { + assertEquals(valueModel, this.valueModel); + if ((oldValue instanceof Double) && (this.oldValue instanceof Double)) { + assertEquals((Double)oldValue, (Double)this.oldValue, EPSILON_DOUBLE); + } else if ((oldValue instanceof Float) && (this.oldValue instanceof Float)) { + assertEquals((Float)oldValue, (Float)this.oldValue, EPSILON_FLOAT); + } else { + assertEquals(oldValue, this.oldValue); + } + if ((newValue instanceof Double) && (this.newValue instanceof Double)) { + assertEquals((Double)newValue, (Double)this.newValue, EPSILON_DOUBLE); + } else if ((newValue instanceof Float) && (this.newValue instanceof Float)) { + assertEquals((Float)newValue, (Float)this.newValue, EPSILON_FLOAT); + } else { + assertEquals(newValue, this.newValue); + } + assertEquals(counter, this.counter); + reset(); + } + + public void check0() { + assertEquals(0, counter); + } +} --- old/modules/base/src/test/java/javafx/beans/value/ObservableValueBaseTest.java 2015-08-31 10:24:20.513216877 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,212 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.value; - -import javafx.beans.InvalidationListener; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.Observable; - -import org.junit.Before; -import org.junit.Test; - -public class ObservableValueBaseTest { - - private static final Object UNDEFINED_VALUE = new Object(); - private static final Object V1 = new Object(); - private static final Object V2 = new Object(); - - private ObservableObjectValueStub valueModel; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - @Before - public void setUp() { - valueModel = new ObservableObjectValueStub(); - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED_VALUE); - } - - @Test - public void testInitialState() { - // no exceptions etc. - valueModel.fireValueChangedEvent(); - } - - @Test - public void testOneInvalidationListener() { - // adding one observer - valueModel.addListener(invalidationListener); - System.gc(); // making sure we did not not overdo weak references - valueModel.set(V1); - invalidationListener.check(valueModel, 1); - - // remove observer - valueModel.removeListener(invalidationListener); - valueModel.set(V2); - invalidationListener.check(null, 0); - - // remove observer again - valueModel.removeListener(invalidationListener); - valueModel.set(V1); - invalidationListener.check(null, 0); - } - - @Test - public void testOneChangeListener() { - // adding one observer - valueModel.addListener(changeListener); - System.gc(); // making sure we did not not overdo weak references - valueModel.set(V1); - changeListener.check(valueModel, null, V1, 1); - - // set same value again - valueModel.set(V1); - changeListener.check(null, UNDEFINED_VALUE, UNDEFINED_VALUE, 0); - - // set null - valueModel.set(null); - changeListener.check(valueModel, V1, null, 1); - valueModel.set(null); - changeListener.check(null, UNDEFINED_VALUE, UNDEFINED_VALUE, 0); - - // remove observer - valueModel.removeListener(changeListener); - valueModel.set(V2); - changeListener.check(null, UNDEFINED_VALUE, UNDEFINED_VALUE, 0); - - // remove observer again - valueModel.removeListener(changeListener); - valueModel.set(V1); - changeListener.check(null, UNDEFINED_VALUE, UNDEFINED_VALUE, 0); - } - - @Test - public void testTwoObservers() { - final InvalidationListenerMock observer2 = new InvalidationListenerMock(); - - // adding two observers - valueModel.addListener(invalidationListener); - valueModel.addListener(observer2); - System.gc(); // making sure we did not not overdo weak references - valueModel.fireValueChangedEvent(); - invalidationListener.check(valueModel, 1); - observer2.check(valueModel, 1); - - // remove first observer - invalidationListener.reset(); - observer2.reset(); - valueModel.removeListener(invalidationListener); - valueModel.fireValueChangedEvent(); - invalidationListener.check(null, 0); - observer2.check(valueModel, 1); - - // remove second observer - observer2.reset(); - valueModel.removeListener(observer2); - valueModel.fireValueChangedEvent(); - invalidationListener.check(null, 0); - observer2.check(null, 0); - - // remove observers in reverse order - observer2.reset(); - valueModel.removeListener(observer2); - valueModel.removeListener(invalidationListener); - valueModel.fireValueChangedEvent(); - invalidationListener.check(null, 0); - observer2.check(null, 0); - } - - @Test - public void testConcurrentAdd() { - final InvalidationListenerMock observer2 = new AddingListenerMock(); - valueModel.addListener(observer2); - - // fire event that adds a second observer - // Note: there is no assumption if observer that is being added is notified - valueModel.fireValueChangedEvent(); - observer2.check(valueModel, 1); - - // fire event again, this time both observers need to be notified - invalidationListener.reset(); - observer2.reset(); - valueModel.fireValueChangedEvent(); - invalidationListener.check(valueModel, 1); - observer2.check(valueModel, 1); - } - - @Test - public void testConcurrentRemove() { - final InvalidationListenerMock observer2 = new RemovingListenerMock(); - valueModel.addListener(observer2); - valueModel.addListener(invalidationListener); - - // fire event that removes one observer - // Note: there is no assumption if observer that is being removed is notified - valueModel.fireValueChangedEvent(); - observer2.check(valueModel, 1); - - // fire event again, this time only non-removed observer is notified - invalidationListener.reset(); - observer2.reset(); - valueModel.fireValueChangedEvent(); - invalidationListener.check(null, 0); - observer2.check(valueModel, 1); - } - - @Test(expected=NullPointerException.class) - public void testAddingNull_InvalidationListener() { - valueModel.addListener((InvalidationListener)null); - } - - @Test(expected=NullPointerException.class) - public void testAddingNull_ChangeListener() { - valueModel.addListener((ChangeListener)null); - } - - @Test(expected=NullPointerException.class) - public void testRemovingNull_InvalidationListener() { - valueModel.removeListener((InvalidationListener)null); - } - - @Test(expected=NullPointerException.class) - public void testRemovingNull_ChangeListener() { - valueModel.removeListener((ChangeListener)null); - } - - private class AddingListenerMock extends InvalidationListenerMock { - @Override public void invalidated(Observable valueModel) { - super.invalidated(valueModel); - valueModel.addListener(invalidationListener); - } - } - - private class RemovingListenerMock extends InvalidationListenerMock { - @Override public void invalidated(Observable valueModel) { - super.invalidated(valueModel); - valueModel.removeListener(invalidationListener); - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/value/ObservableValueBaseTest.java 2015-08-31 10:24:20.305216880 -0400 @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.value; + +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.InvalidationListener; +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.Observable; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableObjectValueStub; + +import org.junit.Before; +import org.junit.Test; + +public class ObservableValueBaseTest { + + private static final Object UNDEFINED_VALUE = new Object(); + private static final Object V1 = new Object(); + private static final Object V2 = new Object(); + + private ObservableObjectValueStub valueModel; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + @Before + public void setUp() { + valueModel = new ObservableObjectValueStub(); + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED_VALUE); + } + + @Test + public void testInitialState() { + // no exceptions etc. + valueModel.fireValueChangedEvent(); + } + + @Test + public void testOneInvalidationListener() { + // adding one observer + valueModel.addListener(invalidationListener); + System.gc(); // making sure we did not not overdo weak references + valueModel.set(V1); + invalidationListener.check(valueModel, 1); + + // remove observer + valueModel.removeListener(invalidationListener); + valueModel.set(V2); + invalidationListener.check(null, 0); + + // remove observer again + valueModel.removeListener(invalidationListener); + valueModel.set(V1); + invalidationListener.check(null, 0); + } + + @Test + public void testOneChangeListener() { + // adding one observer + valueModel.addListener(changeListener); + System.gc(); // making sure we did not not overdo weak references + valueModel.set(V1); + changeListener.check(valueModel, null, V1, 1); + + // set same value again + valueModel.set(V1); + changeListener.check(null, UNDEFINED_VALUE, UNDEFINED_VALUE, 0); + + // set null + valueModel.set(null); + changeListener.check(valueModel, V1, null, 1); + valueModel.set(null); + changeListener.check(null, UNDEFINED_VALUE, UNDEFINED_VALUE, 0); + + // remove observer + valueModel.removeListener(changeListener); + valueModel.set(V2); + changeListener.check(null, UNDEFINED_VALUE, UNDEFINED_VALUE, 0); + + // remove observer again + valueModel.removeListener(changeListener); + valueModel.set(V1); + changeListener.check(null, UNDEFINED_VALUE, UNDEFINED_VALUE, 0); + } + + @Test + public void testTwoObservers() { + final InvalidationListenerMock observer2 = new InvalidationListenerMock(); + + // adding two observers + valueModel.addListener(invalidationListener); + valueModel.addListener(observer2); + System.gc(); // making sure we did not not overdo weak references + valueModel.fireValueChangedEvent(); + invalidationListener.check(valueModel, 1); + observer2.check(valueModel, 1); + + // remove first observer + invalidationListener.reset(); + observer2.reset(); + valueModel.removeListener(invalidationListener); + valueModel.fireValueChangedEvent(); + invalidationListener.check(null, 0); + observer2.check(valueModel, 1); + + // remove second observer + observer2.reset(); + valueModel.removeListener(observer2); + valueModel.fireValueChangedEvent(); + invalidationListener.check(null, 0); + observer2.check(null, 0); + + // remove observers in reverse order + observer2.reset(); + valueModel.removeListener(observer2); + valueModel.removeListener(invalidationListener); + valueModel.fireValueChangedEvent(); + invalidationListener.check(null, 0); + observer2.check(null, 0); + } + + @Test + public void testConcurrentAdd() { + final InvalidationListenerMock observer2 = new AddingListenerMock(); + valueModel.addListener(observer2); + + // fire event that adds a second observer + // Note: there is no assumption if observer that is being added is notified + valueModel.fireValueChangedEvent(); + observer2.check(valueModel, 1); + + // fire event again, this time both observers need to be notified + invalidationListener.reset(); + observer2.reset(); + valueModel.fireValueChangedEvent(); + invalidationListener.check(valueModel, 1); + observer2.check(valueModel, 1); + } + + @Test + public void testConcurrentRemove() { + final InvalidationListenerMock observer2 = new RemovingListenerMock(); + valueModel.addListener(observer2); + valueModel.addListener(invalidationListener); + + // fire event that removes one observer + // Note: there is no assumption if observer that is being removed is notified + valueModel.fireValueChangedEvent(); + observer2.check(valueModel, 1); + + // fire event again, this time only non-removed observer is notified + invalidationListener.reset(); + observer2.reset(); + valueModel.fireValueChangedEvent(); + invalidationListener.check(null, 0); + observer2.check(valueModel, 1); + } + + @Test(expected=NullPointerException.class) + public void testAddingNull_InvalidationListener() { + valueModel.addListener((InvalidationListener)null); + } + + @Test(expected=NullPointerException.class) + public void testAddingNull_ChangeListener() { + valueModel.addListener((ChangeListener)null); + } + + @Test(expected=NullPointerException.class) + public void testRemovingNull_InvalidationListener() { + valueModel.removeListener((InvalidationListener)null); + } + + @Test(expected=NullPointerException.class) + public void testRemovingNull_ChangeListener() { + valueModel.removeListener((ChangeListener)null); + } + + private class AddingListenerMock extends InvalidationListenerMock { + @Override public void invalidated(Observable valueModel) { + super.invalidated(valueModel); + valueModel.addListener(invalidationListener); + } + } + + private class RemovingListenerMock extends InvalidationListenerMock { + @Override public void invalidated(Observable valueModel) { + super.invalidated(valueModel); + valueModel.removeListener(invalidationListener); + } + } +} --- old/modules/base/src/test/java/javafx/beans/value/WeakChangeListenerMock.java 2015-08-31 10:24:21.121216870 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.value; - -import javafx.beans.WeakListener; - -public class WeakChangeListenerMock implements ChangeListener, WeakListener { - @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { } - - @Override public boolean wasGarbageCollected() { - return true; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/value/WeakChangeListenerMock.java 2015-08-31 10:24:20.985216872 -0400 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.value; + +import javafx.beans.WeakListener; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; + +public class WeakChangeListenerMock implements ChangeListener, WeakListener { + @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { } + + @Override public boolean wasGarbageCollected() { + return true; + } +} --- old/modules/base/src/test/java/javafx/beans/value/WeakChangeListenerTest.java 2015-08-31 10:24:21.945216861 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.beans.value; - -import javafx.beans.InvalidationListener; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class WeakChangeListenerTest { - - @Test(expected=NullPointerException.class) - public void testConstructWithNull() { - new WeakChangeListener(null); - } - - @Test - public void testHandle() { - ChangeListenerMock listener = new ChangeListenerMock(new Object()); - final WeakChangeListener weakListener = new WeakChangeListener(listener); - final ObservableMock o = new ObservableMock(); - final Object obj1 = new Object(); - final Object obj2 = new Object(); - - // regular call - weakListener.changed(o, obj1, obj2); - listener.check(o, obj1, obj2, 1); - assertFalse(weakListener.wasGarbageCollected()); - - // GC-ed call - o.reset(); - listener = null; - System.gc(); - assertTrue(weakListener.wasGarbageCollected()); - weakListener.changed(o, obj2, obj1); - assertEquals(1, o.removeCounter); - } - - private static class ObservableMock implements ObservableValue { - private int removeCounter; - - private void reset() { - removeCounter = 0; - } - - @Override - public Object getValue() { - return null; - } - - @Override - public void addListener(InvalidationListener listener) { - // not used - } - - @Override - public void addListener(ChangeListener listener) { - // not used - } - - @Override - public void removeListener(InvalidationListener listener) { - // not used - } - - @Override - public void removeListener(ChangeListener listener) { - removeCounter++; - } - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/beans/value/WeakChangeListenerTest.java 2015-08-31 10:24:21.745216863 -0400 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.beans.value; + +import javafx.beans.InvalidationListener; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.WeakChangeListener; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class WeakChangeListenerTest { + + @Test(expected=NullPointerException.class) + public void testConstructWithNull() { + new WeakChangeListener(null); + } + + @Test + public void testHandle() { + ChangeListenerMock listener = new ChangeListenerMock(new Object()); + final WeakChangeListener weakListener = new WeakChangeListener(listener); + final ObservableMock o = new ObservableMock(); + final Object obj1 = new Object(); + final Object obj2 = new Object(); + + // regular call + weakListener.changed(o, obj1, obj2); + listener.check(o, obj1, obj2, 1); + assertFalse(weakListener.wasGarbageCollected()); + + // GC-ed call + o.reset(); + listener = null; + System.gc(); + assertTrue(weakListener.wasGarbageCollected()); + weakListener.changed(o, obj2, obj1); + assertEquals(1, o.removeCounter); + } + + private static class ObservableMock implements ObservableValue { + private int removeCounter; + + private void reset() { + removeCounter = 0; + } + + @Override + public Object getValue() { + return null; + } + + @Override + public void addListener(InvalidationListener listener) { + // not used + } + + @Override + public void addListener(ChangeListener listener) { + // not used + } + + @Override + public void removeListener(InvalidationListener listener) { + // not used + } + + @Override + public void removeListener(ChangeListener listener) { + removeCounter++; + } + + } + +} --- old/modules/base/src/test/java/javafx/binding/BindingToStringTest.java 2015-08-31 10:24:22.617216854 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - - -import javafx.beans.binding.*; -import javafx.beans.property.*; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BindingToStringTest { - - @Before - public void setUp() throws Exception { - } - - @Test - public void testBooleanToString() { - final boolean value1 = true; - final boolean value2 = false; - final BooleanProperty v = new SimpleBooleanProperty(value1); - final BooleanBinding binding = new BooleanBinding() { - {bind(v);} - @Override - protected boolean computeValue() { - return v.get(); - } - }; - - assertEquals("BooleanBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("BooleanBinding [value: "+value1+"]", binding.toString()); - v.set(value2); - assertEquals("BooleanBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("BooleanBinding [value: "+value2+"]", binding.toString()); - } - - @Test - public void testDoubleToString() { - final double value1 = Math.PI; - final double value2 = -Math.E; - final DoubleProperty v = new SimpleDoubleProperty(value1); - final DoubleBinding binding = new DoubleBinding() { - {bind(v);} - @Override - protected double computeValue() { - return v.get(); - } - }; - - assertEquals("DoubleBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("DoubleBinding [value: "+value1+"]", binding.toString()); - v.set(value2); - assertEquals("DoubleBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("DoubleBinding [value: "+value2+"]", binding.toString()); - } - - @Test - public void testFloatToString() { - final float value1 = (float)Math.PI; - final float value2 = (float)-Math.E; - final FloatProperty v = new SimpleFloatProperty(value1); - final FloatBinding binding = new FloatBinding() { - {bind(v);} - @Override - protected float computeValue() { - return v.get(); - } - }; - - assertEquals("FloatBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("FloatBinding [value: "+value1+"]", binding.toString()); - v.set(value2); - assertEquals("FloatBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("FloatBinding [value: "+value2+"]", binding.toString()); - } - - @Test - public void testIntegerToString() { - final int value1 = 42; - final int value2 = 987654321; - final IntegerProperty v = new SimpleIntegerProperty(value1); - final IntegerBinding binding = new IntegerBinding() { - {bind(v);} - @Override - protected int computeValue() { - return v.get(); - } - }; - - assertEquals("IntegerBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("IntegerBinding [value: "+value1+"]", binding.toString()); - v.set(value2); - assertEquals("IntegerBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("IntegerBinding [value: "+value2+"]", binding.toString()); - } - - @Test - public void testLongToString() { - final long value1 = -987654321234567890L; - final long value2 = 1234567890987654321L; - final LongProperty v = new SimpleLongProperty(value1); - final LongBinding binding = new LongBinding() { - {bind(v);} - @Override - protected long computeValue() { - return v.get(); - } - }; - - assertEquals("LongBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("LongBinding [value: "+value1+"]", binding.toString()); - v.set(value2); - assertEquals("LongBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("LongBinding [value: "+value2+"]", binding.toString()); - } - - @Test - public void testObjectToString() { - final Object value1 = new Object(); - final Object value2 = new Object(); - final ObjectProperty v = new SimpleObjectProperty(value1); - final ObjectBinding binding = new ObjectBinding() { - {bind(v);} - @Override - protected Object computeValue() { - return v.get(); - } - }; - - assertEquals("ObjectBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("ObjectBinding [value: "+value1+"]", binding.toString()); - v.set(value2); - assertEquals("ObjectBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("ObjectBinding [value: "+value2+"]", binding.toString()); - } - - @Test - public void testStringToString() { - final String value1 = "Hello World"; - final String value2 = "Goodbye"; - final StringProperty v = new SimpleStringProperty(value1); - final StringBinding binding = new StringBinding() { - {bind(v);} - @Override - protected String computeValue() { - return v.get(); - } - }; - - assertEquals("StringBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("StringBinding [value: "+value1+"]", binding.toString()); - v.set(value2); - assertEquals("StringBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("StringBinding [value: "+value2+"]", binding.toString()); - } - - @Test - public void testListToString() { - final ObservableList value1 = FXCollections.observableArrayList(new Object()); - final ObservableList value2 = FXCollections.observableArrayList(new Object(), new Object()); - final ListProperty v = new SimpleListProperty(value1); - final ListBinding binding = new ListBinding() { - {bind(v);} - @Override - protected ObservableList computeValue() { - return v.get(); - } - }; - - assertEquals("ListBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("ListBinding [value: "+value1+"]", binding.toString()); - v.set(value2); - assertEquals("ListBinding [invalid]", binding.toString()); - binding.get(); - assertEquals("ListBinding [value: "+value2+"]", binding.toString()); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/BindingToStringTest.java 2015-08-31 10:24:22.481216855 -0400 @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + + +import javafx.beans.binding.*; +import javafx.beans.property.*; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BindingToStringTest { + + @Before + public void setUp() throws Exception { + } + + @Test + public void testBooleanToString() { + final boolean value1 = true; + final boolean value2 = false; + final BooleanProperty v = new SimpleBooleanProperty(value1); + final BooleanBinding binding = new BooleanBinding() { + {bind(v);} + @Override + protected boolean computeValue() { + return v.get(); + } + }; + + assertEquals("BooleanBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("BooleanBinding [value: "+value1+"]", binding.toString()); + v.set(value2); + assertEquals("BooleanBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("BooleanBinding [value: "+value2+"]", binding.toString()); + } + + @Test + public void testDoubleToString() { + final double value1 = Math.PI; + final double value2 = -Math.E; + final DoubleProperty v = new SimpleDoubleProperty(value1); + final DoubleBinding binding = new DoubleBinding() { + {bind(v);} + @Override + protected double computeValue() { + return v.get(); + } + }; + + assertEquals("DoubleBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("DoubleBinding [value: "+value1+"]", binding.toString()); + v.set(value2); + assertEquals("DoubleBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("DoubleBinding [value: "+value2+"]", binding.toString()); + } + + @Test + public void testFloatToString() { + final float value1 = (float)Math.PI; + final float value2 = (float)-Math.E; + final FloatProperty v = new SimpleFloatProperty(value1); + final FloatBinding binding = new FloatBinding() { + {bind(v);} + @Override + protected float computeValue() { + return v.get(); + } + }; + + assertEquals("FloatBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("FloatBinding [value: "+value1+"]", binding.toString()); + v.set(value2); + assertEquals("FloatBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("FloatBinding [value: "+value2+"]", binding.toString()); + } + + @Test + public void testIntegerToString() { + final int value1 = 42; + final int value2 = 987654321; + final IntegerProperty v = new SimpleIntegerProperty(value1); + final IntegerBinding binding = new IntegerBinding() { + {bind(v);} + @Override + protected int computeValue() { + return v.get(); + } + }; + + assertEquals("IntegerBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("IntegerBinding [value: "+value1+"]", binding.toString()); + v.set(value2); + assertEquals("IntegerBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("IntegerBinding [value: "+value2+"]", binding.toString()); + } + + @Test + public void testLongToString() { + final long value1 = -987654321234567890L; + final long value2 = 1234567890987654321L; + final LongProperty v = new SimpleLongProperty(value1); + final LongBinding binding = new LongBinding() { + {bind(v);} + @Override + protected long computeValue() { + return v.get(); + } + }; + + assertEquals("LongBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("LongBinding [value: "+value1+"]", binding.toString()); + v.set(value2); + assertEquals("LongBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("LongBinding [value: "+value2+"]", binding.toString()); + } + + @Test + public void testObjectToString() { + final Object value1 = new Object(); + final Object value2 = new Object(); + final ObjectProperty v = new SimpleObjectProperty(value1); + final ObjectBinding binding = new ObjectBinding() { + {bind(v);} + @Override + protected Object computeValue() { + return v.get(); + } + }; + + assertEquals("ObjectBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("ObjectBinding [value: "+value1+"]", binding.toString()); + v.set(value2); + assertEquals("ObjectBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("ObjectBinding [value: "+value2+"]", binding.toString()); + } + + @Test + public void testStringToString() { + final String value1 = "Hello World"; + final String value2 = "Goodbye"; + final StringProperty v = new SimpleStringProperty(value1); + final StringBinding binding = new StringBinding() { + {bind(v);} + @Override + protected String computeValue() { + return v.get(); + } + }; + + assertEquals("StringBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("StringBinding [value: "+value1+"]", binding.toString()); + v.set(value2); + assertEquals("StringBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("StringBinding [value: "+value2+"]", binding.toString()); + } + + @Test + public void testListToString() { + final ObservableList value1 = FXCollections.observableArrayList(new Object()); + final ObservableList value2 = FXCollections.observableArrayList(new Object(), new Object()); + final ListProperty v = new SimpleListProperty(value1); + final ListBinding binding = new ListBinding() { + {bind(v);} + @Override + protected ObservableList computeValue() { + return v.get(); + } + }; + + assertEquals("ListBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("ListBinding [value: "+value1+"]", binding.toString()); + v.set(value2); + assertEquals("ListBinding [invalid]", binding.toString()); + binding.get(); + assertEquals("ListBinding [value: "+value2+"]", binding.toString()); + } + +} --- old/modules/base/src/test/java/javafx/binding/BindingsArrayTest.java 2015-08-31 10:24:23.365216845 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,1239 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import javafx.beans.binding.*; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.ListProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleListProperty; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import com.sun.javafx.binding.ErrorLoggingUtiltity; -import javafx.collections.ObservableFloatArray; -import javafx.collections.ObservableIntegerArray; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - */ -public class BindingsArrayTest { - - private static final double EPSILON_DOUBLE = 1e-12; - private static final float EPSILON_FLOAT = 1e-5f; - - private static final Object data1 = new Object(); - private static final Object data2 = new Object(); - - private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); - - private ListProperty property; - private ObservableList list1; - private ObservableList list2; - private IntegerProperty index; - - @BeforeClass - public static void setUpClass() { - log.start(); - } - - @AfterClass - public static void tearDownClass() { - log.stop(); - } - - @Before - public void setUp() { - property = new SimpleListProperty(); - list1 = FXCollections.observableArrayList(data1, data2); - list2 = FXCollections.observableArrayList(); - index = new SimpleIntegerProperty(); - } - - @Test - public void testSize() { - final IntegerBinding size = Bindings.size(property); - DependencyUtils.checkDependencies(size.getDependencies(), property); - - assertEquals(0, size.get()); - property.set(list1); - assertEquals(2, size.get()); - list1.remove(data2); - assertEquals(1, size.get()); - property.set(list2); - assertEquals(0, size.get()); - property.addAll(data2, data2); - assertEquals(2, size.get()); - property.set(null); - assertEquals(0, size.get()); - } - - @Test(expected = NullPointerException.class) - public void testSize_Null() { - Bindings.size((ObservableList) null); - } - - @Test - public void testIsEmpty() { - final BooleanBinding empty = Bindings.isEmpty(property); - DependencyUtils.checkDependencies(empty.getDependencies(), property); - - assertTrue(empty.get()); - property.set(list1); - assertFalse(empty.get()); - list1.remove(data2); - assertFalse(empty.get()); - property.set(list2); - assertTrue(empty.get()); - property.addAll(data2, data2); - assertFalse(empty.get()); - property.set(null); - assertTrue(empty.get()); - } - - @Test(expected = NullPointerException.class) - public void testIsEmpty_Null() { - Bindings.isEmpty((ObservableList) null); - } - - @Test - public void testIsNotEmpty() { - final BooleanBinding notEmpty = Bindings.isNotEmpty(property); - DependencyUtils.checkDependencies(notEmpty.getDependencies(), property); - - assertFalse(notEmpty.get()); - property.set(list1); - assertTrue(notEmpty.get()); - list1.remove(data2); - assertTrue(notEmpty.get()); - property.set(list2); - assertFalse(notEmpty.get()); - property.addAll(data2, data2); - assertTrue(notEmpty.get()); - property.set(null); - assertFalse(notEmpty.get()); - } - - @Test(expected = NullPointerException.class) - public void testIsNotEmpty_Null() { - Bindings.isNotEmpty((ObservableList) null); - } - - @Test - public void testValueAt_Constant() { - final ObjectBinding binding0 = Bindings.valueAt(property, 0); - final ObjectBinding binding1 = Bindings.valueAt(property, 1); - final ObjectBinding binding2 = Bindings.valueAt(property, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), property); - DependencyUtils.checkDependencies(binding1.getDependencies(), property); - DependencyUtils.checkDependencies(binding2.getDependencies(), property); - assertNull(binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(list1); - assertEquals(data1, binding0.get()); - assertEquals(data2, binding1.get()); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.remove(data2); - assertEquals(data1, binding0.get()); - assertNull(binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(list2); - assertNull(binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.addAll(data2, data2); - assertEquals(data2, binding0.get()); - assertEquals(data2, binding1.get()); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(null); - assertNull(binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testValueAt_Constant_Null() { - Bindings.valueAt(null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testValueAt_Constant_NegativeIndex() { - Bindings.valueAt(property, -1); - } - - @Test - public void testValueAt_Variable() { - final ObjectBinding binding = Bindings.valueAt(property, index); - DependencyUtils.checkDependencies(binding.getDependencies(), property, index); - - index.set(-1); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(list1); - index.set(-1); - assertNull(binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(data1, binding.get()); - index.set(1); - assertEquals(data2, binding.get()); - index.set(2); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.remove(data2); - index.set(-1); - assertNull(binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(data1, binding.get()); - index.set(1); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(list2); - index.set(-1); - assertNull(binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.addAll(data2, data2); - index.set(-1); - assertNull(binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(data2, binding.get()); - index.set(1); - assertEquals(data2, binding.get()); - index.set(2); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(null); - index.set(-1); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testValueAt_Variable_Null() { - Bindings.valueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testValueAt_Variable_NullIndex() { - Bindings.valueAt(property, null); - } - - @Test - public void testBooleanValueAt_Constant() { - final boolean defaultData = false; - final boolean localData1 = false; - final boolean localData2 = true; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final BooleanBinding binding0 = Bindings.booleanValueAt(localProperty, 0); - final BooleanBinding binding1 = Bindings.booleanValueAt(localProperty, 1); - final BooleanBinding binding2 = Bindings.booleanValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testBooleanValueAt_Constant_Null() { - Bindings.booleanValueAt(null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testBooleanValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.booleanValueAt(localProperty, -1); - } - - @Test - public void testBooleanValueAt_Variable() { - final boolean defaultData = false; - final boolean localData1 = false; - final boolean localData2 = true; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final BooleanBinding binding = Bindings.booleanValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(0, null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testBooleanValueAt_Variable_Null() { - Bindings.booleanValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testBooleanValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.booleanValueAt(localProperty, null); - } - - @Test - public void testDoubleValueAt_Constant() { - final double defaultData = 0.0; - final double localData1 = Math.PI; - final double localData2 = -Math.E; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final DoubleBinding binding0 = Bindings.doubleValueAt(localProperty, 0); - final DoubleBinding binding1 = Bindings.doubleValueAt(localProperty, 1); - final DoubleBinding binding2 = Bindings.doubleValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); - assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get(), EPSILON_DOUBLE); - assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testDoubleValueAt_Constant_Null() { - Bindings.doubleValueAt(null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testDoubleValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.doubleValueAt(localProperty, -1); - } - - @Test - public void testDoubleValueAt_Variable() { - final double defaultData = 0.0; - final double localData1 = -Math.PI; - final double localData2 = Math.E; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final DoubleBinding binding = Bindings.doubleValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get(), EPSILON_DOUBLE); - index.set(1); - assertEquals(localData2, binding.get(), EPSILON_DOUBLE); - index.set(2); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get(), EPSILON_DOUBLE); - index.set(1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(0, null); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - index.set(1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get(), EPSILON_DOUBLE); - index.set(1); - assertEquals(localData2, binding.get(), EPSILON_DOUBLE); - index.set(2); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testDoubleValueAt_Variable_Null() { - Bindings.doubleValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testDoubleValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.doubleValueAt(localProperty, null); - } - - @Test - public void testFloatValueAt_Constant() { - final float defaultData = 0.0f; - final float localData1 = (float)Math.PI; - final float localData2 = (float)-Math.E; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final FloatBinding binding0 = Bindings.floatValueAt(localProperty, 0); - final FloatBinding binding1 = Bindings.floatValueAt(localProperty, 1); - final FloatBinding binding2 = Bindings.floatValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get(), EPSILON_FLOAT); - assertEquals(localData2, binding1.get(), EPSILON_FLOAT); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get(), EPSILON_FLOAT); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get(), EPSILON_FLOAT); - assertEquals(localData2, binding1.get(), EPSILON_FLOAT); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testFloatValueAt_Constant_Null() { - Bindings.floatValueAt((ObservableFloatArray) null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testFloatValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.floatValueAt(localProperty, -1); - } - - @Test - public void testFloatValueAt_Variable() { - final float defaultData = 0.0f; - final float localData1 = (float)-Math.PI; - final float localData2 = (float)Math.E; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final FloatBinding binding = Bindings.floatValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get(), EPSILON_FLOAT); - index.set(1); - assertEquals(localData2, binding.get(), EPSILON_FLOAT); - index.set(2); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get(), EPSILON_FLOAT); - index.set(1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(0, null); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - index.set(1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get(), EPSILON_FLOAT); - index.set(1); - assertEquals(localData2, binding.get(), EPSILON_FLOAT); - index.set(2); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testFloatValueAt_Variable_Null() { - Bindings.floatValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testFloatValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.floatValueAt(localProperty, null); - } - - @Test - public void testIntegerValueAt_Constant() { - final int defaultData = 0; - final int localData1 = 42; - final int localData2 = -7; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final IntegerBinding binding0 = Bindings.integerValueAt(localProperty, 0); - final IntegerBinding binding1 = Bindings.integerValueAt(localProperty, 1); - final IntegerBinding binding2 = Bindings.integerValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testIntegerValueAt_Constant_Null() { - Bindings.integerValueAt((ObservableIntegerArray) null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testIntegerValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.integerValueAt(localProperty, -1); - } - - @Test - public void testIntegerValueAt_Variable() { - final int defaultData = 0; - final int localData1 = 42; - final int localData2 = -7; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final IntegerBinding binding = Bindings.integerValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(0, null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testIntegerValueAt_Variable_Null() { - Bindings.integerValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testIntegerValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.integerValueAt(localProperty, null); - } - - @Test - public void testLongValueAt_Constant() { - final long defaultData = 0L; - final long localData1 = 1234567890987654321L; - final long localData2 = -987654321987654321L; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final LongBinding binding0 = Bindings.longValueAt(localProperty, 0); - final LongBinding binding1 = Bindings.longValueAt(localProperty, 1); - final LongBinding binding2 = Bindings.longValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testLongValueAt_Constant_Null() { - Bindings.longValueAt(null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testLongValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.longValueAt(localProperty, -1); - } - - @Test - public void testLongValueAt_Variable() { - final long defaultData = 0; - final long localData1 = 98765432123456789L; - final long localData2 = -1234567890123456789L; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final LongBinding binding = Bindings.longValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(0, null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testLongValueAt_Variable_Null() { - Bindings.longValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testLongValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.longValueAt(localProperty, null); - } - - @Test - public void testStringValueAt_Constant() { - final String defaultData = null; - final String localData1 = "Hello World"; - final String localData2 = "Goodbye World"; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final StringBinding binding0 = Bindings.stringValueAt(localProperty, 0); - final StringBinding binding1 = Bindings.stringValueAt(localProperty, 1); - final StringBinding binding2 = Bindings.stringValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testStringValueAt_Constant_Null() { - Bindings.stringValueAt(null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testStringValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.stringValueAt(localProperty, -1); - } - - @Test - public void testStringValueAt_Variable() { - final String defaultData = null; - final String localData1 = "Goodbye"; - final String localData2 = "Hello"; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final StringBinding binding = Bindings.stringValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testStringValueAt_Variable_Null() { - Bindings.stringValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testStringValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.stringValueAt(localProperty, null); - } - - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/BindingsArrayTest.java 2015-08-31 10:24:23.153216848 -0400 @@ -0,0 +1,1239 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import javafx.beans.binding.*; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import test.com.sun.javafx.binding.ErrorLoggingUtiltity; +import javafx.collections.ObservableFloatArray; +import javafx.collections.ObservableIntegerArray; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + */ +public class BindingsArrayTest { + + private static final double EPSILON_DOUBLE = 1e-12; + private static final float EPSILON_FLOAT = 1e-5f; + + private static final Object data1 = new Object(); + private static final Object data2 = new Object(); + + private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); + + private ListProperty property; + private ObservableList list1; + private ObservableList list2; + private IntegerProperty index; + + @BeforeClass + public static void setUpClass() { + log.start(); + } + + @AfterClass + public static void tearDownClass() { + log.stop(); + } + + @Before + public void setUp() { + property = new SimpleListProperty(); + list1 = FXCollections.observableArrayList(data1, data2); + list2 = FXCollections.observableArrayList(); + index = new SimpleIntegerProperty(); + } + + @Test + public void testSize() { + final IntegerBinding size = Bindings.size(property); + DependencyUtils.checkDependencies(size.getDependencies(), property); + + assertEquals(0, size.get()); + property.set(list1); + assertEquals(2, size.get()); + list1.remove(data2); + assertEquals(1, size.get()); + property.set(list2); + assertEquals(0, size.get()); + property.addAll(data2, data2); + assertEquals(2, size.get()); + property.set(null); + assertEquals(0, size.get()); + } + + @Test(expected = NullPointerException.class) + public void testSize_Null() { + Bindings.size((ObservableList) null); + } + + @Test + public void testIsEmpty() { + final BooleanBinding empty = Bindings.isEmpty(property); + DependencyUtils.checkDependencies(empty.getDependencies(), property); + + assertTrue(empty.get()); + property.set(list1); + assertFalse(empty.get()); + list1.remove(data2); + assertFalse(empty.get()); + property.set(list2); + assertTrue(empty.get()); + property.addAll(data2, data2); + assertFalse(empty.get()); + property.set(null); + assertTrue(empty.get()); + } + + @Test(expected = NullPointerException.class) + public void testIsEmpty_Null() { + Bindings.isEmpty((ObservableList) null); + } + + @Test + public void testIsNotEmpty() { + final BooleanBinding notEmpty = Bindings.isNotEmpty(property); + DependencyUtils.checkDependencies(notEmpty.getDependencies(), property); + + assertFalse(notEmpty.get()); + property.set(list1); + assertTrue(notEmpty.get()); + list1.remove(data2); + assertTrue(notEmpty.get()); + property.set(list2); + assertFalse(notEmpty.get()); + property.addAll(data2, data2); + assertTrue(notEmpty.get()); + property.set(null); + assertFalse(notEmpty.get()); + } + + @Test(expected = NullPointerException.class) + public void testIsNotEmpty_Null() { + Bindings.isNotEmpty((ObservableList) null); + } + + @Test + public void testValueAt_Constant() { + final ObjectBinding binding0 = Bindings.valueAt(property, 0); + final ObjectBinding binding1 = Bindings.valueAt(property, 1); + final ObjectBinding binding2 = Bindings.valueAt(property, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), property); + DependencyUtils.checkDependencies(binding1.getDependencies(), property); + DependencyUtils.checkDependencies(binding2.getDependencies(), property); + assertNull(binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(list1); + assertEquals(data1, binding0.get()); + assertEquals(data2, binding1.get()); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.remove(data2); + assertEquals(data1, binding0.get()); + assertNull(binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(list2); + assertNull(binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.addAll(data2, data2); + assertEquals(data2, binding0.get()); + assertEquals(data2, binding1.get()); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(null); + assertNull(binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testValueAt_Constant_Null() { + Bindings.valueAt(null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testValueAt_Constant_NegativeIndex() { + Bindings.valueAt(property, -1); + } + + @Test + public void testValueAt_Variable() { + final ObjectBinding binding = Bindings.valueAt(property, index); + DependencyUtils.checkDependencies(binding.getDependencies(), property, index); + + index.set(-1); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(list1); + index.set(-1); + assertNull(binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(data1, binding.get()); + index.set(1); + assertEquals(data2, binding.get()); + index.set(2); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.remove(data2); + index.set(-1); + assertNull(binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(data1, binding.get()); + index.set(1); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(list2); + index.set(-1); + assertNull(binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.addAll(data2, data2); + index.set(-1); + assertNull(binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(data2, binding.get()); + index.set(1); + assertEquals(data2, binding.get()); + index.set(2); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(null); + index.set(-1); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testValueAt_Variable_Null() { + Bindings.valueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testValueAt_Variable_NullIndex() { + Bindings.valueAt(property, null); + } + + @Test + public void testBooleanValueAt_Constant() { + final boolean defaultData = false; + final boolean localData1 = false; + final boolean localData2 = true; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final BooleanBinding binding0 = Bindings.booleanValueAt(localProperty, 0); + final BooleanBinding binding1 = Bindings.booleanValueAt(localProperty, 1); + final BooleanBinding binding2 = Bindings.booleanValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testBooleanValueAt_Constant_Null() { + Bindings.booleanValueAt(null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testBooleanValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.booleanValueAt(localProperty, -1); + } + + @Test + public void testBooleanValueAt_Variable() { + final boolean defaultData = false; + final boolean localData1 = false; + final boolean localData2 = true; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final BooleanBinding binding = Bindings.booleanValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(0, null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testBooleanValueAt_Variable_Null() { + Bindings.booleanValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testBooleanValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.booleanValueAt(localProperty, null); + } + + @Test + public void testDoubleValueAt_Constant() { + final double defaultData = 0.0; + final double localData1 = Math.PI; + final double localData2 = -Math.E; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final DoubleBinding binding0 = Bindings.doubleValueAt(localProperty, 0); + final DoubleBinding binding1 = Bindings.doubleValueAt(localProperty, 1); + final DoubleBinding binding2 = Bindings.doubleValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); + assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get(), EPSILON_DOUBLE); + assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testDoubleValueAt_Constant_Null() { + Bindings.doubleValueAt(null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testDoubleValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.doubleValueAt(localProperty, -1); + } + + @Test + public void testDoubleValueAt_Variable() { + final double defaultData = 0.0; + final double localData1 = -Math.PI; + final double localData2 = Math.E; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final DoubleBinding binding = Bindings.doubleValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get(), EPSILON_DOUBLE); + index.set(1); + assertEquals(localData2, binding.get(), EPSILON_DOUBLE); + index.set(2); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get(), EPSILON_DOUBLE); + index.set(1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(0, null); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + index.set(1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get(), EPSILON_DOUBLE); + index.set(1); + assertEquals(localData2, binding.get(), EPSILON_DOUBLE); + index.set(2); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testDoubleValueAt_Variable_Null() { + Bindings.doubleValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testDoubleValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.doubleValueAt(localProperty, null); + } + + @Test + public void testFloatValueAt_Constant() { + final float defaultData = 0.0f; + final float localData1 = (float)Math.PI; + final float localData2 = (float)-Math.E; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final FloatBinding binding0 = Bindings.floatValueAt(localProperty, 0); + final FloatBinding binding1 = Bindings.floatValueAt(localProperty, 1); + final FloatBinding binding2 = Bindings.floatValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get(), EPSILON_FLOAT); + assertEquals(localData2, binding1.get(), EPSILON_FLOAT); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get(), EPSILON_FLOAT); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get(), EPSILON_FLOAT); + assertEquals(localData2, binding1.get(), EPSILON_FLOAT); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testFloatValueAt_Constant_Null() { + Bindings.floatValueAt((ObservableFloatArray) null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testFloatValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.floatValueAt(localProperty, -1); + } + + @Test + public void testFloatValueAt_Variable() { + final float defaultData = 0.0f; + final float localData1 = (float)-Math.PI; + final float localData2 = (float)Math.E; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final FloatBinding binding = Bindings.floatValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get(), EPSILON_FLOAT); + index.set(1); + assertEquals(localData2, binding.get(), EPSILON_FLOAT); + index.set(2); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get(), EPSILON_FLOAT); + index.set(1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(0, null); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + index.set(1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get(), EPSILON_FLOAT); + index.set(1); + assertEquals(localData2, binding.get(), EPSILON_FLOAT); + index.set(2); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testFloatValueAt_Variable_Null() { + Bindings.floatValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testFloatValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.floatValueAt(localProperty, null); + } + + @Test + public void testIntegerValueAt_Constant() { + final int defaultData = 0; + final int localData1 = 42; + final int localData2 = -7; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final IntegerBinding binding0 = Bindings.integerValueAt(localProperty, 0); + final IntegerBinding binding1 = Bindings.integerValueAt(localProperty, 1); + final IntegerBinding binding2 = Bindings.integerValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testIntegerValueAt_Constant_Null() { + Bindings.integerValueAt((ObservableIntegerArray) null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testIntegerValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.integerValueAt(localProperty, -1); + } + + @Test + public void testIntegerValueAt_Variable() { + final int defaultData = 0; + final int localData1 = 42; + final int localData2 = -7; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final IntegerBinding binding = Bindings.integerValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(0, null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testIntegerValueAt_Variable_Null() { + Bindings.integerValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testIntegerValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.integerValueAt(localProperty, null); + } + + @Test + public void testLongValueAt_Constant() { + final long defaultData = 0L; + final long localData1 = 1234567890987654321L; + final long localData2 = -987654321987654321L; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final LongBinding binding0 = Bindings.longValueAt(localProperty, 0); + final LongBinding binding1 = Bindings.longValueAt(localProperty, 1); + final LongBinding binding2 = Bindings.longValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testLongValueAt_Constant_Null() { + Bindings.longValueAt(null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testLongValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.longValueAt(localProperty, -1); + } + + @Test + public void testLongValueAt_Variable() { + final long defaultData = 0; + final long localData1 = 98765432123456789L; + final long localData2 = -1234567890123456789L; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final LongBinding binding = Bindings.longValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(0, null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testLongValueAt_Variable_Null() { + Bindings.longValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testLongValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.longValueAt(localProperty, null); + } + + @Test + public void testStringValueAt_Constant() { + final String defaultData = null; + final String localData1 = "Hello World"; + final String localData2 = "Goodbye World"; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final StringBinding binding0 = Bindings.stringValueAt(localProperty, 0); + final StringBinding binding1 = Bindings.stringValueAt(localProperty, 1); + final StringBinding binding2 = Bindings.stringValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testStringValueAt_Constant_Null() { + Bindings.stringValueAt(null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testStringValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.stringValueAt(localProperty, -1); + } + + @Test + public void testStringValueAt_Variable() { + final String defaultData = null; + final String localData1 = "Goodbye"; + final String localData2 = "Hello"; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final StringBinding binding = Bindings.stringValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testStringValueAt_Variable_Null() { + Bindings.stringValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testStringValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.stringValueAt(localProperty, null); + } + + +} --- old/modules/base/src/test/java/javafx/binding/BindingsBooleanTest.java 2015-08-31 10:24:23.985216838 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,424 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import static org.junit.Assert.*; -import javafx.beans.InvalidationListener; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.binding.Bindings; -import javafx.beans.binding.BooleanBinding; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableBooleanValue; - -import org.junit.Before; -import org.junit.Test; - -public class BindingsBooleanTest { - - private BooleanProperty op1; - private BooleanProperty op2; - private InvalidationListenerMock observer; - - @Before - public void setUp() { - op1 = new SimpleBooleanProperty(true); - op2 = new SimpleBooleanProperty(false); - observer = new InvalidationListenerMock(); - } - - @SuppressWarnings("unused") - @Test - public void testAnd() { - final BooleanBinding binding = Bindings.and(op1, op2); - binding.addListener(observer); - - // check initial value - assertEquals(true && false, binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); - - // change first operand - observer.reset(); - op1.set(false); - assertEquals(false && false, binding.get()); - observer.check(binding, 1); - - // change second operand - op1.set(true); // avoid short-circuit invalidation - binding.get(); - observer.reset(); - op2.set(true); - assertEquals(true && true, binding.get()); - observer.check(binding, 1); - - // last possibility - op1.set(false); - assertEquals(false && true, binding.get()); - observer.check(binding, 1); - } - - @Test - public void testAnd_Efficiency() { - final BooleanBinding binding = Bindings.and(op1, op2); - binding.addListener(observer); - binding.get(); - - // change both values - op1.set(false); - op2.set(true); - observer.check(binding, 1); - - // check short circuit invalidation - op2.set(false); - observer.check(null, 0); - } - - @SuppressWarnings("unused") - @Test - public void testAnd_Self() { - final BooleanBinding binding = Bindings.and(op1, op1); - binding.addListener(observer); - - // check initial value - assertEquals(true && true, binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), op1); - - // change value - observer.reset(); - op1.set(false); - assertEquals(false && false, binding.get()); - observer.check(binding, 1); - - // change value again - op1.set(true); - assertEquals(true && true, binding.get()); - observer.check(binding, 1); - } - - @Test - public void testAnd_WeakReference() { - final ObservableBooleanValueMock op1 = new ObservableBooleanValueMock(); - final ObservableBooleanValueMock op2 = new ObservableBooleanValueMock(); - BooleanBinding binding = Bindings.and(op1, op2); - assertNotNull(op1.listener); - assertNotNull(op2.listener); - binding = null; - System.gc(); - op1.fireInvalidationEvent(); - assertNull(op1.listener); - assertNotNull(op2.listener); - op2.fireInvalidationEvent(); - assertNull(op1.listener); - assertNull(op2.listener); - } - - @Test(expected=NullPointerException.class) - public void testAnd_null_x() { - Bindings.and(null, op1); - } - - @Test(expected=NullPointerException.class) - public void testAnd_x_null() { - Bindings.and(op1, null); - } - - @SuppressWarnings("unused") - @Test - public void testOr() { - final BooleanBinding binding = Bindings.or(op1, op2); - binding.addListener(observer); - - // check initial value - assertEquals(true || false, binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); - - // change first operand - observer.reset(); - op1.set(false); - assertEquals(false || false, binding.get()); - observer.check(binding, 1); - - // change second operand - op2.set(true); - assertEquals(false || true, binding.get()); - observer.check(binding, 1); - - // last possibility - op1.set(true); - assertEquals(true || true, binding.get()); - observer.check(binding, 1); - } - - @Test - public void testOr_Efficiency() { - final BooleanBinding binding = Bindings.or(op1, op2); - binding.addListener(observer); - binding.get(); - - // change both values - op1.set(false); - op2.set(true); - observer.check(binding, 1); - - // check short circuit invalidation - op1.set(true); // force short-circuit invalidation - binding.get(); - observer.reset(); - op2.set(false); - observer.check(null, 0); - } - - @SuppressWarnings("unused") - @Test - public void testOr_Self() { - final BooleanBinding binding = Bindings.or(op1, op1); - binding.addListener(observer); - - // check initial value - assertEquals(true || true, binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), op1); - - // change value - observer.reset(); - op1.set(false); - assertEquals(false || false, binding.get()); - observer.check(binding, 1); - - // change value again - op1.set(true); - assertEquals(true || true, binding.get()); - observer.check(binding, 1); - } - - @Test - public void testOr_WeakReference() { - final ObservableBooleanValueMock op1 = new ObservableBooleanValueMock(); - final ObservableBooleanValueMock op2 = new ObservableBooleanValueMock(); - BooleanBinding binding = Bindings.or(op1, op2); - assertNotNull(op1.listener); - assertNotNull(op2.listener); - binding = null; - System.gc(); - op1.fireInvalidationEvent(); - assertNull(op1.listener); - assertNotNull(op2.listener); - op2.fireInvalidationEvent(); - assertNull(op1.listener); - assertNull(op2.listener); - } - - @Test(expected=NullPointerException.class) - public void testOr_null_x() { - Bindings.or(null, op1); - } - - @Test(expected=NullPointerException.class) - public void testOr_x_null() { - Bindings.or(op1, null); - } - - @Test - public void testNot() { - final BooleanBinding binding = Bindings.not(op1); - binding.addListener(observer); - - // check initial value - assertEquals(!true, binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), op1); - - // change first operand - observer.reset(); - op1.set(false); - assertEquals(!false, binding.get()); - observer.check(binding, 1); - - // change again - op1.set(true); - assertEquals(!true, binding.get()); - observer.check(binding, 1); - } - - @Test - public void testNot_Efficiency() { - final BooleanBinding binding = Bindings.not(op1); - binding.addListener(observer); - binding.get(); - - // change value twice - op1.set(false); - op1.set(true); - observer.check(binding, 1); - } - - @Test(expected=NullPointerException.class) - public void testNot_null() { - Bindings.not(null); - } - - @Test - public void testEqual() { - final BooleanBinding binding = Bindings.equal(op1, op2); - binding.addListener(observer); - - // check initial value - assertEquals(true == false, binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); - - // change first operand - observer.reset(); - op1.set(false); - assertEquals(false == false, binding.get()); - observer.check(binding, 1); - - // change second operand - op2.set(true); - assertEquals(false == true, binding.get()); - observer.check(binding, 1); - - // last possibility - op1.set(true); - assertEquals(true == true, binding.get()); - observer.check(binding, 1); - } - - @Test - public void testEqual_Efficiency() { - final BooleanBinding binding = Bindings.equal(op1, op2); - binding.addListener(observer); - binding.get(); - - // change both values - op1.set(false); - op2.set(true); - observer.check(binding, 1); - } - - @Test - public void testEqual_Self() { - final BooleanBinding binding = Bindings.equal(op1, op1); - binding.addListener(observer); - - // check initial value - assertEquals(true == true, binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), op1); - - // change value - observer.reset(); - op1.set(false); - assertEquals(false == false, binding.get()); - observer.check(binding, 1); - - // change value again - op1.set(true); - assertEquals(true == true, binding.get()); - observer.check(binding, 1); - } - - @Test(expected=NullPointerException.class) - public void testEqual_null_x() { - Bindings.equal((ObservableBooleanValue)null, op1); - } - - @Test(expected=NullPointerException.class) - public void testEqual_x_null() { - Bindings.equal(op1, (ObservableBooleanValue)null); - } - - @Test - public void testNotEqual() { - final BooleanBinding binding = Bindings.notEqual(op1, op2); - binding.addListener(observer); - - // check initial value - assertEquals(true != false, binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); - - // change first operand - observer.reset(); - op1.set(false); - assertEquals(false != false, binding.get()); - observer.check(binding, 1); - - // change second operand - op2.set(true); - assertEquals(false != true, binding.get()); - observer.check(binding, 1); - - // last possibility - op1.set(true); - assertEquals(true != true, binding.get()); - observer.check(binding, 1); - } - - private static class ObservableBooleanValueMock implements ObservableBooleanValue { - private InvalidationListener listener; - - @Override - public boolean get() { - return false; - } - - @Override - public Boolean getValue() { - return Boolean.FALSE; - } - - private void fireInvalidationEvent() { - if (listener == null) { - fail("Attempt to fire an event with no listener attached"); - } - this.listener.invalidated(this); - } - - @Override - public void addListener(ChangeListener listener) { - // not used - } - - @Override - public void removeListener(ChangeListener listener) { - // not used - } - - @Override - public void addListener(InvalidationListener listener) { - if ((this.listener != null) && !this.listener.equals(listener)) { - fail("More than one listener set in mock."); - } - this.listener = listener; - } - - @Override - public void removeListener(InvalidationListener listener) { - if (this.listener != listener) { - fail("Attempt to remove unknown listener"); - } - this.listener = null; - } - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/BindingsBooleanTest.java 2015-08-31 10:24:23.853216840 -0400 @@ -0,0 +1,424 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import static org.junit.Assert.*; +import javafx.beans.InvalidationListener; +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.binding.Bindings; +import javafx.beans.binding.BooleanBinding; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableBooleanValue; + +import org.junit.Before; +import org.junit.Test; + +public class BindingsBooleanTest { + + private BooleanProperty op1; + private BooleanProperty op2; + private InvalidationListenerMock observer; + + @Before + public void setUp() { + op1 = new SimpleBooleanProperty(true); + op2 = new SimpleBooleanProperty(false); + observer = new InvalidationListenerMock(); + } + + @SuppressWarnings("unused") + @Test + public void testAnd() { + final BooleanBinding binding = Bindings.and(op1, op2); + binding.addListener(observer); + + // check initial value + assertEquals(true && false, binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); + + // change first operand + observer.reset(); + op1.set(false); + assertEquals(false && false, binding.get()); + observer.check(binding, 1); + + // change second operand + op1.set(true); // avoid short-circuit invalidation + binding.get(); + observer.reset(); + op2.set(true); + assertEquals(true && true, binding.get()); + observer.check(binding, 1); + + // last possibility + op1.set(false); + assertEquals(false && true, binding.get()); + observer.check(binding, 1); + } + + @Test + public void testAnd_Efficiency() { + final BooleanBinding binding = Bindings.and(op1, op2); + binding.addListener(observer); + binding.get(); + + // change both values + op1.set(false); + op2.set(true); + observer.check(binding, 1); + + // check short circuit invalidation + op2.set(false); + observer.check(null, 0); + } + + @SuppressWarnings("unused") + @Test + public void testAnd_Self() { + final BooleanBinding binding = Bindings.and(op1, op1); + binding.addListener(observer); + + // check initial value + assertEquals(true && true, binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), op1); + + // change value + observer.reset(); + op1.set(false); + assertEquals(false && false, binding.get()); + observer.check(binding, 1); + + // change value again + op1.set(true); + assertEquals(true && true, binding.get()); + observer.check(binding, 1); + } + + @Test + public void testAnd_WeakReference() { + final ObservableBooleanValueMock op1 = new ObservableBooleanValueMock(); + final ObservableBooleanValueMock op2 = new ObservableBooleanValueMock(); + BooleanBinding binding = Bindings.and(op1, op2); + assertNotNull(op1.listener); + assertNotNull(op2.listener); + binding = null; + System.gc(); + op1.fireInvalidationEvent(); + assertNull(op1.listener); + assertNotNull(op2.listener); + op2.fireInvalidationEvent(); + assertNull(op1.listener); + assertNull(op2.listener); + } + + @Test(expected=NullPointerException.class) + public void testAnd_null_x() { + Bindings.and(null, op1); + } + + @Test(expected=NullPointerException.class) + public void testAnd_x_null() { + Bindings.and(op1, null); + } + + @SuppressWarnings("unused") + @Test + public void testOr() { + final BooleanBinding binding = Bindings.or(op1, op2); + binding.addListener(observer); + + // check initial value + assertEquals(true || false, binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); + + // change first operand + observer.reset(); + op1.set(false); + assertEquals(false || false, binding.get()); + observer.check(binding, 1); + + // change second operand + op2.set(true); + assertEquals(false || true, binding.get()); + observer.check(binding, 1); + + // last possibility + op1.set(true); + assertEquals(true || true, binding.get()); + observer.check(binding, 1); + } + + @Test + public void testOr_Efficiency() { + final BooleanBinding binding = Bindings.or(op1, op2); + binding.addListener(observer); + binding.get(); + + // change both values + op1.set(false); + op2.set(true); + observer.check(binding, 1); + + // check short circuit invalidation + op1.set(true); // force short-circuit invalidation + binding.get(); + observer.reset(); + op2.set(false); + observer.check(null, 0); + } + + @SuppressWarnings("unused") + @Test + public void testOr_Self() { + final BooleanBinding binding = Bindings.or(op1, op1); + binding.addListener(observer); + + // check initial value + assertEquals(true || true, binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), op1); + + // change value + observer.reset(); + op1.set(false); + assertEquals(false || false, binding.get()); + observer.check(binding, 1); + + // change value again + op1.set(true); + assertEquals(true || true, binding.get()); + observer.check(binding, 1); + } + + @Test + public void testOr_WeakReference() { + final ObservableBooleanValueMock op1 = new ObservableBooleanValueMock(); + final ObservableBooleanValueMock op2 = new ObservableBooleanValueMock(); + BooleanBinding binding = Bindings.or(op1, op2); + assertNotNull(op1.listener); + assertNotNull(op2.listener); + binding = null; + System.gc(); + op1.fireInvalidationEvent(); + assertNull(op1.listener); + assertNotNull(op2.listener); + op2.fireInvalidationEvent(); + assertNull(op1.listener); + assertNull(op2.listener); + } + + @Test(expected=NullPointerException.class) + public void testOr_null_x() { + Bindings.or(null, op1); + } + + @Test(expected=NullPointerException.class) + public void testOr_x_null() { + Bindings.or(op1, null); + } + + @Test + public void testNot() { + final BooleanBinding binding = Bindings.not(op1); + binding.addListener(observer); + + // check initial value + assertEquals(!true, binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), op1); + + // change first operand + observer.reset(); + op1.set(false); + assertEquals(!false, binding.get()); + observer.check(binding, 1); + + // change again + op1.set(true); + assertEquals(!true, binding.get()); + observer.check(binding, 1); + } + + @Test + public void testNot_Efficiency() { + final BooleanBinding binding = Bindings.not(op1); + binding.addListener(observer); + binding.get(); + + // change value twice + op1.set(false); + op1.set(true); + observer.check(binding, 1); + } + + @Test(expected=NullPointerException.class) + public void testNot_null() { + Bindings.not(null); + } + + @Test + public void testEqual() { + final BooleanBinding binding = Bindings.equal(op1, op2); + binding.addListener(observer); + + // check initial value + assertEquals(true == false, binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); + + // change first operand + observer.reset(); + op1.set(false); + assertEquals(false == false, binding.get()); + observer.check(binding, 1); + + // change second operand + op2.set(true); + assertEquals(false == true, binding.get()); + observer.check(binding, 1); + + // last possibility + op1.set(true); + assertEquals(true == true, binding.get()); + observer.check(binding, 1); + } + + @Test + public void testEqual_Efficiency() { + final BooleanBinding binding = Bindings.equal(op1, op2); + binding.addListener(observer); + binding.get(); + + // change both values + op1.set(false); + op2.set(true); + observer.check(binding, 1); + } + + @Test + public void testEqual_Self() { + final BooleanBinding binding = Bindings.equal(op1, op1); + binding.addListener(observer); + + // check initial value + assertEquals(true == true, binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), op1); + + // change value + observer.reset(); + op1.set(false); + assertEquals(false == false, binding.get()); + observer.check(binding, 1); + + // change value again + op1.set(true); + assertEquals(true == true, binding.get()); + observer.check(binding, 1); + } + + @Test(expected=NullPointerException.class) + public void testEqual_null_x() { + Bindings.equal((ObservableBooleanValue)null, op1); + } + + @Test(expected=NullPointerException.class) + public void testEqual_x_null() { + Bindings.equal(op1, (ObservableBooleanValue)null); + } + + @Test + public void testNotEqual() { + final BooleanBinding binding = Bindings.notEqual(op1, op2); + binding.addListener(observer); + + // check initial value + assertEquals(true != false, binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); + + // change first operand + observer.reset(); + op1.set(false); + assertEquals(false != false, binding.get()); + observer.check(binding, 1); + + // change second operand + op2.set(true); + assertEquals(false != true, binding.get()); + observer.check(binding, 1); + + // last possibility + op1.set(true); + assertEquals(true != true, binding.get()); + observer.check(binding, 1); + } + + private static class ObservableBooleanValueMock implements ObservableBooleanValue { + private InvalidationListener listener; + + @Override + public boolean get() { + return false; + } + + @Override + public Boolean getValue() { + return Boolean.FALSE; + } + + private void fireInvalidationEvent() { + if (listener == null) { + fail("Attempt to fire an event with no listener attached"); + } + this.listener.invalidated(this); + } + + @Override + public void addListener(ChangeListener listener) { + // not used + } + + @Override + public void removeListener(ChangeListener listener) { + // not used + } + + @Override + public void addListener(InvalidationListener listener) { + if ((this.listener != null) && !this.listener.equals(listener)) { + fail("More than one listener set in mock."); + } + this.listener = listener; + } + + @Override + public void removeListener(InvalidationListener listener) { + if (this.listener != listener) { + fail("Attempt to remove unknown listener"); + } + this.listener = null; + } + + } +} --- old/modules/base/src/test/java/javafx/binding/BindingsCreateBindingTest.java 2015-08-31 10:24:24.669216831 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import java.util.Arrays; -import java.util.Collection; -import java.util.concurrent.Callable; -import javafx.beans.Observable; -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.property.Property; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleLongProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import com.sun.javafx.binding.ErrorLoggingUtiltity; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import static org.junit.Assert.*; - -/** - */ -@RunWith(Parameterized.class) -public class BindingsCreateBindingTest { - - private static final float EPSILON_FLOAT = 1e-5f; - private static final double EPSILON_DOUBLE = 1e-10; - - private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); - - private static interface Functions { - public Binding create(Callable func, Observable... dependencies); - public void check(S value0, S value1); - } - - private final Property p0; - private final Property p1; - private final Functions f; - private final T value0; - private final T value1; - private final T defaultValue; - - @BeforeClass - public static void setUpClass() { - log.start(); - } - - @AfterClass - public static void tearDownClass() { - log.stop(); - } - - public BindingsCreateBindingTest(Property p0, Property p1, Functions f, T value0, T value1, T defaultValue) { - this.p0 = p0; - this.p1 = p1; - this.f = f; - this.value0 = value0; - this.value1 = value1; - this.defaultValue = defaultValue; - } - - @Test - public void testNoDependencies() { - // func returns value0, no dependencies specified - final Callable func0 = () -> value0; - final Binding binding0 = f.create(func0); - - f.check(value0, binding0.getValue()); - assertTrue(binding0.getDependencies().isEmpty()); - binding0.dispose(); - - // func returns value1, dependencies set to null - final Callable func1 = () -> value1; - final Binding binding1 = f.create(func1, (Observable[])null); - - f.check(value1, binding1.getValue()); - assertTrue(binding1.getDependencies().isEmpty()); - binding1.dispose(); - - // func throws exception, dependencies set to empty array - final Callable func2 = () -> { - throw new Exception(); - }; - final Binding binding2 = f.create(func2, new Observable [0]); - - f.check(defaultValue, binding2.getValue()); - log.check(java.util.logging.Level.WARNING, Exception.class); - assertTrue(binding2.getDependencies().isEmpty()); - binding2.dispose(); - } - - @Test - public void testOneDependency() { - final Callable func = () -> p0.getValue(); - final Binding binding = f.create(func, p0); - - f.check(p0.getValue(), binding.getValue()); - assertEquals(binding.getDependencies(), Arrays.asList(p0)); - p0.setValue(value1); - f.check(p0.getValue(), binding.getValue()); - binding.dispose(); - } - - @Test - public void testCreateBoolean_TwoDependencies() { - final Callable func = () -> p0.getValue(); - final Binding binding = f.create(func, p0, p1); - - f.check(p0.getValue(), binding.getValue()); - assertTrue(binding.getDependencies().equals(Arrays.asList(p0, p1)) || binding.getDependencies().equals((Arrays.asList(p1, p0)))); - p0.setValue(value1); - f.check(p0.getValue(), binding.getValue()); - binding.dispose(); - } - - @Parameterized.Parameters - public static Collection parameters() { - return Arrays.asList(new Object[][] { - { - new SimpleBooleanProperty(), new SimpleBooleanProperty(), - new Functions() { - @Override - public Binding create(Callable func, Observable... dependencies) { - return Bindings.createBooleanBinding(func, dependencies); - } - - @Override - public void check(Boolean value0, Boolean value1) { - assertEquals(value0, value1); - } - }, - true, false, false - }, - { - new SimpleDoubleProperty(), new SimpleDoubleProperty(), - new Functions() { - @Override - public Binding create(Callable func, Observable... dependencies) { - return Bindings.createDoubleBinding(func, dependencies); - } - - @Override - public void check(Number value0, Number value1) { - assertEquals(value0.doubleValue(), value1.doubleValue(), EPSILON_DOUBLE); - } - }, - Math.PI, -Math.E, 0.0 - }, - { - new SimpleFloatProperty(), new SimpleFloatProperty(), - new Functions() { - @Override - public Binding create(Callable func, Observable... dependencies) { - return Bindings.createFloatBinding(func, dependencies); - } - - @Override - public void check(Number value0, Number value1) { - assertEquals(value0.floatValue(), value1.floatValue(), EPSILON_FLOAT); - } - }, - (float)Math.PI, (float)-Math.E, 0.0f - }, - { - new SimpleIntegerProperty(), new SimpleIntegerProperty(), - new Functions() { - @Override - public Binding create(Callable func, Observable... dependencies) { - return Bindings.createIntegerBinding(func, dependencies); - } - - @Override - public void check(Number value0, Number value1) { - assertEquals(value0.intValue(), value1.intValue()); - } - }, - Integer.MAX_VALUE, Integer.MIN_VALUE, 0 - }, - { - new SimpleLongProperty(), new SimpleLongProperty(), - new Functions() { - @Override - public Binding create(Callable func, Observable... dependencies) { - return Bindings.createLongBinding(func, dependencies); - } - - @Override - public void check(Number value0, Number value1) { - assertEquals(value0.longValue(), value1.longValue()); - } - }, - Long.MAX_VALUE, Long.MIN_VALUE, 0L - }, - { - new SimpleObjectProperty(), new SimpleObjectProperty(), - new Functions() { - @Override - public Binding create(Callable func, Observable... dependencies) { - return Bindings.createObjectBinding(func, dependencies); - } - - @Override - public void check(Object value0, Object value1) { - assertEquals(value0, value1); - } - }, - new Object(), new Object(), null - }, - { - new SimpleStringProperty(), new SimpleStringProperty(), - new Functions() { - @Override - public Binding create(Callable func, Observable... dependencies) { - return Bindings.createStringBinding(func, dependencies); - } - - @Override - public void check(String value0, String value1) { - assertEquals(value0, value1); - } - }, - "Hello World", "Goodbye World", "" - }, - }); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/BindingsCreateBindingTest.java 2015-08-31 10:24:24.461216833 -0400 @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import java.util.Arrays; +import java.util.Collection; +import java.util.concurrent.Callable; +import javafx.beans.Observable; +import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.property.Property; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import test.com.sun.javafx.binding.ErrorLoggingUtiltity; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import static org.junit.Assert.*; + +/** + */ +@RunWith(Parameterized.class) +public class BindingsCreateBindingTest { + + private static final float EPSILON_FLOAT = 1e-5f; + private static final double EPSILON_DOUBLE = 1e-10; + + private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); + + private static interface Functions { + public Binding create(Callable func, Observable... dependencies); + public void check(S value0, S value1); + } + + private final Property p0; + private final Property p1; + private final Functions f; + private final T value0; + private final T value1; + private final T defaultValue; + + @BeforeClass + public static void setUpClass() { + log.start(); + } + + @AfterClass + public static void tearDownClass() { + log.stop(); + } + + public BindingsCreateBindingTest(Property p0, Property p1, Functions f, T value0, T value1, T defaultValue) { + this.p0 = p0; + this.p1 = p1; + this.f = f; + this.value0 = value0; + this.value1 = value1; + this.defaultValue = defaultValue; + } + + @Test + public void testNoDependencies() { + // func returns value0, no dependencies specified + final Callable func0 = () -> value0; + final Binding binding0 = f.create(func0); + + f.check(value0, binding0.getValue()); + assertTrue(binding0.getDependencies().isEmpty()); + binding0.dispose(); + + // func returns value1, dependencies set to null + final Callable func1 = () -> value1; + final Binding binding1 = f.create(func1, (Observable[])null); + + f.check(value1, binding1.getValue()); + assertTrue(binding1.getDependencies().isEmpty()); + binding1.dispose(); + + // func throws exception, dependencies set to empty array + final Callable func2 = () -> { + throw new Exception(); + }; + final Binding binding2 = f.create(func2, new Observable [0]); + + f.check(defaultValue, binding2.getValue()); + log.check(java.util.logging.Level.WARNING, Exception.class); + assertTrue(binding2.getDependencies().isEmpty()); + binding2.dispose(); + } + + @Test + public void testOneDependency() { + final Callable func = () -> p0.getValue(); + final Binding binding = f.create(func, p0); + + f.check(p0.getValue(), binding.getValue()); + assertEquals(binding.getDependencies(), Arrays.asList(p0)); + p0.setValue(value1); + f.check(p0.getValue(), binding.getValue()); + binding.dispose(); + } + + @Test + public void testCreateBoolean_TwoDependencies() { + final Callable func = () -> p0.getValue(); + final Binding binding = f.create(func, p0, p1); + + f.check(p0.getValue(), binding.getValue()); + assertTrue(binding.getDependencies().equals(Arrays.asList(p0, p1)) || binding.getDependencies().equals((Arrays.asList(p1, p0)))); + p0.setValue(value1); + f.check(p0.getValue(), binding.getValue()); + binding.dispose(); + } + + @Parameterized.Parameters + public static Collection parameters() { + return Arrays.asList(new Object[][] { + { + new SimpleBooleanProperty(), new SimpleBooleanProperty(), + new Functions() { + @Override + public Binding create(Callable func, Observable... dependencies) { + return Bindings.createBooleanBinding(func, dependencies); + } + + @Override + public void check(Boolean value0, Boolean value1) { + assertEquals(value0, value1); + } + }, + true, false, false + }, + { + new SimpleDoubleProperty(), new SimpleDoubleProperty(), + new Functions() { + @Override + public Binding create(Callable func, Observable... dependencies) { + return Bindings.createDoubleBinding(func, dependencies); + } + + @Override + public void check(Number value0, Number value1) { + assertEquals(value0.doubleValue(), value1.doubleValue(), EPSILON_DOUBLE); + } + }, + Math.PI, -Math.E, 0.0 + }, + { + new SimpleFloatProperty(), new SimpleFloatProperty(), + new Functions() { + @Override + public Binding create(Callable func, Observable... dependencies) { + return Bindings.createFloatBinding(func, dependencies); + } + + @Override + public void check(Number value0, Number value1) { + assertEquals(value0.floatValue(), value1.floatValue(), EPSILON_FLOAT); + } + }, + (float)Math.PI, (float)-Math.E, 0.0f + }, + { + new SimpleIntegerProperty(), new SimpleIntegerProperty(), + new Functions() { + @Override + public Binding create(Callable func, Observable... dependencies) { + return Bindings.createIntegerBinding(func, dependencies); + } + + @Override + public void check(Number value0, Number value1) { + assertEquals(value0.intValue(), value1.intValue()); + } + }, + Integer.MAX_VALUE, Integer.MIN_VALUE, 0 + }, + { + new SimpleLongProperty(), new SimpleLongProperty(), + new Functions() { + @Override + public Binding create(Callable func, Observable... dependencies) { + return Bindings.createLongBinding(func, dependencies); + } + + @Override + public void check(Number value0, Number value1) { + assertEquals(value0.longValue(), value1.longValue()); + } + }, + Long.MAX_VALUE, Long.MIN_VALUE, 0L + }, + { + new SimpleObjectProperty(), new SimpleObjectProperty(), + new Functions() { + @Override + public Binding create(Callable func, Observable... dependencies) { + return Bindings.createObjectBinding(func, dependencies); + } + + @Override + public void check(Object value0, Object value1) { + assertEquals(value0, value1); + } + }, + new Object(), new Object(), null + }, + { + new SimpleStringProperty(), new SimpleStringProperty(), + new Functions() { + @Override + public Binding create(Callable func, Observable... dependencies) { + return Bindings.createStringBinding(func, dependencies); + } + + @Override + public void check(String value0, String value1) { + assertEquals(value0, value1); + } + }, + "Hello World", "Goodbye World", "" + }, + }); + } +} --- old/modules/base/src/test/java/javafx/binding/BindingsEqualsTest.java 2015-08-31 10:24:25.353216823 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,1347 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; -import java.util.Collection; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.binding.Bindings; -import javafx.beans.binding.BooleanBinding; -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.FloatProperty; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.LongProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleLongProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; -import javafx.beans.value.*; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -@RunWith(Parameterized.class) -public class BindingsEqualsTest { - - private static final float EPSILON_FLOAT = 1e-5f; - private static final double EPSILON_DOUBLE = 1e-10; - - public static interface Functions { - BooleanBinding generateExpressionExpression(Object op1, Object op2); - BooleanBinding generateExpressionPrimitive(Object op1, T op2); - BooleanBinding generatePrimitiveExpression(T op1, Object op2); - void setOp1(T value); - void setOp2(T value); - void check(T op1, T op2, BooleanBinding exp); - } - - private final ObservableValue op1; - private final ObservableValue op2; - private final Functions func; - private final T[] v; - private InvalidationListenerMock observer; - - public BindingsEqualsTest(ObservableValue op1, ObservableValue op2, Functions func, T... v) { - this.op1 = op1; - this.op2 = op2; - this.func = func; - this.v = v; - } - - private static String makeSafe(String value) { - return value == null? "" : value; - } - - @Before - public void setUp() { - func.setOp1(v[0]); - func.setOp2(v[1]); - observer = new InvalidationListenerMock(); - } - - @Test - public void test_Expression_Expression() { - final BooleanBinding binding = func.generateExpressionExpression(op1, op2); - binding.addListener(observer); - - // check initial value - func.check(v[0], v[1], binding); - DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); - - // change first operand - observer.reset(); - func.setOp1(v[1]); - func.check(v[1], v[1], binding); - observer.check(binding, 1); - - // change second operand - func.setOp2(v[0]); - func.check(v[1], v[0], binding); - observer.check(binding, 1); - - // change both operands - func.setOp1(v[0]); - func.setOp2(v[1]); - func.check(v[0], v[1], binding); - observer.check(binding, 1); - } - - @Test - public void test_Self() { - // using same FloatValue twice - final BooleanBinding binding = func.generateExpressionExpression(op1, op1); - binding.addListener(observer); - - // check initial value - func.check(v[0], v[0], binding); - - // change value - func.setOp1(v[1]); - func.check(v[1], v[1], binding); - observer.check(binding, 1); - } - - @Test(expected=NullPointerException.class) - public void test_null_Expression() { - func.generateExpressionExpression(null, op1); - } - - @Test(expected=NullPointerException.class) - public void test_Expression_null() { - func.generateExpressionExpression(op1, null); - } - - @Test - public void test_Expression_Primitive() { - final BooleanBinding binding = func.generateExpressionPrimitive(op1, v[1]); - binding.addListener(observer); - - // check initial value - func.check(v[0], v[1], binding); - DependencyUtils.checkDependencies(binding.getDependencies(), op1); - - // change first operand - observer.reset(); - func.setOp1(v[1]); - func.check(v[1], v[1], binding); - observer.check(binding, 1); - - // change to highest value - func.setOp1(v[2]); - func.check(v[2], v[1], binding); - observer.check(binding, 1); - } - - @Test(expected=NullPointerException.class) - public void test_null_Primitive() { - func.generateExpressionPrimitive(null, v[0]); - } - - @Test - public void test_Primitive_Expression() { - final BooleanBinding binding = func.generatePrimitiveExpression(v[1], op1); - binding.addListener(observer); - - // check initial value - func.check(v[1], v[0], binding); - DependencyUtils.checkDependencies(binding.getDependencies(), op1); - - // change first operand - observer.reset(); - func.setOp1(v[1]); - func.check(v[1], v[1], binding); - observer.check(binding, 1); - - // change to highest value - func.setOp1(v[2]); - func.check(v[1], v[2], binding); - observer.check(binding, 1); - } - - @Test(expected=NullPointerException.class) - public void test_Primitive_null() { - func.generatePrimitiveExpression(v[0], null); - } - - @Parameterized.Parameters - public static Collection parameters() { - final FloatProperty float1 = new SimpleFloatProperty(); - final FloatProperty float2 = new SimpleFloatProperty(); - final Float[] floatData = new Float[] {-EPSILON_FLOAT, 0.0f, EPSILON_FLOAT}; - - final DoubleProperty double1 = new SimpleDoubleProperty(); - final DoubleProperty double2 = new SimpleDoubleProperty(); - final Double[] doubleData = new Double[] {-EPSILON_DOUBLE, 0.0, EPSILON_DOUBLE}; - - final IntegerProperty int1 = new SimpleIntegerProperty(); - final IntegerProperty int2 = new SimpleIntegerProperty(); - final Integer[] integerData = new Integer[] {-1, 0, 1}; - - final LongProperty long1 = new SimpleLongProperty(); - final LongProperty long2 = new SimpleLongProperty(); - final Long[] longData = new Long[] {-1L, 0L, 1L}; - - final StringProperty string1 = new SimpleStringProperty(); - final StringProperty string2 = new SimpleStringProperty(); - final String[] stringData = new String[] {null, "Hello", "Hello World"}; - final String[] ciStringData = new String[] {null, "hello", "HELLO"}; - - final ObjectProperty object1 = new SimpleObjectProperty(); - final ObjectProperty object2 = new SimpleObjectProperty(); - final Object[] objectData = new Object[] {new Object(), new Object(), new Object()}; - - return Arrays.asList(new Object[][] { - { - float1, float2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.equal((ObservableFloatValue)op1, (ObservableFloatValue)op2, EPSILON_FLOAT); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.equal((ObservableFloatValue)op1, op2.floatValue(), EPSILON_FLOAT); - } - @Override - public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.equal(op1.floatValue(), (ObservableFloatValue)op2, EPSILON_FLOAT); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, BooleanBinding exp) { - assertEquals(Math.abs(op1 - op2) <= EPSILON_FLOAT, exp.get()); - } - }, - floatData - }, - { - float1, float2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.notEqual((ObservableFloatValue)op1, (ObservableFloatValue)op2, EPSILON_FLOAT); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.notEqual((ObservableFloatValue)op1, op2.floatValue(), EPSILON_FLOAT); - } - @Override - public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.notEqual(op1.floatValue(), (ObservableFloatValue)op2, EPSILON_FLOAT); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, BooleanBinding exp) { - assertEquals(Math.abs(op1 - op2) > EPSILON_FLOAT, exp.get()); - } - }, - floatData - }, - { - float1, float2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.greaterThan((ObservableFloatValue)op1, (ObservableFloatValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.greaterThan((ObservableFloatValue)op1, op2.floatValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.greaterThan(op1.floatValue(), (ObservableFloatValue)op2); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, BooleanBinding exp) { - assertEquals(op1 > op2, exp.get()); - } - }, - floatData - }, - { - float1, float2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.lessThan((ObservableFloatValue)op1, (ObservableFloatValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.lessThan((ObservableFloatValue)op1, op2.floatValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.lessThan(op1.floatValue(), (ObservableFloatValue)op2); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, BooleanBinding exp) { - assertEquals(op1 < op2, exp.get()); - } - }, - floatData - }, - { - float1, float2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.greaterThanOrEqual((ObservableFloatValue)op1, (ObservableFloatValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.greaterThanOrEqual((ObservableFloatValue)op1, op2.floatValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.greaterThanOrEqual(op1.floatValue(), (ObservableFloatValue)op2); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, BooleanBinding exp) { - assertEquals(op1 >= op2, exp.get()); - } - }, - floatData - }, - { - float1, float2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.lessThanOrEqual((ObservableFloatValue)op1, (ObservableFloatValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.lessThanOrEqual((ObservableFloatValue)op1, op2.floatValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.lessThanOrEqual(op1.floatValue(), (ObservableFloatValue)op2); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, BooleanBinding exp) { - assertEquals(op1 <= op2, exp.get()); - } - }, - floatData - }, - - - - // double - { - double1, double2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.equal((ObservableDoubleValue)op1, (ObservableDoubleValue)op2, EPSILON_DOUBLE); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.equal((ObservableDoubleValue)op1, op2.doubleValue(), EPSILON_DOUBLE); - } - @Override - public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.equal(op1.doubleValue(), (ObservableDoubleValue)op2, EPSILON_DOUBLE); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, BooleanBinding exp) { - assertEquals(Math.abs(op1 - op2) <= EPSILON_DOUBLE, exp.get()); - } - }, - doubleData - }, - { - double1, double2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.notEqual((ObservableDoubleValue)op1, (ObservableDoubleValue)op2, EPSILON_DOUBLE); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.notEqual((ObservableDoubleValue)op1, op2.doubleValue(), EPSILON_DOUBLE); - } - @Override - public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.notEqual(op1.doubleValue(), (ObservableDoubleValue)op2, EPSILON_DOUBLE); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, BooleanBinding exp) { - assertEquals(Math.abs(op1 - op2) > EPSILON_DOUBLE, exp.get()); - } - }, - doubleData - }, - { - double1, double2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.greaterThan((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.greaterThan((ObservableDoubleValue)op1, op2.doubleValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.greaterThan(op1.doubleValue(), (ObservableDoubleValue)op2); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, BooleanBinding exp) { - assertEquals(op1 > op2, exp.get()); - } - }, - doubleData - }, - { - double1, double2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.lessThan((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.lessThan((ObservableDoubleValue)op1, op2.doubleValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.lessThan(op1.doubleValue(), (ObservableDoubleValue)op2); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, BooleanBinding exp) { - assertEquals(op1 < op2, exp.get()); - } - }, - doubleData - }, - { - double1, double2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.greaterThanOrEqual((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.greaterThanOrEqual((ObservableDoubleValue)op1, op2.doubleValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.greaterThanOrEqual(op1.doubleValue(), (ObservableDoubleValue)op2); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, BooleanBinding exp) { - assertEquals(op1 >= op2, exp.get()); - } - }, - doubleData - }, - { - double1, double2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.lessThanOrEqual((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.lessThanOrEqual((ObservableDoubleValue)op1, op2.doubleValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.lessThanOrEqual(op1.doubleValue(), (ObservableDoubleValue)op2); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, BooleanBinding exp) { - assertEquals(op1 <= op2, exp.get()); - } - }, - doubleData - }, - - - - // integer - { - int1, int2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.equal((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.equal((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.equal(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, BooleanBinding exp) { - assertEquals(op1.equals(op2), exp.get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.equal((ObservableIntegerValue)op1, (ObservableIntegerValue)op2, 1); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.equal((ObservableIntegerValue)op1, op2.intValue(), 1); - } - @Override - public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.equal(op1.intValue(), (ObservableIntegerValue)op2, 1); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, BooleanBinding exp) { - assertEquals(Math.abs(op1 - op2) <= 1, exp.get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.notEqual((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.notEqual((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.notEqual(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, BooleanBinding exp) { - assertEquals(!op1.equals(op2), exp.get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.notEqual((ObservableIntegerValue)op1, (ObservableIntegerValue)op2, 1); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.notEqual((ObservableIntegerValue)op1, op2.intValue(), 1); - } - @Override - public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.notEqual(op1.intValue(), (ObservableIntegerValue)op2, 1); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, BooleanBinding exp) { - assertEquals(Math.abs(op1 - op2) > 1, exp.get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.greaterThan((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.greaterThan((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.greaterThan(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, BooleanBinding exp) { - assertEquals(op1 > op2, exp.get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.lessThan((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.lessThan((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.lessThan(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, BooleanBinding exp) { - assertEquals(op1 < op2, exp.get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.greaterThanOrEqual((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.greaterThanOrEqual((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.greaterThanOrEqual(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, BooleanBinding exp) { - assertEquals(op1 >= op2, exp.get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.lessThanOrEqual((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.lessThanOrEqual((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.lessThanOrEqual(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, BooleanBinding exp) { - assertEquals(op1 <= op2, exp.get()); - } - }, - integerData - }, - - - - // long - { - long1, long2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.equal((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.equal((ObservableLongValue)op1, op2.longValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.equal(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, BooleanBinding exp) { - assertEquals(op1.equals(op2), exp.get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.equal((ObservableLongValue)op1, (ObservableLongValue)op2, 1); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.equal((ObservableLongValue)op1, op2.longValue(), 1); - } - @Override - public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.equal(op1.longValue(), (ObservableLongValue)op2, 1); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, BooleanBinding exp) { - assertEquals(Math.abs(op1 - op2) <= 1, exp.get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.notEqual((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.notEqual((ObservableLongValue)op1, op2.longValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.notEqual(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, BooleanBinding exp) { - assertEquals(!op1.equals(op2), exp.get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.notEqual((ObservableLongValue)op1, (ObservableLongValue)op2, 1); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.notEqual((ObservableLongValue)op1, op2.longValue(), 1); - } - @Override - public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.notEqual(op1.longValue(), (ObservableLongValue)op2, 1); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, BooleanBinding exp) { - assertEquals(Math.abs(op1 - op2) > 1, exp.get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.greaterThan((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.greaterThan((ObservableLongValue)op1, op2.longValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.greaterThan(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, BooleanBinding exp) { - assertEquals(op1 > op2, exp.get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.lessThan((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.lessThan((ObservableLongValue)op1, op2.longValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.lessThan(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, BooleanBinding exp) { - assertEquals(op1 < op2, exp.get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.greaterThanOrEqual((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.greaterThanOrEqual((ObservableLongValue)op1, op2.longValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.greaterThanOrEqual(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, BooleanBinding exp) { - assertEquals(op1 >= op2, exp.get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.lessThanOrEqual((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.lessThanOrEqual((ObservableLongValue)op1, op2.longValue()); - } - @Override - public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.lessThanOrEqual(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, BooleanBinding exp) { - assertEquals(op1 <= op2, exp.get()); - } - }, - longData - }, - - - - // String - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.equal((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.equal((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.equal(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(makeSafe(op1).equals(makeSafe(op2)), exp.get()); - } - }, - stringData - }, - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.equal((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.equal((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.equal(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(makeSafe(op1).equals(makeSafe(op2)), exp.get()); - } - }, - ciStringData - }, - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.equalIgnoreCase((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.equalIgnoreCase((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.equalIgnoreCase(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(makeSafe(op1).equalsIgnoreCase(makeSafe(op2)), exp.get()); - } - }, - stringData - }, - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.equalIgnoreCase((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.equalIgnoreCase((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.equalIgnoreCase(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(makeSafe(op1).equalsIgnoreCase(makeSafe(op2)), exp.get()); - } - }, - ciStringData - }, - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.notEqual((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.notEqual((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.notEqual(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(!makeSafe(op1).equals(makeSafe(op2)), exp.get()); - } - }, - stringData - }, - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.notEqual((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.notEqual((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.notEqual(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(!makeSafe(op1).equals(makeSafe(op2)), exp.get()); - } - }, - ciStringData - }, - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.notEqualIgnoreCase((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.notEqualIgnoreCase((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.notEqualIgnoreCase(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(!makeSafe(op1).equalsIgnoreCase(makeSafe(op2)), exp.get()); - } - }, - stringData - }, - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.notEqualIgnoreCase((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.notEqualIgnoreCase((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.notEqualIgnoreCase(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(!makeSafe(op1).equalsIgnoreCase(makeSafe(op2)), exp.get()); - } - }, - ciStringData - }, - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.greaterThan((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.greaterThan((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.greaterThan(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(makeSafe(op1).compareTo(makeSafe(op2)) > 0, exp.get()); - } - }, - stringData - }, - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.lessThan((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.lessThan((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.lessThan(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(makeSafe(op1).compareTo(makeSafe(op2)) < 0, exp.get()); - } - }, - stringData - }, - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.greaterThanOrEqual((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.greaterThanOrEqual((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.greaterThanOrEqual(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(makeSafe(op1).compareTo(makeSafe(op2)) >= 0, exp.get()); - } - }, - stringData - }, - { - string1, string2, - new Functions() { - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.lessThanOrEqual((ObservableStringValue)op1, (ObservableStringValue)op2); - } - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { - return Bindings.lessThanOrEqual((ObservableStringValue)op1, op2); - } - @Override - public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { - return Bindings.lessThanOrEqual(op1, (ObservableStringValue)op2); - } - @Override - public void setOp1(String value) {string1.set(value);} - @Override - public void setOp2(String value) {string2.set(value);} - @Override - public void check(String op1, String op2, BooleanBinding exp) { - assertEquals(makeSafe(op1).compareTo(makeSafe(op2)) <= 0, exp.get()); - } - }, - stringData - }, - - - - // Object - { - object1, object2, - new Functions() { - @SuppressWarnings("unchecked") - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.equal((ObservableObjectValue)op1, (ObservableObjectValue)op2); - } - @SuppressWarnings("unchecked") - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Object op2) { - return Bindings.equal((ObservableObjectValue)op1, op2); - } - @SuppressWarnings("unchecked") - @Override - public BooleanBinding generatePrimitiveExpression(Object op1, Object op2) { - return Bindings.equal(op1, (ObservableObjectValue)op2); - } - @Override - public void setOp1(Object value) {object1.set(value);} - @Override - public void setOp2(Object value) {object2.set(value);} - @Override - public void check(Object op1, Object op2, BooleanBinding exp) { - assertEquals(op1.equals(op2), exp.get()); - } - }, - objectData - }, - { - object1, object2, - new Functions() { - @SuppressWarnings("unchecked") - @Override - public BooleanBinding generateExpressionExpression(Object op1, Object op2) { - return Bindings.notEqual((ObservableObjectValue)op1, (ObservableObjectValue)op2); - } - @SuppressWarnings("unchecked") - @Override - public BooleanBinding generateExpressionPrimitive(Object op1, Object op2) { - return Bindings.notEqual((ObservableObjectValue)op1, op2); - } - @SuppressWarnings("unchecked") - @Override - public BooleanBinding generatePrimitiveExpression(Object op1, Object op2) { - return Bindings.notEqual(op1, (ObservableObjectValue)op2); - } - @Override - public void setOp1(Object value) {object1.set(value);} - @Override - public void setOp2(Object value) {object2.set(value);} - @Override - public void check(Object op1, Object op2, BooleanBinding exp) { - assertEquals(!op1.equals(op2), exp.get()); - } - }, - objectData - }, - }); - }; - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/BindingsEqualsTest.java 2015-08-31 10:24:25.221216824 -0400 @@ -0,0 +1,1347 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.Collection; + +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.binding.Bindings; +import javafx.beans.binding.BooleanBinding; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.FloatProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.LongProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.beans.value.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class BindingsEqualsTest { + + private static final float EPSILON_FLOAT = 1e-5f; + private static final double EPSILON_DOUBLE = 1e-10; + + public static interface Functions { + BooleanBinding generateExpressionExpression(Object op1, Object op2); + BooleanBinding generateExpressionPrimitive(Object op1, T op2); + BooleanBinding generatePrimitiveExpression(T op1, Object op2); + void setOp1(T value); + void setOp2(T value); + void check(T op1, T op2, BooleanBinding exp); + } + + private final ObservableValue op1; + private final ObservableValue op2; + private final Functions func; + private final T[] v; + private InvalidationListenerMock observer; + + public BindingsEqualsTest(ObservableValue op1, ObservableValue op2, Functions func, T... v) { + this.op1 = op1; + this.op2 = op2; + this.func = func; + this.v = v; + } + + private static String makeSafe(String value) { + return value == null? "" : value; + } + + @Before + public void setUp() { + func.setOp1(v[0]); + func.setOp2(v[1]); + observer = new InvalidationListenerMock(); + } + + @Test + public void test_Expression_Expression() { + final BooleanBinding binding = func.generateExpressionExpression(op1, op2); + binding.addListener(observer); + + // check initial value + func.check(v[0], v[1], binding); + DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); + + // change first operand + observer.reset(); + func.setOp1(v[1]); + func.check(v[1], v[1], binding); + observer.check(binding, 1); + + // change second operand + func.setOp2(v[0]); + func.check(v[1], v[0], binding); + observer.check(binding, 1); + + // change both operands + func.setOp1(v[0]); + func.setOp2(v[1]); + func.check(v[0], v[1], binding); + observer.check(binding, 1); + } + + @Test + public void test_Self() { + // using same FloatValue twice + final BooleanBinding binding = func.generateExpressionExpression(op1, op1); + binding.addListener(observer); + + // check initial value + func.check(v[0], v[0], binding); + + // change value + func.setOp1(v[1]); + func.check(v[1], v[1], binding); + observer.check(binding, 1); + } + + @Test(expected=NullPointerException.class) + public void test_null_Expression() { + func.generateExpressionExpression(null, op1); + } + + @Test(expected=NullPointerException.class) + public void test_Expression_null() { + func.generateExpressionExpression(op1, null); + } + + @Test + public void test_Expression_Primitive() { + final BooleanBinding binding = func.generateExpressionPrimitive(op1, v[1]); + binding.addListener(observer); + + // check initial value + func.check(v[0], v[1], binding); + DependencyUtils.checkDependencies(binding.getDependencies(), op1); + + // change first operand + observer.reset(); + func.setOp1(v[1]); + func.check(v[1], v[1], binding); + observer.check(binding, 1); + + // change to highest value + func.setOp1(v[2]); + func.check(v[2], v[1], binding); + observer.check(binding, 1); + } + + @Test(expected=NullPointerException.class) + public void test_null_Primitive() { + func.generateExpressionPrimitive(null, v[0]); + } + + @Test + public void test_Primitive_Expression() { + final BooleanBinding binding = func.generatePrimitiveExpression(v[1], op1); + binding.addListener(observer); + + // check initial value + func.check(v[1], v[0], binding); + DependencyUtils.checkDependencies(binding.getDependencies(), op1); + + // change first operand + observer.reset(); + func.setOp1(v[1]); + func.check(v[1], v[1], binding); + observer.check(binding, 1); + + // change to highest value + func.setOp1(v[2]); + func.check(v[1], v[2], binding); + observer.check(binding, 1); + } + + @Test(expected=NullPointerException.class) + public void test_Primitive_null() { + func.generatePrimitiveExpression(v[0], null); + } + + @Parameterized.Parameters + public static Collection parameters() { + final FloatProperty float1 = new SimpleFloatProperty(); + final FloatProperty float2 = new SimpleFloatProperty(); + final Float[] floatData = new Float[] {-EPSILON_FLOAT, 0.0f, EPSILON_FLOAT}; + + final DoubleProperty double1 = new SimpleDoubleProperty(); + final DoubleProperty double2 = new SimpleDoubleProperty(); + final Double[] doubleData = new Double[] {-EPSILON_DOUBLE, 0.0, EPSILON_DOUBLE}; + + final IntegerProperty int1 = new SimpleIntegerProperty(); + final IntegerProperty int2 = new SimpleIntegerProperty(); + final Integer[] integerData = new Integer[] {-1, 0, 1}; + + final LongProperty long1 = new SimpleLongProperty(); + final LongProperty long2 = new SimpleLongProperty(); + final Long[] longData = new Long[] {-1L, 0L, 1L}; + + final StringProperty string1 = new SimpleStringProperty(); + final StringProperty string2 = new SimpleStringProperty(); + final String[] stringData = new String[] {null, "Hello", "Hello World"}; + final String[] ciStringData = new String[] {null, "hello", "HELLO"}; + + final ObjectProperty object1 = new SimpleObjectProperty(); + final ObjectProperty object2 = new SimpleObjectProperty(); + final Object[] objectData = new Object[] {new Object(), new Object(), new Object()}; + + return Arrays.asList(new Object[][] { + { + float1, float2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.equal((ObservableFloatValue)op1, (ObservableFloatValue)op2, EPSILON_FLOAT); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.equal((ObservableFloatValue)op1, op2.floatValue(), EPSILON_FLOAT); + } + @Override + public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.equal(op1.floatValue(), (ObservableFloatValue)op2, EPSILON_FLOAT); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, BooleanBinding exp) { + assertEquals(Math.abs(op1 - op2) <= EPSILON_FLOAT, exp.get()); + } + }, + floatData + }, + { + float1, float2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.notEqual((ObservableFloatValue)op1, (ObservableFloatValue)op2, EPSILON_FLOAT); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.notEqual((ObservableFloatValue)op1, op2.floatValue(), EPSILON_FLOAT); + } + @Override + public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.notEqual(op1.floatValue(), (ObservableFloatValue)op2, EPSILON_FLOAT); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, BooleanBinding exp) { + assertEquals(Math.abs(op1 - op2) > EPSILON_FLOAT, exp.get()); + } + }, + floatData + }, + { + float1, float2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.greaterThan((ObservableFloatValue)op1, (ObservableFloatValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.greaterThan((ObservableFloatValue)op1, op2.floatValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.greaterThan(op1.floatValue(), (ObservableFloatValue)op2); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, BooleanBinding exp) { + assertEquals(op1 > op2, exp.get()); + } + }, + floatData + }, + { + float1, float2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.lessThan((ObservableFloatValue)op1, (ObservableFloatValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.lessThan((ObservableFloatValue)op1, op2.floatValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.lessThan(op1.floatValue(), (ObservableFloatValue)op2); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, BooleanBinding exp) { + assertEquals(op1 < op2, exp.get()); + } + }, + floatData + }, + { + float1, float2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.greaterThanOrEqual((ObservableFloatValue)op1, (ObservableFloatValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.greaterThanOrEqual((ObservableFloatValue)op1, op2.floatValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.greaterThanOrEqual(op1.floatValue(), (ObservableFloatValue)op2); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, BooleanBinding exp) { + assertEquals(op1 >= op2, exp.get()); + } + }, + floatData + }, + { + float1, float2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.lessThanOrEqual((ObservableFloatValue)op1, (ObservableFloatValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.lessThanOrEqual((ObservableFloatValue)op1, op2.floatValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.lessThanOrEqual(op1.floatValue(), (ObservableFloatValue)op2); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, BooleanBinding exp) { + assertEquals(op1 <= op2, exp.get()); + } + }, + floatData + }, + + + + // double + { + double1, double2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.equal((ObservableDoubleValue)op1, (ObservableDoubleValue)op2, EPSILON_DOUBLE); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.equal((ObservableDoubleValue)op1, op2.doubleValue(), EPSILON_DOUBLE); + } + @Override + public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.equal(op1.doubleValue(), (ObservableDoubleValue)op2, EPSILON_DOUBLE); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, BooleanBinding exp) { + assertEquals(Math.abs(op1 - op2) <= EPSILON_DOUBLE, exp.get()); + } + }, + doubleData + }, + { + double1, double2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.notEqual((ObservableDoubleValue)op1, (ObservableDoubleValue)op2, EPSILON_DOUBLE); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.notEqual((ObservableDoubleValue)op1, op2.doubleValue(), EPSILON_DOUBLE); + } + @Override + public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.notEqual(op1.doubleValue(), (ObservableDoubleValue)op2, EPSILON_DOUBLE); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, BooleanBinding exp) { + assertEquals(Math.abs(op1 - op2) > EPSILON_DOUBLE, exp.get()); + } + }, + doubleData + }, + { + double1, double2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.greaterThan((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.greaterThan((ObservableDoubleValue)op1, op2.doubleValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.greaterThan(op1.doubleValue(), (ObservableDoubleValue)op2); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, BooleanBinding exp) { + assertEquals(op1 > op2, exp.get()); + } + }, + doubleData + }, + { + double1, double2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.lessThan((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.lessThan((ObservableDoubleValue)op1, op2.doubleValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.lessThan(op1.doubleValue(), (ObservableDoubleValue)op2); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, BooleanBinding exp) { + assertEquals(op1 < op2, exp.get()); + } + }, + doubleData + }, + { + double1, double2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.greaterThanOrEqual((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.greaterThanOrEqual((ObservableDoubleValue)op1, op2.doubleValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.greaterThanOrEqual(op1.doubleValue(), (ObservableDoubleValue)op2); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, BooleanBinding exp) { + assertEquals(op1 >= op2, exp.get()); + } + }, + doubleData + }, + { + double1, double2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.lessThanOrEqual((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.lessThanOrEqual((ObservableDoubleValue)op1, op2.doubleValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.lessThanOrEqual(op1.doubleValue(), (ObservableDoubleValue)op2); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, BooleanBinding exp) { + assertEquals(op1 <= op2, exp.get()); + } + }, + doubleData + }, + + + + // integer + { + int1, int2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.equal((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.equal((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.equal(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, BooleanBinding exp) { + assertEquals(op1.equals(op2), exp.get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.equal((ObservableIntegerValue)op1, (ObservableIntegerValue)op2, 1); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.equal((ObservableIntegerValue)op1, op2.intValue(), 1); + } + @Override + public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.equal(op1.intValue(), (ObservableIntegerValue)op2, 1); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, BooleanBinding exp) { + assertEquals(Math.abs(op1 - op2) <= 1, exp.get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.notEqual((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.notEqual((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.notEqual(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, BooleanBinding exp) { + assertEquals(!op1.equals(op2), exp.get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.notEqual((ObservableIntegerValue)op1, (ObservableIntegerValue)op2, 1); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.notEqual((ObservableIntegerValue)op1, op2.intValue(), 1); + } + @Override + public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.notEqual(op1.intValue(), (ObservableIntegerValue)op2, 1); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, BooleanBinding exp) { + assertEquals(Math.abs(op1 - op2) > 1, exp.get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.greaterThan((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.greaterThan((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.greaterThan(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, BooleanBinding exp) { + assertEquals(op1 > op2, exp.get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.lessThan((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.lessThan((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.lessThan(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, BooleanBinding exp) { + assertEquals(op1 < op2, exp.get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.greaterThanOrEqual((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.greaterThanOrEqual((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.greaterThanOrEqual(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, BooleanBinding exp) { + assertEquals(op1 >= op2, exp.get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.lessThanOrEqual((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.lessThanOrEqual((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.lessThanOrEqual(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, BooleanBinding exp) { + assertEquals(op1 <= op2, exp.get()); + } + }, + integerData + }, + + + + // long + { + long1, long2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.equal((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.equal((ObservableLongValue)op1, op2.longValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.equal(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, BooleanBinding exp) { + assertEquals(op1.equals(op2), exp.get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.equal((ObservableLongValue)op1, (ObservableLongValue)op2, 1); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.equal((ObservableLongValue)op1, op2.longValue(), 1); + } + @Override + public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.equal(op1.longValue(), (ObservableLongValue)op2, 1); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, BooleanBinding exp) { + assertEquals(Math.abs(op1 - op2) <= 1, exp.get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.notEqual((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.notEqual((ObservableLongValue)op1, op2.longValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.notEqual(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, BooleanBinding exp) { + assertEquals(!op1.equals(op2), exp.get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.notEqual((ObservableLongValue)op1, (ObservableLongValue)op2, 1); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.notEqual((ObservableLongValue)op1, op2.longValue(), 1); + } + @Override + public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.notEqual(op1.longValue(), (ObservableLongValue)op2, 1); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, BooleanBinding exp) { + assertEquals(Math.abs(op1 - op2) > 1, exp.get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.greaterThan((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.greaterThan((ObservableLongValue)op1, op2.longValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.greaterThan(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, BooleanBinding exp) { + assertEquals(op1 > op2, exp.get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.lessThan((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.lessThan((ObservableLongValue)op1, op2.longValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.lessThan(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, BooleanBinding exp) { + assertEquals(op1 < op2, exp.get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.greaterThanOrEqual((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.greaterThanOrEqual((ObservableLongValue)op1, op2.longValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.greaterThanOrEqual(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, BooleanBinding exp) { + assertEquals(op1 >= op2, exp.get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.lessThanOrEqual((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.lessThanOrEqual((ObservableLongValue)op1, op2.longValue()); + } + @Override + public BooleanBinding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.lessThanOrEqual(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, BooleanBinding exp) { + assertEquals(op1 <= op2, exp.get()); + } + }, + longData + }, + + + + // String + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.equal((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.equal((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.equal(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(makeSafe(op1).equals(makeSafe(op2)), exp.get()); + } + }, + stringData + }, + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.equal((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.equal((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.equal(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(makeSafe(op1).equals(makeSafe(op2)), exp.get()); + } + }, + ciStringData + }, + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.equalIgnoreCase((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.equalIgnoreCase((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.equalIgnoreCase(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(makeSafe(op1).equalsIgnoreCase(makeSafe(op2)), exp.get()); + } + }, + stringData + }, + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.equalIgnoreCase((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.equalIgnoreCase((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.equalIgnoreCase(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(makeSafe(op1).equalsIgnoreCase(makeSafe(op2)), exp.get()); + } + }, + ciStringData + }, + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.notEqual((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.notEqual((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.notEqual(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(!makeSafe(op1).equals(makeSafe(op2)), exp.get()); + } + }, + stringData + }, + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.notEqual((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.notEqual((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.notEqual(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(!makeSafe(op1).equals(makeSafe(op2)), exp.get()); + } + }, + ciStringData + }, + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.notEqualIgnoreCase((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.notEqualIgnoreCase((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.notEqualIgnoreCase(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(!makeSafe(op1).equalsIgnoreCase(makeSafe(op2)), exp.get()); + } + }, + stringData + }, + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.notEqualIgnoreCase((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.notEqualIgnoreCase((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.notEqualIgnoreCase(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(!makeSafe(op1).equalsIgnoreCase(makeSafe(op2)), exp.get()); + } + }, + ciStringData + }, + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.greaterThan((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.greaterThan((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.greaterThan(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(makeSafe(op1).compareTo(makeSafe(op2)) > 0, exp.get()); + } + }, + stringData + }, + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.lessThan((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.lessThan((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.lessThan(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(makeSafe(op1).compareTo(makeSafe(op2)) < 0, exp.get()); + } + }, + stringData + }, + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.greaterThanOrEqual((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.greaterThanOrEqual((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.greaterThanOrEqual(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(makeSafe(op1).compareTo(makeSafe(op2)) >= 0, exp.get()); + } + }, + stringData + }, + { + string1, string2, + new Functions() { + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.lessThanOrEqual((ObservableStringValue)op1, (ObservableStringValue)op2); + } + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, String op2) { + return Bindings.lessThanOrEqual((ObservableStringValue)op1, op2); + } + @Override + public BooleanBinding generatePrimitiveExpression(String op1, Object op2) { + return Bindings.lessThanOrEqual(op1, (ObservableStringValue)op2); + } + @Override + public void setOp1(String value) {string1.set(value);} + @Override + public void setOp2(String value) {string2.set(value);} + @Override + public void check(String op1, String op2, BooleanBinding exp) { + assertEquals(makeSafe(op1).compareTo(makeSafe(op2)) <= 0, exp.get()); + } + }, + stringData + }, + + + + // Object + { + object1, object2, + new Functions() { + @SuppressWarnings("unchecked") + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.equal((ObservableObjectValue)op1, (ObservableObjectValue)op2); + } + @SuppressWarnings("unchecked") + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Object op2) { + return Bindings.equal((ObservableObjectValue)op1, op2); + } + @SuppressWarnings("unchecked") + @Override + public BooleanBinding generatePrimitiveExpression(Object op1, Object op2) { + return Bindings.equal(op1, (ObservableObjectValue)op2); + } + @Override + public void setOp1(Object value) {object1.set(value);} + @Override + public void setOp2(Object value) {object2.set(value);} + @Override + public void check(Object op1, Object op2, BooleanBinding exp) { + assertEquals(op1.equals(op2), exp.get()); + } + }, + objectData + }, + { + object1, object2, + new Functions() { + @SuppressWarnings("unchecked") + @Override + public BooleanBinding generateExpressionExpression(Object op1, Object op2) { + return Bindings.notEqual((ObservableObjectValue)op1, (ObservableObjectValue)op2); + } + @SuppressWarnings("unchecked") + @Override + public BooleanBinding generateExpressionPrimitive(Object op1, Object op2) { + return Bindings.notEqual((ObservableObjectValue)op1, op2); + } + @SuppressWarnings("unchecked") + @Override + public BooleanBinding generatePrimitiveExpression(Object op1, Object op2) { + return Bindings.notEqual(op1, (ObservableObjectValue)op2); + } + @Override + public void setOp1(Object value) {object1.set(value);} + @Override + public void setOp2(Object value) {object2.set(value);} + @Override + public void check(Object op1, Object op2, BooleanBinding exp) { + assertEquals(!op1.equals(op2), exp.get()); + } + }, + objectData + }, + }); + }; + +} --- old/modules/base/src/test/java/javafx/binding/BindingsIsNullTest.java 2015-08-31 10:24:25.973216816 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.binding.Bindings; -import javafx.beans.binding.BooleanBinding; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; - -import org.junit.Before; -import org.junit.Test; - -public class BindingsIsNullTest { - - private ObjectProperty oo; - private StringProperty os; - private InvalidationListenerMock observer; - - @Before - public void setUp() { - oo = new SimpleObjectProperty(); - os = new SimpleStringProperty(); - observer = new InvalidationListenerMock(); - } - - @Test - public void test_Object_IsNull() { - final BooleanBinding binding = Bindings.isNull(oo); - binding.addListener(observer); - - // check initial value - assertTrue(binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), oo); - observer.reset(); - - // change operand - oo.set(new Object()); - assertFalse(binding.get()); - observer.check(binding, 1); - - // change again - oo.set(null); - assertTrue(binding.get()); - observer.check(binding, 1); - } - - @Test - public void test_Object_IsNotNull() { - final BooleanBinding binding = Bindings.isNotNull(oo); - binding.addListener(observer); - - // check initial value - assertFalse(binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), oo); - observer.reset(); - - // change operand - oo.set(new Object()); - assertTrue(binding.get()); - observer.check(binding, 1); - - // change again - oo.set(null); - assertFalse(binding.get()); - observer.check(binding, 1); - } - - @Test - public void test_String_IsNull() { - final BooleanBinding binding = Bindings.isNull(os); - binding.addListener(observer); - - // check initial value - assertTrue(binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), os); - observer.reset(); - - // change operand - os.set("Hello World"); - assertFalse(binding.get()); - observer.check(binding, 1); - - // change again - os.set(null); - assertTrue(binding.get()); - observer.check(binding, 1); - } - - @Test - public void test_String_IsNotNull() { - final BooleanBinding binding = Bindings.isNotNull(os); - binding.addListener(observer); - - // check initial value - assertFalse(binding.get()); - DependencyUtils.checkDependencies(binding.getDependencies(), os); - observer.reset(); - - // change operand - os.set("Hello World"); - assertTrue(binding.get()); - observer.check(binding, 1); - - // change again - os.set(null); - assertFalse(binding.get()); - observer.check(binding, 1); - } - - @Test(expected=NullPointerException.class) - public void test_IsNull_NPE() { - Bindings.isNull(null); - } - - @Test(expected=NullPointerException.class) - public void test_IsNotNull_NPE() { - Bindings.isNotNull(null); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/BindingsIsNullTest.java 2015-08-31 10:24:25.841216817 -0400 @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.binding.Bindings; +import javafx.beans.binding.BooleanBinding; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +import org.junit.Before; +import org.junit.Test; + +public class BindingsIsNullTest { + + private ObjectProperty oo; + private StringProperty os; + private InvalidationListenerMock observer; + + @Before + public void setUp() { + oo = new SimpleObjectProperty(); + os = new SimpleStringProperty(); + observer = new InvalidationListenerMock(); + } + + @Test + public void test_Object_IsNull() { + final BooleanBinding binding = Bindings.isNull(oo); + binding.addListener(observer); + + // check initial value + assertTrue(binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), oo); + observer.reset(); + + // change operand + oo.set(new Object()); + assertFalse(binding.get()); + observer.check(binding, 1); + + // change again + oo.set(null); + assertTrue(binding.get()); + observer.check(binding, 1); + } + + @Test + public void test_Object_IsNotNull() { + final BooleanBinding binding = Bindings.isNotNull(oo); + binding.addListener(observer); + + // check initial value + assertFalse(binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), oo); + observer.reset(); + + // change operand + oo.set(new Object()); + assertTrue(binding.get()); + observer.check(binding, 1); + + // change again + oo.set(null); + assertFalse(binding.get()); + observer.check(binding, 1); + } + + @Test + public void test_String_IsNull() { + final BooleanBinding binding = Bindings.isNull(os); + binding.addListener(observer); + + // check initial value + assertTrue(binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), os); + observer.reset(); + + // change operand + os.set("Hello World"); + assertFalse(binding.get()); + observer.check(binding, 1); + + // change again + os.set(null); + assertTrue(binding.get()); + observer.check(binding, 1); + } + + @Test + public void test_String_IsNotNull() { + final BooleanBinding binding = Bindings.isNotNull(os); + binding.addListener(observer); + + // check initial value + assertFalse(binding.get()); + DependencyUtils.checkDependencies(binding.getDependencies(), os); + observer.reset(); + + // change operand + os.set("Hello World"); + assertTrue(binding.get()); + observer.check(binding, 1); + + // change again + os.set(null); + assertFalse(binding.get()); + observer.check(binding, 1); + } + + @Test(expected=NullPointerException.class) + public void test_IsNull_NPE() { + Bindings.isNull(null); + } + + @Test(expected=NullPointerException.class) + public void test_IsNotNull_NPE() { + Bindings.isNotNull(null); + } + +} --- old/modules/base/src/test/java/javafx/binding/BindingsListTest.java 2015-08-31 10:24:26.661216808 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,1237 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import javafx.beans.binding.*; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.ListProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleListProperty; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import com.sun.javafx.binding.ErrorLoggingUtiltity; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - */ -public class BindingsListTest { - - private static final double EPSILON_DOUBLE = 1e-12; - private static final float EPSILON_FLOAT = 1e-5f; - - private static final Object data1 = new Object(); - private static final Object data2 = new Object(); - - private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); - - private ListProperty property; - private ObservableList list1; - private ObservableList list2; - private IntegerProperty index; - - @BeforeClass - public static void setUpClass() { - log.start(); - } - - @AfterClass - public static void tearDownClass() { - log.stop(); - } - - @Before - public void setUp() { - property = new SimpleListProperty(); - list1 = FXCollections.observableArrayList(data1, data2); - list2 = FXCollections.observableArrayList(); - index = new SimpleIntegerProperty(); - } - - @Test - public void testSize() { - final IntegerBinding size = Bindings.size(property); - DependencyUtils.checkDependencies(size.getDependencies(), property); - - assertEquals(0, size.get()); - property.set(list1); - assertEquals(2, size.get()); - list1.remove(data2); - assertEquals(1, size.get()); - property.set(list2); - assertEquals(0, size.get()); - property.addAll(data2, data2); - assertEquals(2, size.get()); - property.set(null); - assertEquals(0, size.get()); - } - - @Test(expected = NullPointerException.class) - public void testSize_Null() { - Bindings.size((ObservableList) null); - } - - @Test - public void testIsEmpty() { - final BooleanBinding empty = Bindings.isEmpty(property); - DependencyUtils.checkDependencies(empty.getDependencies(), property); - - assertTrue(empty.get()); - property.set(list1); - assertFalse(empty.get()); - list1.remove(data2); - assertFalse(empty.get()); - property.set(list2); - assertTrue(empty.get()); - property.addAll(data2, data2); - assertFalse(empty.get()); - property.set(null); - assertTrue(empty.get()); - } - - @Test(expected = NullPointerException.class) - public void testIsEmpty_Null() { - Bindings.isEmpty((ObservableList) null); - } - - @Test - public void testIsNotEmpty() { - final BooleanBinding notEmpty = Bindings.isNotEmpty(property); - DependencyUtils.checkDependencies(notEmpty.getDependencies(), property); - - assertFalse(notEmpty.get()); - property.set(list1); - assertTrue(notEmpty.get()); - list1.remove(data2); - assertTrue(notEmpty.get()); - property.set(list2); - assertFalse(notEmpty.get()); - property.addAll(data2, data2); - assertTrue(notEmpty.get()); - property.set(null); - assertFalse(notEmpty.get()); - } - - @Test(expected = NullPointerException.class) - public void testIsNotEmpty_Null() { - Bindings.isNotEmpty((ObservableList) null); - } - - @Test - public void testValueAt_Constant() { - final ObjectBinding binding0 = Bindings.valueAt(property, 0); - final ObjectBinding binding1 = Bindings.valueAt(property, 1); - final ObjectBinding binding2 = Bindings.valueAt(property, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), property); - DependencyUtils.checkDependencies(binding1.getDependencies(), property); - DependencyUtils.checkDependencies(binding2.getDependencies(), property); - assertNull(binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(list1); - assertEquals(data1, binding0.get()); - assertEquals(data2, binding1.get()); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.remove(data2); - assertEquals(data1, binding0.get()); - assertNull(binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(list2); - assertNull(binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.addAll(data2, data2); - assertEquals(data2, binding0.get()); - assertEquals(data2, binding1.get()); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(null); - assertNull(binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertNull(binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testValueAt_Constant_Null() { - Bindings.valueAt(null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testValueAt_Constant_NegativeIndex() { - Bindings.valueAt(property, -1); - } - - @Test - public void testValueAt_Variable() { - final ObjectBinding binding = Bindings.valueAt(property, index); - DependencyUtils.checkDependencies(binding.getDependencies(), property, index); - - index.set(-1); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(list1); - index.set(-1); - assertNull(binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(data1, binding.get()); - index.set(1); - assertEquals(data2, binding.get()); - index.set(2); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.remove(data2); - index.set(-1); - assertNull(binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(data1, binding.get()); - index.set(1); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(list2); - index.set(-1); - assertNull(binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.addAll(data2, data2); - index.set(-1); - assertNull(binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(data2, binding.get()); - index.set(1); - assertEquals(data2, binding.get()); - index.set(2); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - property.set(null); - index.set(-1); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertNull(binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testValueAt_Variable_Null() { - Bindings.valueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testValueAt_Variable_NullIndex() { - Bindings.valueAt(property, null); - } - - @Test - public void testBooleanValueAt_Constant() { - final boolean defaultData = false; - final boolean localData1 = false; - final boolean localData2 = true; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final BooleanBinding binding0 = Bindings.booleanValueAt(localProperty, 0); - final BooleanBinding binding1 = Bindings.booleanValueAt(localProperty, 1); - final BooleanBinding binding2 = Bindings.booleanValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testBooleanValueAt_Constant_Null() { - Bindings.booleanValueAt(null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testBooleanValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.booleanValueAt(localProperty, -1); - } - - @Test - public void testBooleanValueAt_Variable() { - final boolean defaultData = false; - final boolean localData1 = false; - final boolean localData2 = true; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final BooleanBinding binding = Bindings.booleanValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(0, null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testBooleanValueAt_Variable_Null() { - Bindings.booleanValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testBooleanValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.booleanValueAt(localProperty, null); - } - - @Test - public void testDoubleValueAt_Constant() { - final double defaultData = 0.0; - final double localData1 = Math.PI; - final double localData2 = -Math.E; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final DoubleBinding binding0 = Bindings.doubleValueAt(localProperty, 0); - final DoubleBinding binding1 = Bindings.doubleValueAt(localProperty, 1); - final DoubleBinding binding2 = Bindings.doubleValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); - assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get(), EPSILON_DOUBLE); - assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testDoubleValueAt_Constant_Null() { - Bindings.doubleValueAt(null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testDoubleValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.doubleValueAt(localProperty, -1); - } - - @Test - public void testDoubleValueAt_Variable() { - final double defaultData = 0.0; - final double localData1 = -Math.PI; - final double localData2 = Math.E; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final DoubleBinding binding = Bindings.doubleValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get(), EPSILON_DOUBLE); - index.set(1); - assertEquals(localData2, binding.get(), EPSILON_DOUBLE); - index.set(2); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get(), EPSILON_DOUBLE); - index.set(1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(0, null); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - index.set(1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get(), EPSILON_DOUBLE); - index.set(1); - assertEquals(localData2, binding.get(), EPSILON_DOUBLE); - index.set(2); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testDoubleValueAt_Variable_Null() { - Bindings.doubleValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testDoubleValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.doubleValueAt(localProperty, null); - } - - @Test - public void testFloatValueAt_Constant() { - final float defaultData = 0.0f; - final float localData1 = (float)Math.PI; - final float localData2 = (float)-Math.E; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final FloatBinding binding0 = Bindings.floatValueAt(localProperty, 0); - final FloatBinding binding1 = Bindings.floatValueAt(localProperty, 1); - final FloatBinding binding2 = Bindings.floatValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get(), EPSILON_FLOAT); - assertEquals(localData2, binding1.get(), EPSILON_FLOAT); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get(), EPSILON_FLOAT); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get(), EPSILON_FLOAT); - assertEquals(localData2, binding1.get(), EPSILON_FLOAT); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testFloatValueAt_Constant_Null() { - Bindings.floatValueAt((ObservableList) null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testFloatValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.floatValueAt(localProperty, -1); - } - - @Test - public void testFloatValueAt_Variable() { - final float defaultData = 0.0f; - final float localData1 = (float)-Math.PI; - final float localData2 = (float)Math.E; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final FloatBinding binding = Bindings.floatValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get(), EPSILON_FLOAT); - index.set(1); - assertEquals(localData2, binding.get(), EPSILON_FLOAT); - index.set(2); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get(), EPSILON_FLOAT); - index.set(1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(0, null); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - index.set(1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get(), EPSILON_FLOAT); - index.set(1); - assertEquals(localData2, binding.get(), EPSILON_FLOAT); - index.set(2); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testFloatValueAt_Variable_Null() { - Bindings.floatValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testFloatValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.floatValueAt(localProperty, null); - } - - @Test - public void testIntegerValueAt_Constant() { - final int defaultData = 0; - final int localData1 = 42; - final int localData2 = -7; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final IntegerBinding binding0 = Bindings.integerValueAt(localProperty, 0); - final IntegerBinding binding1 = Bindings.integerValueAt(localProperty, 1); - final IntegerBinding binding2 = Bindings.integerValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testIntegerValueAt_Constant_Null() { - Bindings.integerValueAt((ObservableList) null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testIntegerValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.integerValueAt(localProperty, -1); - } - - @Test - public void testIntegerValueAt_Variable() { - final int defaultData = 0; - final int localData1 = 42; - final int localData2 = -7; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final IntegerBinding binding = Bindings.integerValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(0, null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testIntegerValueAt_Variable_Null() { - Bindings.integerValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testIntegerValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.integerValueAt(localProperty, null); - } - - @Test - public void testLongValueAt_Constant() { - final long defaultData = 0L; - final long localData1 = 1234567890987654321L; - final long localData2 = -987654321987654321L; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final LongBinding binding0 = Bindings.longValueAt(localProperty, 0); - final LongBinding binding1 = Bindings.longValueAt(localProperty, 1); - final LongBinding binding2 = Bindings.longValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testLongValueAt_Constant_Null() { - Bindings.longValueAt(null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testLongValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.longValueAt(localProperty, -1); - } - - @Test - public void testLongValueAt_Variable() { - final long defaultData = 0; - final long localData1 = 98765432123456789L; - final long localData2 = -1234567890123456789L; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final LongBinding binding = Bindings.longValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(0, null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testLongValueAt_Variable_Null() { - Bindings.longValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testLongValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.longValueAt(localProperty, null); - } - - @Test - public void testStringValueAt_Constant() { - final String defaultData = null; - final String localData1 = "Hello World"; - final String localData2 = "Goodbye World"; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final StringBinding binding0 = Bindings.stringValueAt(localProperty, 0); - final StringBinding binding1 = Bindings.stringValueAt(localProperty, 1); - final StringBinding binding2 = Bindings.stringValueAt(localProperty, 2); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(IndexOutOfBoundsException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testStringValueAt_Constant_Null() { - Bindings.stringValueAt(null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testStringValueAt_Constant_NegativeIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.stringValueAt(localProperty, -1); - } - - @Test - public void testStringValueAt_Variable() { - final String defaultData = null; - final String localData1 = "Goodbye"; - final String localData2 = "Hello"; - final ListProperty localProperty = new SimpleListProperty(); - final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); - final ObservableList localList2 = FXCollections.observableArrayList(); - - final StringBinding binding = Bindings.stringValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.remove(1); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData1, binding.get()); - index.set(1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(localList2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.addAll(localData2, localData2); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(ArrayIndexOutOfBoundsException.class); - index.set(0); - assertEquals(localData2, binding.get()); - index.set(1); - assertEquals(localData2, binding.get()); - index.set(2); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - - localProperty.set(null); - index.set(-1); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - index.set(0); - assertEquals(defaultData, binding.get()); - log.checkFine(IndexOutOfBoundsException.class); - } - - @Test(expected = NullPointerException.class) - public void testStringValueAt_Variable_Null() { - Bindings.stringValueAt((ObservableList)null, index); - } - - @Test(expected = NullPointerException.class) - public void testStringValueAt_Variable_NullIndex() { - final ListProperty localProperty = new SimpleListProperty(); - Bindings.stringValueAt(localProperty, null); - } - - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/BindingsListTest.java 2015-08-31 10:24:26.469216810 -0400 @@ -0,0 +1,1237 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import javafx.beans.binding.*; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import test.com.sun.javafx.binding.ErrorLoggingUtiltity; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + */ +public class BindingsListTest { + + private static final double EPSILON_DOUBLE = 1e-12; + private static final float EPSILON_FLOAT = 1e-5f; + + private static final Object data1 = new Object(); + private static final Object data2 = new Object(); + + private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); + + private ListProperty property; + private ObservableList list1; + private ObservableList list2; + private IntegerProperty index; + + @BeforeClass + public static void setUpClass() { + log.start(); + } + + @AfterClass + public static void tearDownClass() { + log.stop(); + } + + @Before + public void setUp() { + property = new SimpleListProperty(); + list1 = FXCollections.observableArrayList(data1, data2); + list2 = FXCollections.observableArrayList(); + index = new SimpleIntegerProperty(); + } + + @Test + public void testSize() { + final IntegerBinding size = Bindings.size(property); + DependencyUtils.checkDependencies(size.getDependencies(), property); + + assertEquals(0, size.get()); + property.set(list1); + assertEquals(2, size.get()); + list1.remove(data2); + assertEquals(1, size.get()); + property.set(list2); + assertEquals(0, size.get()); + property.addAll(data2, data2); + assertEquals(2, size.get()); + property.set(null); + assertEquals(0, size.get()); + } + + @Test(expected = NullPointerException.class) + public void testSize_Null() { + Bindings.size((ObservableList) null); + } + + @Test + public void testIsEmpty() { + final BooleanBinding empty = Bindings.isEmpty(property); + DependencyUtils.checkDependencies(empty.getDependencies(), property); + + assertTrue(empty.get()); + property.set(list1); + assertFalse(empty.get()); + list1.remove(data2); + assertFalse(empty.get()); + property.set(list2); + assertTrue(empty.get()); + property.addAll(data2, data2); + assertFalse(empty.get()); + property.set(null); + assertTrue(empty.get()); + } + + @Test(expected = NullPointerException.class) + public void testIsEmpty_Null() { + Bindings.isEmpty((ObservableList) null); + } + + @Test + public void testIsNotEmpty() { + final BooleanBinding notEmpty = Bindings.isNotEmpty(property); + DependencyUtils.checkDependencies(notEmpty.getDependencies(), property); + + assertFalse(notEmpty.get()); + property.set(list1); + assertTrue(notEmpty.get()); + list1.remove(data2); + assertTrue(notEmpty.get()); + property.set(list2); + assertFalse(notEmpty.get()); + property.addAll(data2, data2); + assertTrue(notEmpty.get()); + property.set(null); + assertFalse(notEmpty.get()); + } + + @Test(expected = NullPointerException.class) + public void testIsNotEmpty_Null() { + Bindings.isNotEmpty((ObservableList) null); + } + + @Test + public void testValueAt_Constant() { + final ObjectBinding binding0 = Bindings.valueAt(property, 0); + final ObjectBinding binding1 = Bindings.valueAt(property, 1); + final ObjectBinding binding2 = Bindings.valueAt(property, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), property); + DependencyUtils.checkDependencies(binding1.getDependencies(), property); + DependencyUtils.checkDependencies(binding2.getDependencies(), property); + assertNull(binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(list1); + assertEquals(data1, binding0.get()); + assertEquals(data2, binding1.get()); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.remove(data2); + assertEquals(data1, binding0.get()); + assertNull(binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(list2); + assertNull(binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.addAll(data2, data2); + assertEquals(data2, binding0.get()); + assertEquals(data2, binding1.get()); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(null); + assertNull(binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testValueAt_Constant_Null() { + Bindings.valueAt(null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testValueAt_Constant_NegativeIndex() { + Bindings.valueAt(property, -1); + } + + @Test + public void testValueAt_Variable() { + final ObjectBinding binding = Bindings.valueAt(property, index); + DependencyUtils.checkDependencies(binding.getDependencies(), property, index); + + index.set(-1); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(list1); + index.set(-1); + assertNull(binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(data1, binding.get()); + index.set(1); + assertEquals(data2, binding.get()); + index.set(2); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.remove(data2); + index.set(-1); + assertNull(binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(data1, binding.get()); + index.set(1); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(list2); + index.set(-1); + assertNull(binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.addAll(data2, data2); + index.set(-1); + assertNull(binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(data2, binding.get()); + index.set(1); + assertEquals(data2, binding.get()); + index.set(2); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + property.set(null); + index.set(-1); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertNull(binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testValueAt_Variable_Null() { + Bindings.valueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testValueAt_Variable_NullIndex() { + Bindings.valueAt(property, null); + } + + @Test + public void testBooleanValueAt_Constant() { + final boolean defaultData = false; + final boolean localData1 = false; + final boolean localData2 = true; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final BooleanBinding binding0 = Bindings.booleanValueAt(localProperty, 0); + final BooleanBinding binding1 = Bindings.booleanValueAt(localProperty, 1); + final BooleanBinding binding2 = Bindings.booleanValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testBooleanValueAt_Constant_Null() { + Bindings.booleanValueAt(null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testBooleanValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.booleanValueAt(localProperty, -1); + } + + @Test + public void testBooleanValueAt_Variable() { + final boolean defaultData = false; + final boolean localData1 = false; + final boolean localData2 = true; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final BooleanBinding binding = Bindings.booleanValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(0, null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testBooleanValueAt_Variable_Null() { + Bindings.booleanValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testBooleanValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.booleanValueAt(localProperty, null); + } + + @Test + public void testDoubleValueAt_Constant() { + final double defaultData = 0.0; + final double localData1 = Math.PI; + final double localData2 = -Math.E; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final DoubleBinding binding0 = Bindings.doubleValueAt(localProperty, 0); + final DoubleBinding binding1 = Bindings.doubleValueAt(localProperty, 1); + final DoubleBinding binding2 = Bindings.doubleValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); + assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get(), EPSILON_DOUBLE); + assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testDoubleValueAt_Constant_Null() { + Bindings.doubleValueAt(null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testDoubleValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.doubleValueAt(localProperty, -1); + } + + @Test + public void testDoubleValueAt_Variable() { + final double defaultData = 0.0; + final double localData1 = -Math.PI; + final double localData2 = Math.E; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final DoubleBinding binding = Bindings.doubleValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get(), EPSILON_DOUBLE); + index.set(1); + assertEquals(localData2, binding.get(), EPSILON_DOUBLE); + index.set(2); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get(), EPSILON_DOUBLE); + index.set(1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(0, null); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + index.set(1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get(), EPSILON_DOUBLE); + index.set(1); + assertEquals(localData2, binding.get(), EPSILON_DOUBLE); + index.set(2); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testDoubleValueAt_Variable_Null() { + Bindings.doubleValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testDoubleValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.doubleValueAt(localProperty, null); + } + + @Test + public void testFloatValueAt_Constant() { + final float defaultData = 0.0f; + final float localData1 = (float)Math.PI; + final float localData2 = (float)-Math.E; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final FloatBinding binding0 = Bindings.floatValueAt(localProperty, 0); + final FloatBinding binding1 = Bindings.floatValueAt(localProperty, 1); + final FloatBinding binding2 = Bindings.floatValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get(), EPSILON_FLOAT); + assertEquals(localData2, binding1.get(), EPSILON_FLOAT); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get(), EPSILON_FLOAT); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get(), EPSILON_FLOAT); + assertEquals(localData2, binding1.get(), EPSILON_FLOAT); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testFloatValueAt_Constant_Null() { + Bindings.floatValueAt((ObservableList) null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testFloatValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.floatValueAt(localProperty, -1); + } + + @Test + public void testFloatValueAt_Variable() { + final float defaultData = 0.0f; + final float localData1 = (float)-Math.PI; + final float localData2 = (float)Math.E; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final FloatBinding binding = Bindings.floatValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get(), EPSILON_FLOAT); + index.set(1); + assertEquals(localData2, binding.get(), EPSILON_FLOAT); + index.set(2); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get(), EPSILON_FLOAT); + index.set(1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(0, null); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + index.set(1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get(), EPSILON_FLOAT); + index.set(1); + assertEquals(localData2, binding.get(), EPSILON_FLOAT); + index.set(2); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testFloatValueAt_Variable_Null() { + Bindings.floatValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testFloatValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.floatValueAt(localProperty, null); + } + + @Test + public void testIntegerValueAt_Constant() { + final int defaultData = 0; + final int localData1 = 42; + final int localData2 = -7; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final IntegerBinding binding0 = Bindings.integerValueAt(localProperty, 0); + final IntegerBinding binding1 = Bindings.integerValueAt(localProperty, 1); + final IntegerBinding binding2 = Bindings.integerValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testIntegerValueAt_Constant_Null() { + Bindings.integerValueAt((ObservableList) null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testIntegerValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.integerValueAt(localProperty, -1); + } + + @Test + public void testIntegerValueAt_Variable() { + final int defaultData = 0; + final int localData1 = 42; + final int localData2 = -7; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final IntegerBinding binding = Bindings.integerValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(0, null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testIntegerValueAt_Variable_Null() { + Bindings.integerValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testIntegerValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.integerValueAt(localProperty, null); + } + + @Test + public void testLongValueAt_Constant() { + final long defaultData = 0L; + final long localData1 = 1234567890987654321L; + final long localData2 = -987654321987654321L; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final LongBinding binding0 = Bindings.longValueAt(localProperty, 0); + final LongBinding binding1 = Bindings.longValueAt(localProperty, 1); + final LongBinding binding2 = Bindings.longValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testLongValueAt_Constant_Null() { + Bindings.longValueAt(null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testLongValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.longValueAt(localProperty, -1); + } + + @Test + public void testLongValueAt_Variable() { + final long defaultData = 0; + final long localData1 = 98765432123456789L; + final long localData2 = -1234567890123456789L; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final LongBinding binding = Bindings.longValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(0, null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testLongValueAt_Variable_Null() { + Bindings.longValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testLongValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.longValueAt(localProperty, null); + } + + @Test + public void testStringValueAt_Constant() { + final String defaultData = null; + final String localData1 = "Hello World"; + final String localData2 = "Goodbye World"; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final StringBinding binding0 = Bindings.stringValueAt(localProperty, 0); + final StringBinding binding1 = Bindings.stringValueAt(localProperty, 1); + final StringBinding binding2 = Bindings.stringValueAt(localProperty, 2); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testStringValueAt_Constant_Null() { + Bindings.stringValueAt(null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testStringValueAt_Constant_NegativeIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.stringValueAt(localProperty, -1); + } + + @Test + public void testStringValueAt_Variable() { + final String defaultData = null; + final String localData1 = "Goodbye"; + final String localData2 = "Hello"; + final ListProperty localProperty = new SimpleListProperty(); + final ObservableList localList1 = FXCollections.observableArrayList(localData1, localData2); + final ObservableList localList2 = FXCollections.observableArrayList(); + + final StringBinding binding = Bindings.stringValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.remove(1); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData1, binding.get()); + index.set(1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(localList2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.addAll(localData2, localData2); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + index.set(0); + assertEquals(localData2, binding.get()); + index.set(1); + assertEquals(localData2, binding.get()); + index.set(2); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + + localProperty.set(null); + index.set(-1); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + index.set(0); + assertEquals(defaultData, binding.get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = NullPointerException.class) + public void testStringValueAt_Variable_Null() { + Bindings.stringValueAt((ObservableList)null, index); + } + + @Test(expected = NullPointerException.class) + public void testStringValueAt_Variable_NullIndex() { + final ListProperty localProperty = new SimpleListProperty(); + Bindings.stringValueAt(localProperty, null); + } + + +} --- old/modules/base/src/test/java/javafx/binding/BindingsMapTest.java 2015-08-31 10:24:27.325216801 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,1136 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import javafx.beans.binding.*; -import javafx.beans.property.MapProperty; -import javafx.beans.property.SimpleMapProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; -import javafx.beans.value.ObservableValue; -import javafx.collections.FXCollections; -import javafx.collections.ObservableMap; -import com.sun.javafx.binding.ErrorLoggingUtiltity; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class BindingsMapTest { - - private static final double EPSILON_DOUBLE = 1e-12; - private static final float EPSILON_FLOAT = 1e-5f; - - private static final String key1 = "Key1"; - private static final String key2 = "Key2"; - private static final String key3 = "Key3"; - private static final Object data1 = new Object(); - private static final Object data2 = new Object(); - - private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); - - private MapProperty property; - private ObservableMap map1; - private ObservableMap map2; - private StringProperty index; - - @BeforeClass - public static void setUpClass() { - log.start(); - } - - @AfterClass - public static void tearDownClass() { - log.stop(); - } - - @Before - public void setUp() { - property = new SimpleMapProperty(); - map1 = FXCollections.observableHashMap(); - map1.put(key1, data1); - map1.put(key2, data2); - map2 = FXCollections.observableHashMap(); - index = new SimpleStringProperty(); - } - - @Test - public void testSize() { - final IntegerBinding size = Bindings.size(property); - DependencyUtils.checkDependencies(size.getDependencies(), property); - - assertEquals(0, size.get()); - property.set(map1); - assertEquals(2, size.get()); - map1.remove(key2); - assertEquals(1, size.get()); - property.set(map2); - assertEquals(0, size.get()); - property.put(key1, data1); - property.put(key2, data2); - assertEquals(2, size.get()); - property.set(null); - assertEquals(0, size.get()); - } - - @Test(expected = NullPointerException.class) - public void testSize_Null() { - Bindings.size((ObservableMap) null); - } - - @Test - public void testIsEmpty() { - final BooleanBinding empty = Bindings.isEmpty(property); - DependencyUtils.checkDependencies(empty.getDependencies(), property); - - assertTrue(empty.get()); - property.set(map1); - assertFalse(empty.get()); - map1.remove(key2); - assertFalse(empty.get()); - property.set(map2); - assertTrue(empty.get()); - property.put(key1, data1); - property.put(key2, data2); - assertFalse(empty.get()); - property.set(null); - assertTrue(empty.get()); - } - - @Test(expected = NullPointerException.class) - public void testIsEmpty_Null() { - Bindings.isEmpty((ObservableMap) null); - } - - @Test - public void testIsNotEmpty() { - final BooleanBinding notEmpty = Bindings.isNotEmpty(property); - DependencyUtils.checkDependencies(notEmpty.getDependencies(), property); - - assertFalse(notEmpty.get()); - property.set(map1); - assertTrue(notEmpty.get()); - map1.remove(key2); - assertTrue(notEmpty.get()); - property.set(map2); - assertFalse(notEmpty.get()); - property.put(key1, data1); - property.put(key2, data2); - assertTrue(notEmpty.get()); - property.set(null); - assertFalse(notEmpty.get()); - } - - @Test(expected = NullPointerException.class) - public void testIsNotEmpty_Null() { - Bindings.isNotEmpty((ObservableMap) null); - } - - @Test - public void testValueAt_Constant() { - final ObjectBinding binding0 = Bindings.valueAt(property, key1); - final ObjectBinding binding1 = Bindings.valueAt(property, key2); - final ObjectBinding binding2 = Bindings.valueAt(property, key3); - DependencyUtils.checkDependencies(binding0.getDependencies(), property); - DependencyUtils.checkDependencies(binding1.getDependencies(), property); - DependencyUtils.checkDependencies(binding2.getDependencies(), property); - assertNull(binding0.get()); - assertNull(binding1.get()); - assertNull(binding2.get()); - - property.set(map1); - assertEquals(data1, binding0.get()); - assertEquals(data2, binding1.get()); - assertNull(binding2.get()); - - property.remove(key2); - assertEquals(data1, binding0.get()); - assertNull(binding1.get()); - assertNull(binding2.get()); - - property.set(map2); - assertNull(binding0.get()); - assertNull(binding1.get()); - assertNull(binding2.get()); - - property.put(key1, data2); - property.put(key2, data2); - assertEquals(data2, binding0.get()); - assertEquals(data2, binding1.get()); - assertNull(binding2.get()); - - property.set(null); - assertNull(binding0.get()); - assertNull(binding1.get()); - assertNull(binding2.get()); - } - - @Test(expected = NullPointerException.class) - public void testValueAt_Constant_Null() { - Bindings.valueAt(null, key1); - } - - @Test - public void testValueAt_Variable() { - final ObjectBinding binding = Bindings.valueAt(property, index); - DependencyUtils.checkDependencies(binding.getDependencies(), property, index); - - index.set(null); - assertNull(binding.get()); - index.set(key1); - assertNull(binding.get()); - - property.set(map1); - index.set(null); - assertNull(binding.get()); - index.set(key1); - assertEquals(data1, binding.get()); - index.set(key2); - assertEquals(data2, binding.get()); - index.set(key3); - assertNull(binding.get()); - - property.remove(key2); - index.set(null); - assertNull(binding.get()); - index.set(key1); - assertEquals(data1, binding.get()); - index.set(key2); - assertNull(binding.get()); - - property.set(map2); - index.set(null); - assertNull(binding.get()); - index.set(key1); - assertNull(binding.get()); - - property.put(key1, data2); - property.put(key2, data2); - index.set(null); - assertNull(binding.get()); - index.set(key1); - assertEquals(data2, binding.get()); - index.set(key2); - assertEquals(data2, binding.get()); - index.set(key3); - assertNull(binding.get()); - - property.set(null); - index.set(null); - assertNull(binding.get()); - index.set(key1); - assertNull(binding.get()); - } - - @Test(expected = NullPointerException.class) - public void testValueAt_Variable_Null() { - Bindings.valueAt((ObservableMap)null, index); - } - - @Test(expected = NullPointerException.class) - public void testValueAt_Variable_Null_2() { - Bindings.valueAt(property, (ObservableValue)null); - } - - @Test - public void testBooleanValueAt_Constant() { - final boolean defaultData = false; - final boolean localData1 = false; - final boolean localData2 = true; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final BooleanBinding binding0 = Bindings.booleanValueAt(localProperty, key1); - final BooleanBinding binding1 = Bindings.booleanValueAt(localProperty, key2); - final BooleanBinding binding2 = Bindings.booleanValueAt(localProperty, key3); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.remove(key2); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap2); - assertEquals(defaultData, binding0.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void testBooleanValueAt_Constant_Null() { - Bindings.booleanValueAt(null, key1); - } - - @Test - public void testBooleanValueAt_Variable() { - final boolean defaultData = false; - final boolean localData1 = false; - final boolean localData2 = true; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final BooleanBinding binding = Bindings.booleanValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap1); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData1, binding.get()); - index.set(key2); - assertEquals(localData2, binding.get()); - index.set(key3); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.remove(key2); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData1, binding.get()); - index.set(key2); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap2); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData2, binding.get()); - index.set(key2); - assertEquals(localData2, binding.get()); - index.set(key3); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(null); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void testBooleanValueAt_Variable_Null() { - Bindings.booleanValueAt((ObservableMap)null, index); - } - - @Test(expected = NullPointerException.class) - public void testBooleanValueAt_Variable_Null_2() { - final MapProperty localProperty = new SimpleMapProperty(); - Bindings.booleanValueAt(localProperty, (ObservableValue)null); - } - - @Test - public void testDoubleValueAt_Constant() { - final double defaultData = 0.0; - final double localData1 = Math.PI; - final double localData2 = -Math.E; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final DoubleBinding binding0 = Bindings.doubleValueAt(localProperty, key1); - final DoubleBinding binding1 = Bindings.doubleValueAt(localProperty, key2); - final DoubleBinding binding2 = Bindings.doubleValueAt(localProperty, key3); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap1); - assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); - assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - - localProperty.remove(key2); - assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap2); - assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - assertEquals(localData2, binding0.get(), EPSILON_DOUBLE); - assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void testDoubleValueAt_Constant_Null() { - Bindings.doubleValueAt(null, key1); - } - - @Test - public void testDoubleValueAt_Variable() { - final double defaultData = 0.0; - final double localData1 = -Math.PI; - final double localData2 = Math.E; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final DoubleBinding binding = Bindings.doubleValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap1); - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData1, binding.get(), EPSILON_DOUBLE); - index.set(key2); - assertEquals(localData2, binding.get(), EPSILON_DOUBLE); - index.set(key3); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - - localProperty.remove(key2); - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData1, binding.get(), EPSILON_DOUBLE); - index.set(key2); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap2); - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData2, binding.get(), EPSILON_DOUBLE); - index.set(key2); - assertEquals(localData2, binding.get(), EPSILON_DOUBLE); - index.set(key3); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - - localProperty.set(null); - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); - log.checkFine(NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void testDoubleValueAt_Variable_Null_1() { - Bindings.doubleValueAt((ObservableMap)null, index); - } - - @Test(expected = NullPointerException.class) - public void testDoubleValueAt_Variable_Null_2() { - final MapProperty localProperty = new SimpleMapProperty(); - Bindings.doubleValueAt(localProperty, (ObservableValue)null); - } - - @Test - public void testFloatValueAt_Constant() { - final float defaultData = 0.0f; - final float localData1 = (float)Math.PI; - final float localData2 = (float)-Math.E; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final FloatBinding binding0 = Bindings.floatValueAt(localProperty, key1); - final FloatBinding binding1 = Bindings.floatValueAt(localProperty, key2); - final FloatBinding binding2 = Bindings.floatValueAt(localProperty, key3); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap1); - assertEquals(localData1, binding0.get(), EPSILON_FLOAT); - assertEquals(localData2, binding1.get(), EPSILON_FLOAT); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - - localProperty.remove(key2); - assertEquals(localData1, binding0.get(), EPSILON_FLOAT); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap2); - assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - assertEquals(localData2, binding0.get(), EPSILON_FLOAT); - assertEquals(localData2, binding1.get(), EPSILON_FLOAT); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void testFloatValueAt_Constant_Null() { - Bindings.floatValueAt(null, key1); - } - - @Test - public void testFloatValueAt_Variable() { - final float defaultData = 0.0f; - final float localData1 = (float)-Math.PI; - final float localData2 = (float)Math.E; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final FloatBinding binding = Bindings.floatValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap1); - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData1, binding.get(), EPSILON_FLOAT); - index.set(key2); - assertEquals(localData2, binding.get(), EPSILON_FLOAT); - index.set(key3); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - - localProperty.remove(key2); - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData1, binding.get(), EPSILON_FLOAT); - index.set(key2); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap2); - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData2, binding.get(), EPSILON_FLOAT); - index.set(key2); - assertEquals(localData2, binding.get(), EPSILON_FLOAT); - index.set(key3); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - - localProperty.set(null); - index.set(null); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get(), EPSILON_FLOAT); - log.checkFine(NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void testFloatValueAt_Variable_Null_1() { - Bindings.floatValueAt((ObservableMap)null, index); - } - - @Test(expected = NullPointerException.class) - public void testFloatValueAt_Variable_Null_2() { - final MapProperty localProperty = new SimpleMapProperty(); - Bindings.floatValueAt(localProperty, (ObservableValue)null); - } - - @Test - public void testIntegerValueAt_Constant() { - final int defaultData = 0; - final int localData1 = 42; - final int localData2 = -7; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final IntegerBinding binding0 = Bindings.integerValueAt(localProperty, key1); - final IntegerBinding binding1 = Bindings.integerValueAt(localProperty, key2); - final IntegerBinding binding2 = Bindings.integerValueAt(localProperty, key3); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.remove(key2); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap2); - assertEquals(defaultData, binding0.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void testIntegerValueAt_Constant_Null() { - Bindings.integerValueAt(null, key1); - } - - @Test - public void testIntegerValueAt_Variable() { - final int defaultData = 0; - final int localData1 = 42; - final int localData2 = -7; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final IntegerBinding binding = Bindings.integerValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap1); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData1, binding.get()); - index.set(key2); - assertEquals(localData2, binding.get()); - index.set(key3); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.remove(key2); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData1, binding.get()); - index.set(key2); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap2); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData2, binding.get()); - index.set(key2); - assertEquals(localData2, binding.get()); - index.set(key3); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(null); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void testIntegerValueAt_Variable_Null_1() { - Bindings.integerValueAt((ObservableMap)null, index); - } - - @Test(expected = NullPointerException.class) - public void testIntegerValueAt_Variable_Null_2() { - final MapProperty localProperty = new SimpleMapProperty(); - Bindings.integerValueAt(localProperty, (ObservableValue)null); - } - - @Test - public void testLongValueAt_Constant() { - final long defaultData = 0L; - final long localData1 = 1234567890987654321L; - final long localData2 = -987654321987654321L; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final LongBinding binding0 = Bindings.longValueAt(localProperty, key1); - final LongBinding binding1 = Bindings.longValueAt(localProperty, key2); - final LongBinding binding2 = Bindings.longValueAt(localProperty, key3); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.remove(key2); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap2); - assertEquals(defaultData, binding0.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding1.get()); - log.checkFine(NullPointerException.class); - assertEquals(defaultData, binding2.get()); - log.checkFine(NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void testLongValueAt_Constant_Null() { - Bindings.longValueAt(null, key1); - } - - @Test - public void testLongValueAt_Variable() { - final long defaultData = 0; - final long localData1 = 98765432123456789L; - final long localData2 = -1234567890123456789L; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final LongBinding binding = Bindings.longValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap1); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData1, binding.get()); - index.set(key2); - assertEquals(localData2, binding.get()); - index.set(key3); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.remove(key2); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData1, binding.get()); - index.set(key2); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(localMap2); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(localData2, binding.get()); - index.set(key2); - assertEquals(localData2, binding.get()); - index.set(key3); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - - localProperty.set(null); - index.set(null); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - index.set(key1); - assertEquals(defaultData, binding.get()); - log.checkFine(NullPointerException.class); - } - - @Test(expected = NullPointerException.class) - public void testLongValueAt_Variable_Null() { - Bindings.longValueAt((ObservableMap)null, index); - } - - @Test(expected = NullPointerException.class) - public void testLongValueAt_Variable_Null_2() { - final MapProperty localProperty = new SimpleMapProperty(); - Bindings.longValueAt(localProperty, (ObservableValue)null); - } - - @Test - public void testStringValueAt_Constant() { - final String defaultData = null; - final String localData1 = "Hello World"; - final String localData2 = "Goodbye World"; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final StringBinding binding0 = Bindings.stringValueAt(localProperty, key1); - final StringBinding binding1 = Bindings.stringValueAt(localProperty, key2); - final StringBinding binding2 = Bindings.stringValueAt(localProperty, key3); - DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); - DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); - assertEquals(defaultData, binding0.get()); - assertEquals(defaultData, binding1.get()); - assertEquals(defaultData, binding2.get()); - - localProperty.set(localMap1); - assertEquals(localData1, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - - localProperty.remove(key2); - assertEquals(localData1, binding0.get()); - assertEquals(defaultData, binding1.get()); - assertEquals(defaultData, binding2.get()); - - localProperty.set(localMap2); - assertEquals(defaultData, binding0.get()); - assertEquals(defaultData, binding1.get()); - assertEquals(defaultData, binding2.get()); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - assertEquals(localData2, binding0.get()); - assertEquals(localData2, binding1.get()); - assertEquals(defaultData, binding2.get()); - - localProperty.set(null); - assertEquals(defaultData, binding0.get()); - assertEquals(defaultData, binding1.get()); - assertEquals(defaultData, binding2.get()); - } - - @Test(expected = NullPointerException.class) - public void testStringValueAt_Constant_Null() { - Bindings.stringValueAt(null, key1); - } - - @Test - public void testStringValueAt_Variable() { - final String defaultData = null; - final String localData1 = "Goodbye"; - final String localData2 = "Hello"; - final MapProperty localProperty = new SimpleMapProperty(); - final ObservableMap localMap1 = FXCollections.observableHashMap(); - localMap1.put(key1, localData1); - localMap1.put(key2, localData2); - final ObservableMap localMap2 = FXCollections.observableHashMap(); - - final StringBinding binding = Bindings.stringValueAt(localProperty, index); - DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); - - index.set(null); - assertEquals(defaultData, binding.get()); - index.set(key1); - assertEquals(defaultData, binding.get()); - - localProperty.set(localMap1); - index.set(null); - assertEquals(defaultData, binding.get()); - index.set(key1); - assertEquals(localData1, binding.get()); - index.set(key2); - assertEquals(localData2, binding.get()); - index.set(key3); - assertEquals(defaultData, binding.get()); - - localProperty.remove(key2); - index.set(null); - assertEquals(defaultData, binding.get()); - index.set(key1); - assertEquals(localData1, binding.get()); - index.set(key2); - assertEquals(defaultData, binding.get()); - - localProperty.set(localMap2); - index.set(null); - assertEquals(defaultData, binding.get()); - index.set(key1); - assertEquals(defaultData, binding.get()); - - localProperty.put(key1, localData2); - localProperty.put(key2, localData2); - index.set(null); - assertEquals(defaultData, binding.get()); - index.set(key1); - assertEquals(localData2, binding.get()); - index.set(key2); - assertEquals(localData2, binding.get()); - index.set(key3); - assertEquals(defaultData, binding.get()); - - localProperty.set(null); - index.set(null); - assertEquals(defaultData, binding.get()); - index.set(key1); - assertEquals(defaultData, binding.get()); - } - - @Test(expected = NullPointerException.class) - public void testStringValueAt_Variable_Null() { - Bindings.stringValueAt((ObservableMap)null, index); - } - - @Test(expected = NullPointerException.class) - public void testStringValueAt_Variable_Null_2() { - final MapProperty localProperty = new SimpleMapProperty(); - Bindings.stringValueAt(localProperty, (ObservableValue)null); - } - - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/BindingsMapTest.java 2015-08-31 10:24:27.189216802 -0400 @@ -0,0 +1,1136 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import javafx.beans.binding.*; +import javafx.beans.property.MapProperty; +import javafx.beans.property.SimpleMapProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ObservableMap; +import test.com.sun.javafx.binding.ErrorLoggingUtiltity; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class BindingsMapTest { + + private static final double EPSILON_DOUBLE = 1e-12; + private static final float EPSILON_FLOAT = 1e-5f; + + private static final String key1 = "Key1"; + private static final String key2 = "Key2"; + private static final String key3 = "Key3"; + private static final Object data1 = new Object(); + private static final Object data2 = new Object(); + + private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); + + private MapProperty property; + private ObservableMap map1; + private ObservableMap map2; + private StringProperty index; + + @BeforeClass + public static void setUpClass() { + log.start(); + } + + @AfterClass + public static void tearDownClass() { + log.stop(); + } + + @Before + public void setUp() { + property = new SimpleMapProperty(); + map1 = FXCollections.observableHashMap(); + map1.put(key1, data1); + map1.put(key2, data2); + map2 = FXCollections.observableHashMap(); + index = new SimpleStringProperty(); + } + + @Test + public void testSize() { + final IntegerBinding size = Bindings.size(property); + DependencyUtils.checkDependencies(size.getDependencies(), property); + + assertEquals(0, size.get()); + property.set(map1); + assertEquals(2, size.get()); + map1.remove(key2); + assertEquals(1, size.get()); + property.set(map2); + assertEquals(0, size.get()); + property.put(key1, data1); + property.put(key2, data2); + assertEquals(2, size.get()); + property.set(null); + assertEquals(0, size.get()); + } + + @Test(expected = NullPointerException.class) + public void testSize_Null() { + Bindings.size((ObservableMap) null); + } + + @Test + public void testIsEmpty() { + final BooleanBinding empty = Bindings.isEmpty(property); + DependencyUtils.checkDependencies(empty.getDependencies(), property); + + assertTrue(empty.get()); + property.set(map1); + assertFalse(empty.get()); + map1.remove(key2); + assertFalse(empty.get()); + property.set(map2); + assertTrue(empty.get()); + property.put(key1, data1); + property.put(key2, data2); + assertFalse(empty.get()); + property.set(null); + assertTrue(empty.get()); + } + + @Test(expected = NullPointerException.class) + public void testIsEmpty_Null() { + Bindings.isEmpty((ObservableMap) null); + } + + @Test + public void testIsNotEmpty() { + final BooleanBinding notEmpty = Bindings.isNotEmpty(property); + DependencyUtils.checkDependencies(notEmpty.getDependencies(), property); + + assertFalse(notEmpty.get()); + property.set(map1); + assertTrue(notEmpty.get()); + map1.remove(key2); + assertTrue(notEmpty.get()); + property.set(map2); + assertFalse(notEmpty.get()); + property.put(key1, data1); + property.put(key2, data2); + assertTrue(notEmpty.get()); + property.set(null); + assertFalse(notEmpty.get()); + } + + @Test(expected = NullPointerException.class) + public void testIsNotEmpty_Null() { + Bindings.isNotEmpty((ObservableMap) null); + } + + @Test + public void testValueAt_Constant() { + final ObjectBinding binding0 = Bindings.valueAt(property, key1); + final ObjectBinding binding1 = Bindings.valueAt(property, key2); + final ObjectBinding binding2 = Bindings.valueAt(property, key3); + DependencyUtils.checkDependencies(binding0.getDependencies(), property); + DependencyUtils.checkDependencies(binding1.getDependencies(), property); + DependencyUtils.checkDependencies(binding2.getDependencies(), property); + assertNull(binding0.get()); + assertNull(binding1.get()); + assertNull(binding2.get()); + + property.set(map1); + assertEquals(data1, binding0.get()); + assertEquals(data2, binding1.get()); + assertNull(binding2.get()); + + property.remove(key2); + assertEquals(data1, binding0.get()); + assertNull(binding1.get()); + assertNull(binding2.get()); + + property.set(map2); + assertNull(binding0.get()); + assertNull(binding1.get()); + assertNull(binding2.get()); + + property.put(key1, data2); + property.put(key2, data2); + assertEquals(data2, binding0.get()); + assertEquals(data2, binding1.get()); + assertNull(binding2.get()); + + property.set(null); + assertNull(binding0.get()); + assertNull(binding1.get()); + assertNull(binding2.get()); + } + + @Test(expected = NullPointerException.class) + public void testValueAt_Constant_Null() { + Bindings.valueAt(null, key1); + } + + @Test + public void testValueAt_Variable() { + final ObjectBinding binding = Bindings.valueAt(property, index); + DependencyUtils.checkDependencies(binding.getDependencies(), property, index); + + index.set(null); + assertNull(binding.get()); + index.set(key1); + assertNull(binding.get()); + + property.set(map1); + index.set(null); + assertNull(binding.get()); + index.set(key1); + assertEquals(data1, binding.get()); + index.set(key2); + assertEquals(data2, binding.get()); + index.set(key3); + assertNull(binding.get()); + + property.remove(key2); + index.set(null); + assertNull(binding.get()); + index.set(key1); + assertEquals(data1, binding.get()); + index.set(key2); + assertNull(binding.get()); + + property.set(map2); + index.set(null); + assertNull(binding.get()); + index.set(key1); + assertNull(binding.get()); + + property.put(key1, data2); + property.put(key2, data2); + index.set(null); + assertNull(binding.get()); + index.set(key1); + assertEquals(data2, binding.get()); + index.set(key2); + assertEquals(data2, binding.get()); + index.set(key3); + assertNull(binding.get()); + + property.set(null); + index.set(null); + assertNull(binding.get()); + index.set(key1); + assertNull(binding.get()); + } + + @Test(expected = NullPointerException.class) + public void testValueAt_Variable_Null() { + Bindings.valueAt((ObservableMap)null, index); + } + + @Test(expected = NullPointerException.class) + public void testValueAt_Variable_Null_2() { + Bindings.valueAt(property, (ObservableValue)null); + } + + @Test + public void testBooleanValueAt_Constant() { + final boolean defaultData = false; + final boolean localData1 = false; + final boolean localData2 = true; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final BooleanBinding binding0 = Bindings.booleanValueAt(localProperty, key1); + final BooleanBinding binding1 = Bindings.booleanValueAt(localProperty, key2); + final BooleanBinding binding2 = Bindings.booleanValueAt(localProperty, key3); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.remove(key2); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap2); + assertEquals(defaultData, binding0.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void testBooleanValueAt_Constant_Null() { + Bindings.booleanValueAt(null, key1); + } + + @Test + public void testBooleanValueAt_Variable() { + final boolean defaultData = false; + final boolean localData1 = false; + final boolean localData2 = true; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final BooleanBinding binding = Bindings.booleanValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap1); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData1, binding.get()); + index.set(key2); + assertEquals(localData2, binding.get()); + index.set(key3); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.remove(key2); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData1, binding.get()); + index.set(key2); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap2); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData2, binding.get()); + index.set(key2); + assertEquals(localData2, binding.get()); + index.set(key3); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(null); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void testBooleanValueAt_Variable_Null() { + Bindings.booleanValueAt((ObservableMap)null, index); + } + + @Test(expected = NullPointerException.class) + public void testBooleanValueAt_Variable_Null_2() { + final MapProperty localProperty = new SimpleMapProperty(); + Bindings.booleanValueAt(localProperty, (ObservableValue)null); + } + + @Test + public void testDoubleValueAt_Constant() { + final double defaultData = 0.0; + final double localData1 = Math.PI; + final double localData2 = -Math.E; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final DoubleBinding binding0 = Bindings.doubleValueAt(localProperty, key1); + final DoubleBinding binding1 = Bindings.doubleValueAt(localProperty, key2); + final DoubleBinding binding2 = Bindings.doubleValueAt(localProperty, key3); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap1); + assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); + assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + + localProperty.remove(key2); + assertEquals(localData1, binding0.get(), EPSILON_DOUBLE); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap2); + assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + assertEquals(localData2, binding0.get(), EPSILON_DOUBLE); + assertEquals(localData2, binding1.get(), EPSILON_DOUBLE); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void testDoubleValueAt_Constant_Null() { + Bindings.doubleValueAt(null, key1); + } + + @Test + public void testDoubleValueAt_Variable() { + final double defaultData = 0.0; + final double localData1 = -Math.PI; + final double localData2 = Math.E; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final DoubleBinding binding = Bindings.doubleValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap1); + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData1, binding.get(), EPSILON_DOUBLE); + index.set(key2); + assertEquals(localData2, binding.get(), EPSILON_DOUBLE); + index.set(key3); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + + localProperty.remove(key2); + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData1, binding.get(), EPSILON_DOUBLE); + index.set(key2); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap2); + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData2, binding.get(), EPSILON_DOUBLE); + index.set(key2); + assertEquals(localData2, binding.get(), EPSILON_DOUBLE); + index.set(key3); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + + localProperty.set(null); + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get(), EPSILON_DOUBLE); + log.checkFine(NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void testDoubleValueAt_Variable_Null_1() { + Bindings.doubleValueAt((ObservableMap)null, index); + } + + @Test(expected = NullPointerException.class) + public void testDoubleValueAt_Variable_Null_2() { + final MapProperty localProperty = new SimpleMapProperty(); + Bindings.doubleValueAt(localProperty, (ObservableValue)null); + } + + @Test + public void testFloatValueAt_Constant() { + final float defaultData = 0.0f; + final float localData1 = (float)Math.PI; + final float localData2 = (float)-Math.E; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final FloatBinding binding0 = Bindings.floatValueAt(localProperty, key1); + final FloatBinding binding1 = Bindings.floatValueAt(localProperty, key2); + final FloatBinding binding2 = Bindings.floatValueAt(localProperty, key3); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap1); + assertEquals(localData1, binding0.get(), EPSILON_FLOAT); + assertEquals(localData2, binding1.get(), EPSILON_FLOAT); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + + localProperty.remove(key2); + assertEquals(localData1, binding0.get(), EPSILON_FLOAT); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap2); + assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + assertEquals(localData2, binding0.get(), EPSILON_FLOAT); + assertEquals(localData2, binding1.get(), EPSILON_FLOAT); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void testFloatValueAt_Constant_Null() { + Bindings.floatValueAt(null, key1); + } + + @Test + public void testFloatValueAt_Variable() { + final float defaultData = 0.0f; + final float localData1 = (float)-Math.PI; + final float localData2 = (float)Math.E; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final FloatBinding binding = Bindings.floatValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap1); + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData1, binding.get(), EPSILON_FLOAT); + index.set(key2); + assertEquals(localData2, binding.get(), EPSILON_FLOAT); + index.set(key3); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + + localProperty.remove(key2); + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData1, binding.get(), EPSILON_FLOAT); + index.set(key2); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap2); + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData2, binding.get(), EPSILON_FLOAT); + index.set(key2); + assertEquals(localData2, binding.get(), EPSILON_FLOAT); + index.set(key3); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + + localProperty.set(null); + index.set(null); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get(), EPSILON_FLOAT); + log.checkFine(NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void testFloatValueAt_Variable_Null_1() { + Bindings.floatValueAt((ObservableMap)null, index); + } + + @Test(expected = NullPointerException.class) + public void testFloatValueAt_Variable_Null_2() { + final MapProperty localProperty = new SimpleMapProperty(); + Bindings.floatValueAt(localProperty, (ObservableValue)null); + } + + @Test + public void testIntegerValueAt_Constant() { + final int defaultData = 0; + final int localData1 = 42; + final int localData2 = -7; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final IntegerBinding binding0 = Bindings.integerValueAt(localProperty, key1); + final IntegerBinding binding1 = Bindings.integerValueAt(localProperty, key2); + final IntegerBinding binding2 = Bindings.integerValueAt(localProperty, key3); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.remove(key2); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap2); + assertEquals(defaultData, binding0.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void testIntegerValueAt_Constant_Null() { + Bindings.integerValueAt(null, key1); + } + + @Test + public void testIntegerValueAt_Variable() { + final int defaultData = 0; + final int localData1 = 42; + final int localData2 = -7; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final IntegerBinding binding = Bindings.integerValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap1); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData1, binding.get()); + index.set(key2); + assertEquals(localData2, binding.get()); + index.set(key3); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.remove(key2); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData1, binding.get()); + index.set(key2); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap2); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData2, binding.get()); + index.set(key2); + assertEquals(localData2, binding.get()); + index.set(key3); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(null); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void testIntegerValueAt_Variable_Null_1() { + Bindings.integerValueAt((ObservableMap)null, index); + } + + @Test(expected = NullPointerException.class) + public void testIntegerValueAt_Variable_Null_2() { + final MapProperty localProperty = new SimpleMapProperty(); + Bindings.integerValueAt(localProperty, (ObservableValue)null); + } + + @Test + public void testLongValueAt_Constant() { + final long defaultData = 0L; + final long localData1 = 1234567890987654321L; + final long localData2 = -987654321987654321L; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final LongBinding binding0 = Bindings.longValueAt(localProperty, key1); + final LongBinding binding1 = Bindings.longValueAt(localProperty, key2); + final LongBinding binding2 = Bindings.longValueAt(localProperty, key3); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.remove(key2); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap2); + assertEquals(defaultData, binding0.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding1.get()); + log.checkFine(NullPointerException.class); + assertEquals(defaultData, binding2.get()); + log.checkFine(NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void testLongValueAt_Constant_Null() { + Bindings.longValueAt(null, key1); + } + + @Test + public void testLongValueAt_Variable() { + final long defaultData = 0; + final long localData1 = 98765432123456789L; + final long localData2 = -1234567890123456789L; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final LongBinding binding = Bindings.longValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap1); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData1, binding.get()); + index.set(key2); + assertEquals(localData2, binding.get()); + index.set(key3); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.remove(key2); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData1, binding.get()); + index.set(key2); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(localMap2); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(localData2, binding.get()); + index.set(key2); + assertEquals(localData2, binding.get()); + index.set(key3); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + + localProperty.set(null); + index.set(null); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + index.set(key1); + assertEquals(defaultData, binding.get()); + log.checkFine(NullPointerException.class); + } + + @Test(expected = NullPointerException.class) + public void testLongValueAt_Variable_Null() { + Bindings.longValueAt((ObservableMap)null, index); + } + + @Test(expected = NullPointerException.class) + public void testLongValueAt_Variable_Null_2() { + final MapProperty localProperty = new SimpleMapProperty(); + Bindings.longValueAt(localProperty, (ObservableValue)null); + } + + @Test + public void testStringValueAt_Constant() { + final String defaultData = null; + final String localData1 = "Hello World"; + final String localData2 = "Goodbye World"; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final StringBinding binding0 = Bindings.stringValueAt(localProperty, key1); + final StringBinding binding1 = Bindings.stringValueAt(localProperty, key2); + final StringBinding binding2 = Bindings.stringValueAt(localProperty, key3); + DependencyUtils.checkDependencies(binding0.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding1.getDependencies(), localProperty); + DependencyUtils.checkDependencies(binding2.getDependencies(), localProperty); + assertEquals(defaultData, binding0.get()); + assertEquals(defaultData, binding1.get()); + assertEquals(defaultData, binding2.get()); + + localProperty.set(localMap1); + assertEquals(localData1, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + + localProperty.remove(key2); + assertEquals(localData1, binding0.get()); + assertEquals(defaultData, binding1.get()); + assertEquals(defaultData, binding2.get()); + + localProperty.set(localMap2); + assertEquals(defaultData, binding0.get()); + assertEquals(defaultData, binding1.get()); + assertEquals(defaultData, binding2.get()); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + assertEquals(localData2, binding0.get()); + assertEquals(localData2, binding1.get()); + assertEquals(defaultData, binding2.get()); + + localProperty.set(null); + assertEquals(defaultData, binding0.get()); + assertEquals(defaultData, binding1.get()); + assertEquals(defaultData, binding2.get()); + } + + @Test(expected = NullPointerException.class) + public void testStringValueAt_Constant_Null() { + Bindings.stringValueAt(null, key1); + } + + @Test + public void testStringValueAt_Variable() { + final String defaultData = null; + final String localData1 = "Goodbye"; + final String localData2 = "Hello"; + final MapProperty localProperty = new SimpleMapProperty(); + final ObservableMap localMap1 = FXCollections.observableHashMap(); + localMap1.put(key1, localData1); + localMap1.put(key2, localData2); + final ObservableMap localMap2 = FXCollections.observableHashMap(); + + final StringBinding binding = Bindings.stringValueAt(localProperty, index); + DependencyUtils.checkDependencies(binding.getDependencies(), localProperty, index); + + index.set(null); + assertEquals(defaultData, binding.get()); + index.set(key1); + assertEquals(defaultData, binding.get()); + + localProperty.set(localMap1); + index.set(null); + assertEquals(defaultData, binding.get()); + index.set(key1); + assertEquals(localData1, binding.get()); + index.set(key2); + assertEquals(localData2, binding.get()); + index.set(key3); + assertEquals(defaultData, binding.get()); + + localProperty.remove(key2); + index.set(null); + assertEquals(defaultData, binding.get()); + index.set(key1); + assertEquals(localData1, binding.get()); + index.set(key2); + assertEquals(defaultData, binding.get()); + + localProperty.set(localMap2); + index.set(null); + assertEquals(defaultData, binding.get()); + index.set(key1); + assertEquals(defaultData, binding.get()); + + localProperty.put(key1, localData2); + localProperty.put(key2, localData2); + index.set(null); + assertEquals(defaultData, binding.get()); + index.set(key1); + assertEquals(localData2, binding.get()); + index.set(key2); + assertEquals(localData2, binding.get()); + index.set(key3); + assertEquals(defaultData, binding.get()); + + localProperty.set(null); + index.set(null); + assertEquals(defaultData, binding.get()); + index.set(key1); + assertEquals(defaultData, binding.get()); + } + + @Test(expected = NullPointerException.class) + public void testStringValueAt_Variable_Null() { + Bindings.stringValueAt((ObservableMap)null, index); + } + + @Test(expected = NullPointerException.class) + public void testStringValueAt_Variable_Null_2() { + final MapProperty localProperty = new SimpleMapProperty(); + Bindings.stringValueAt(localProperty, (ObservableValue)null); + } + + +} --- old/modules/base/src/test/java/javafx/binding/BindingsNumberCalculationsTest.java 2015-08-31 10:24:28.049216793 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,839 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; -import java.util.Collection; - -import javafx.beans.InvalidationListenerMock; -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.FloatProperty; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.LongProperty; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleLongProperty; -import javafx.beans.value.*; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -@RunWith(Parameterized.class) -public class BindingsNumberCalculationsTest { - - private static final float EPSILON_FLOAT = 1e-5f; - private static final double EPSILON_DOUBLE = 1e-10; - - public static interface Functions { - Binding generateExpressionExpression(Object op1, Object op2); - Binding generateExpressionPrimitive(Object op1, S op2); - Binding generatePrimitiveExpression(S op1, Object op2); - void setOp1(S value); - void setOp2(S value); - void check(S op1, S op2, ObservableValue exp); - } - - private final ObservableValue op1; - private final ObservableValue op2; - private final Functions func; - private final T[] v; - private InvalidationListenerMock observer; - - public BindingsNumberCalculationsTest(ObservableValue op1, ObservableValue op2, Functions func, T[] v) { - this.op1 = op1; - this.op2 = op2; - this.func = func; - this.v = v; - } - - @Before - public void setUp() { - func.setOp1(v[0]); - func.setOp2(v[1]); - observer = new InvalidationListenerMock(); - } - - @Test - public void test_Expression_Expression() { - final Binding binding = func.generateExpressionExpression(op1, op2); - binding.addListener(observer); - - // check initial value - func.check(v[0], v[1], binding); - DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); - - // change first operand - observer.reset(); - func.setOp1(v[2]); - func.check(v[2], v[1], binding); - observer.check(binding, 1); - - // change second operand - func.setOp2(v[3]); - func.check(v[2], v[3], binding); - observer.check(binding, 1); - - // change both operands - func.setOp1(v[4]); - func.setOp2(v[5]); - func.check(v[4], v[5], binding); - observer.check(binding, 1); - } - - @Test - public void test_Self() { - // using same FloatValue twice - final Binding binding = func.generateExpressionExpression(op1, op1); - binding.addListener(observer); - - // check initial value - func.check(v[0], v[0], binding); - - // change value - observer.reset(); - func.setOp1(v[7]); - func.check(v[7], v[7], binding); - observer.check(binding, 1); - } - - @Test(expected=NullPointerException.class) - public void test_null_Expression() { - func.generateExpressionExpression(null, op1); - } - - @Test(expected=NullPointerException.class) - public void test_Expression_null() { - func.generateExpressionExpression(op1, null); - } - - @Test - public void test_Expression_Primitive() { - final Binding binding = func.generateExpressionPrimitive(op1, v[7]); - binding.addListener(observer); - - // check initial value - func.check(v[0], v[7], binding); - DependencyUtils.checkDependencies(binding.getDependencies(), op1); - - // change first operand - observer.reset(); - func.setOp1(v[8]); - func.check(v[8], v[7], binding); - observer.check(binding, 1); - } - - @Test(expected=NullPointerException.class) - public void test_null_Primitive() { - func.generateExpressionPrimitive(null, v[0]); - } - - @Test - public void test_Primitive_Expression() { - final Binding binding = func.generatePrimitiveExpression(v[9], op1); - binding.addListener(observer); - - // check initial value - func.check(v[9], v[0], binding); - DependencyUtils.checkDependencies(binding.getDependencies(), op1); - - // change first operand - observer.reset(); - func.setOp1(v[10]); - func.check(v[9], v[10], binding); - observer.check(binding, 1); - } - - @Test(expected=NullPointerException.class) - public void test_Primitive_null() { - func.generatePrimitiveExpression(v[0], null); - } - - @Parameterized.Parameters - public static Collection parameters() { - final FloatProperty float1 = new SimpleFloatProperty(); - final FloatProperty float2 = new SimpleFloatProperty(); - final Float[] floatData = new Float[] {-3592.9f, 234872.8347f, 3897.274f, 3958.938745f, -8347.3478f, 217.902874f, -2784.827f, -28723.7824f, 82.8274f, -12.23478f, 0.92874f}; - - final DoubleProperty double1 = new SimpleDoubleProperty(); - final DoubleProperty double2 = new SimpleDoubleProperty(); - final Double[] doubleData = new Double[] {2348.2345, -92.214, -214.0214, -908.214, 67.124, 0.214, 2893.124, -214.987234, -89724.897234, 234.25, 8721.234}; - - final IntegerProperty int1 = new SimpleIntegerProperty(); - final IntegerProperty int2 = new SimpleIntegerProperty(); - final Integer[] integerData = new Integer[] {248, -9384, -234, -34, -450809, 342345, 8923489, 23789, -89234, -13134, 23134879}; - - final LongProperty long1 = new SimpleLongProperty(); - final LongProperty long2 = new SimpleLongProperty(); - final Long[] longData = new Long[] {9823984L, 2908934L, -234234L, 9089234L, 132323L, -89324L, -12424L, -8923442L, 78234L, -233487L, 988998L}; - - return Arrays.asList(new Object[][] { - // float - { - float1, float2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.add((ObservableFloatValue)op1, (ObservableFloatValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.add((ObservableFloatValue)op1, op2.floatValue()); - } - @Override - public Binding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.add(op1.floatValue(), (ObservableFloatValue)op2); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, ObservableValue exp) { - assertEquals(op1 + op2, ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); - } - }, - floatData - }, - { - float1, float2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.subtract((ObservableFloatValue)op1, (ObservableFloatValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.subtract((ObservableFloatValue)op1, op2.floatValue()); - } - @Override - public Binding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.subtract(op1.floatValue(), (ObservableFloatValue)op2); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, ObservableValue exp) { - assertEquals(op1 - op2, ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); - } - }, - floatData - }, - { - float1, float2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.multiply((ObservableFloatValue)op1, (ObservableFloatValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.multiply((ObservableFloatValue)op1, op2.floatValue()); - } - @Override - public Binding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.multiply(op1.floatValue(), (ObservableFloatValue)op2); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, ObservableValue exp) { - assertEquals(op1 * op2, ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); - } - }, - floatData - }, - { - float1, float2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.divide((ObservableFloatValue)op1, (ObservableFloatValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.divide((ObservableFloatValue)op1, op2.floatValue()); - } - @Override - public Binding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.divide(op1.floatValue(), (ObservableFloatValue)op2); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, ObservableValue exp) { - assertEquals(op1 / op2, ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); - } - }, - floatData - }, - { - float1, float2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.min((ObservableFloatValue)op1, (ObservableFloatValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.min((ObservableFloatValue)op1, op2.floatValue()); - } - @Override - public Binding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.min(op1.floatValue(), (ObservableFloatValue)op2); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, ObservableValue exp) { - assertEquals(Math.min(op1, op2), ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); - } - }, - floatData - }, - { - float1, float2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.max((ObservableFloatValue)op1, (ObservableFloatValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Float op2) { - return Bindings.max((ObservableFloatValue)op1, op2.floatValue()); - } - @Override - public Binding generatePrimitiveExpression(Float op1, Object op2) { - return Bindings.max(op1.floatValue(), (ObservableFloatValue)op2); - } - @Override - public void setOp1(Float value) {float1.set(value);} - @Override - public void setOp2(Float value) {float2.set(value);} - @Override - public void check(Float op1, Float op2, ObservableValue exp) { - assertEquals(Math.max(op1, op2), ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); - } - }, - floatData - }, - - - - // double - { - double1, double2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.add((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.add((ObservableDoubleValue)op1, op2.doubleValue()); - } - @Override - public Binding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.add(op1.doubleValue(), (ObservableDoubleValue)op2); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, ObservableValue exp) { - assertEquals(op1 + op2, ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); - } - }, - doubleData - }, - { - double1, double2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.subtract((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.subtract((ObservableDoubleValue)op1, op2.doubleValue()); - } - @Override - public Binding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.subtract(op1.doubleValue(), (ObservableDoubleValue)op2); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, ObservableValue exp) { - assertEquals(op1 - op2, ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); - } - }, - doubleData - }, - { - double1, double2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.multiply((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.multiply((ObservableDoubleValue)op1, op2.doubleValue()); - } - @Override - public Binding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.multiply(op1.doubleValue(), (ObservableDoubleValue)op2); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, ObservableValue exp) { - assertEquals(op1 * op2, ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); - } - }, - doubleData - }, - { - double1, double2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.divide((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.divide((ObservableDoubleValue)op1, op2.doubleValue()); - } - @Override - public Binding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.divide(op1.doubleValue(), (ObservableDoubleValue)op2); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, ObservableValue exp) { - assertEquals(op1 / op2, ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); - } - }, - doubleData - }, - { - double1, double2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.min((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.min((ObservableDoubleValue)op1, op2.doubleValue()); - } - @Override - public Binding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.min(op1.doubleValue(), (ObservableDoubleValue)op2); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, ObservableValue exp) { - assertEquals(Math.min(op1, op2), ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); - } - }, - doubleData - }, - { - double1, double2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.max((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Double op2) { - return Bindings.max((ObservableDoubleValue)op1, op2.doubleValue()); - } - @Override - public Binding generatePrimitiveExpression(Double op1, Object op2) { - return Bindings.max(op1.doubleValue(), (ObservableDoubleValue)op2); - } - @Override - public void setOp1(Double value) {double1.set(value);} - @Override - public void setOp2(Double value) {double2.set(value);} - @Override - public void check(Double op1, Double op2, ObservableValue exp) { - assertEquals(Math.max(op1, op2), ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); - } - }, - doubleData - }, - - - - // int - { - int1, int2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.add((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.add((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public Binding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.add(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, ObservableValue exp) { - assertEquals(op1 + op2, ((ObservableIntegerValue)exp).get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.subtract((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.subtract((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public Binding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.subtract(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, ObservableValue exp) { - assertEquals(op1 - op2, ((ObservableIntegerValue)exp).get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.multiply((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.multiply((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public Binding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.multiply(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, ObservableValue exp) { - assertEquals(op1 * op2, ((ObservableIntegerValue)exp).get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.divide((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.divide((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public Binding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.divide(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, ObservableValue exp) { - assertEquals(op1 / op2, ((ObservableIntegerValue)exp).get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.min((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.min((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public Binding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.min(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, ObservableValue exp) { - assertEquals(Math.min(op1, op2), ((ObservableIntegerValue)exp).get()); - } - }, - integerData - }, - { - int1, int2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.max((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Integer op2) { - return Bindings.max((ObservableIntegerValue)op1, op2.intValue()); - } - @Override - public Binding generatePrimitiveExpression(Integer op1, Object op2) { - return Bindings.max(op1.intValue(), (ObservableIntegerValue)op2); - } - @Override - public void setOp1(Integer value) {int1.set(value);} - @Override - public void setOp2(Integer value) {int2.set(value);} - @Override - public void check(Integer op1, Integer op2, ObservableValue exp) { - assertEquals(Math.max(op1, op2), ((ObservableIntegerValue)exp).get()); - } - }, - integerData - }, - - - - // long - { - long1, long2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.add((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.add((ObservableLongValue)op1, op2.longValue()); - } - @Override - public Binding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.add(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, ObservableValue exp) { - assertEquals(op1 + op2, ((ObservableLongValue)exp).get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.subtract((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.subtract((ObservableLongValue)op1, op2.longValue()); - } - @Override - public Binding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.subtract(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, ObservableValue exp) { - assertEquals(op1 - op2, ((ObservableLongValue)exp).get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.multiply((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.multiply((ObservableLongValue)op1, op2.longValue()); - } - @Override - public Binding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.multiply(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, ObservableValue exp) { - assertEquals(op1 * op2, ((ObservableLongValue)exp).get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.divide((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.divide((ObservableLongValue)op1, op2.longValue()); - } - @Override - public Binding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.divide(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, ObservableValue exp) { - assertEquals(op1 / op2, ((ObservableLongValue)exp).get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.min((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.min((ObservableLongValue)op1, op2.longValue()); - } - @Override - public Binding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.min(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, ObservableValue exp) { - assertEquals(Math.min(op1, op2), ((ObservableLongValue)exp).get()); - } - }, - longData - }, - { - long1, long2, - new Functions() { - @Override - public Binding generateExpressionExpression(Object op1, Object op2) { - return Bindings.max((ObservableLongValue)op1, (ObservableLongValue)op2); - } - @Override - public Binding generateExpressionPrimitive(Object op1, Long op2) { - return Bindings.max((ObservableLongValue)op1, op2.longValue()); - } - @Override - public Binding generatePrimitiveExpression(Long op1, Object op2) { - return Bindings.max(op1.longValue(), (ObservableLongValue)op2); - } - @Override - public void setOp1(Long value) {long1.set(value);} - @Override - public void setOp2(Long value) {long2.set(value);} - @Override - public void check(Long op1, Long op2, ObservableValue exp) { - assertEquals(Math.max(op1, op2), ((ObservableLongValue)exp).get()); - } - }, - longData - }, - }); - }; -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/BindingsNumberCalculationsTest.java 2015-08-31 10:24:27.849216795 -0400 @@ -0,0 +1,839 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.Collection; + +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.FloatProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.LongProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.value.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class BindingsNumberCalculationsTest { + + private static final float EPSILON_FLOAT = 1e-5f; + private static final double EPSILON_DOUBLE = 1e-10; + + public static interface Functions { + Binding generateExpressionExpression(Object op1, Object op2); + Binding generateExpressionPrimitive(Object op1, S op2); + Binding generatePrimitiveExpression(S op1, Object op2); + void setOp1(S value); + void setOp2(S value); + void check(S op1, S op2, ObservableValue exp); + } + + private final ObservableValue op1; + private final ObservableValue op2; + private final Functions func; + private final T[] v; + private InvalidationListenerMock observer; + + public BindingsNumberCalculationsTest(ObservableValue op1, ObservableValue op2, Functions func, T[] v) { + this.op1 = op1; + this.op2 = op2; + this.func = func; + this.v = v; + } + + @Before + public void setUp() { + func.setOp1(v[0]); + func.setOp2(v[1]); + observer = new InvalidationListenerMock(); + } + + @Test + public void test_Expression_Expression() { + final Binding binding = func.generateExpressionExpression(op1, op2); + binding.addListener(observer); + + // check initial value + func.check(v[0], v[1], binding); + DependencyUtils.checkDependencies(binding.getDependencies(), op1, op2); + + // change first operand + observer.reset(); + func.setOp1(v[2]); + func.check(v[2], v[1], binding); + observer.check(binding, 1); + + // change second operand + func.setOp2(v[3]); + func.check(v[2], v[3], binding); + observer.check(binding, 1); + + // change both operands + func.setOp1(v[4]); + func.setOp2(v[5]); + func.check(v[4], v[5], binding); + observer.check(binding, 1); + } + + @Test + public void test_Self() { + // using same FloatValue twice + final Binding binding = func.generateExpressionExpression(op1, op1); + binding.addListener(observer); + + // check initial value + func.check(v[0], v[0], binding); + + // change value + observer.reset(); + func.setOp1(v[7]); + func.check(v[7], v[7], binding); + observer.check(binding, 1); + } + + @Test(expected=NullPointerException.class) + public void test_null_Expression() { + func.generateExpressionExpression(null, op1); + } + + @Test(expected=NullPointerException.class) + public void test_Expression_null() { + func.generateExpressionExpression(op1, null); + } + + @Test + public void test_Expression_Primitive() { + final Binding binding = func.generateExpressionPrimitive(op1, v[7]); + binding.addListener(observer); + + // check initial value + func.check(v[0], v[7], binding); + DependencyUtils.checkDependencies(binding.getDependencies(), op1); + + // change first operand + observer.reset(); + func.setOp1(v[8]); + func.check(v[8], v[7], binding); + observer.check(binding, 1); + } + + @Test(expected=NullPointerException.class) + public void test_null_Primitive() { + func.generateExpressionPrimitive(null, v[0]); + } + + @Test + public void test_Primitive_Expression() { + final Binding binding = func.generatePrimitiveExpression(v[9], op1); + binding.addListener(observer); + + // check initial value + func.check(v[9], v[0], binding); + DependencyUtils.checkDependencies(binding.getDependencies(), op1); + + // change first operand + observer.reset(); + func.setOp1(v[10]); + func.check(v[9], v[10], binding); + observer.check(binding, 1); + } + + @Test(expected=NullPointerException.class) + public void test_Primitive_null() { + func.generatePrimitiveExpression(v[0], null); + } + + @Parameterized.Parameters + public static Collection parameters() { + final FloatProperty float1 = new SimpleFloatProperty(); + final FloatProperty float2 = new SimpleFloatProperty(); + final Float[] floatData = new Float[] {-3592.9f, 234872.8347f, 3897.274f, 3958.938745f, -8347.3478f, 217.902874f, -2784.827f, -28723.7824f, 82.8274f, -12.23478f, 0.92874f}; + + final DoubleProperty double1 = new SimpleDoubleProperty(); + final DoubleProperty double2 = new SimpleDoubleProperty(); + final Double[] doubleData = new Double[] {2348.2345, -92.214, -214.0214, -908.214, 67.124, 0.214, 2893.124, -214.987234, -89724.897234, 234.25, 8721.234}; + + final IntegerProperty int1 = new SimpleIntegerProperty(); + final IntegerProperty int2 = new SimpleIntegerProperty(); + final Integer[] integerData = new Integer[] {248, -9384, -234, -34, -450809, 342345, 8923489, 23789, -89234, -13134, 23134879}; + + final LongProperty long1 = new SimpleLongProperty(); + final LongProperty long2 = new SimpleLongProperty(); + final Long[] longData = new Long[] {9823984L, 2908934L, -234234L, 9089234L, 132323L, -89324L, -12424L, -8923442L, 78234L, -233487L, 988998L}; + + return Arrays.asList(new Object[][] { + // float + { + float1, float2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.add((ObservableFloatValue)op1, (ObservableFloatValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.add((ObservableFloatValue)op1, op2.floatValue()); + } + @Override + public Binding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.add(op1.floatValue(), (ObservableFloatValue)op2); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, ObservableValue exp) { + assertEquals(op1 + op2, ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); + } + }, + floatData + }, + { + float1, float2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.subtract((ObservableFloatValue)op1, (ObservableFloatValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.subtract((ObservableFloatValue)op1, op2.floatValue()); + } + @Override + public Binding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.subtract(op1.floatValue(), (ObservableFloatValue)op2); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, ObservableValue exp) { + assertEquals(op1 - op2, ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); + } + }, + floatData + }, + { + float1, float2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.multiply((ObservableFloatValue)op1, (ObservableFloatValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.multiply((ObservableFloatValue)op1, op2.floatValue()); + } + @Override + public Binding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.multiply(op1.floatValue(), (ObservableFloatValue)op2); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, ObservableValue exp) { + assertEquals(op1 * op2, ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); + } + }, + floatData + }, + { + float1, float2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.divide((ObservableFloatValue)op1, (ObservableFloatValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.divide((ObservableFloatValue)op1, op2.floatValue()); + } + @Override + public Binding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.divide(op1.floatValue(), (ObservableFloatValue)op2); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, ObservableValue exp) { + assertEquals(op1 / op2, ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); + } + }, + floatData + }, + { + float1, float2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.min((ObservableFloatValue)op1, (ObservableFloatValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.min((ObservableFloatValue)op1, op2.floatValue()); + } + @Override + public Binding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.min(op1.floatValue(), (ObservableFloatValue)op2); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, ObservableValue exp) { + assertEquals(Math.min(op1, op2), ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); + } + }, + floatData + }, + { + float1, float2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.max((ObservableFloatValue)op1, (ObservableFloatValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Float op2) { + return Bindings.max((ObservableFloatValue)op1, op2.floatValue()); + } + @Override + public Binding generatePrimitiveExpression(Float op1, Object op2) { + return Bindings.max(op1.floatValue(), (ObservableFloatValue)op2); + } + @Override + public void setOp1(Float value) {float1.set(value);} + @Override + public void setOp2(Float value) {float2.set(value);} + @Override + public void check(Float op1, Float op2, ObservableValue exp) { + assertEquals(Math.max(op1, op2), ((ObservableFloatValue)exp).get(), EPSILON_FLOAT); + } + }, + floatData + }, + + + + // double + { + double1, double2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.add((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.add((ObservableDoubleValue)op1, op2.doubleValue()); + } + @Override + public Binding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.add(op1.doubleValue(), (ObservableDoubleValue)op2); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, ObservableValue exp) { + assertEquals(op1 + op2, ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); + } + }, + doubleData + }, + { + double1, double2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.subtract((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.subtract((ObservableDoubleValue)op1, op2.doubleValue()); + } + @Override + public Binding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.subtract(op1.doubleValue(), (ObservableDoubleValue)op2); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, ObservableValue exp) { + assertEquals(op1 - op2, ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); + } + }, + doubleData + }, + { + double1, double2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.multiply((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.multiply((ObservableDoubleValue)op1, op2.doubleValue()); + } + @Override + public Binding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.multiply(op1.doubleValue(), (ObservableDoubleValue)op2); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, ObservableValue exp) { + assertEquals(op1 * op2, ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); + } + }, + doubleData + }, + { + double1, double2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.divide((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.divide((ObservableDoubleValue)op1, op2.doubleValue()); + } + @Override + public Binding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.divide(op1.doubleValue(), (ObservableDoubleValue)op2); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, ObservableValue exp) { + assertEquals(op1 / op2, ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); + } + }, + doubleData + }, + { + double1, double2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.min((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.min((ObservableDoubleValue)op1, op2.doubleValue()); + } + @Override + public Binding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.min(op1.doubleValue(), (ObservableDoubleValue)op2); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, ObservableValue exp) { + assertEquals(Math.min(op1, op2), ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); + } + }, + doubleData + }, + { + double1, double2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.max((ObservableDoubleValue)op1, (ObservableDoubleValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Double op2) { + return Bindings.max((ObservableDoubleValue)op1, op2.doubleValue()); + } + @Override + public Binding generatePrimitiveExpression(Double op1, Object op2) { + return Bindings.max(op1.doubleValue(), (ObservableDoubleValue)op2); + } + @Override + public void setOp1(Double value) {double1.set(value);} + @Override + public void setOp2(Double value) {double2.set(value);} + @Override + public void check(Double op1, Double op2, ObservableValue exp) { + assertEquals(Math.max(op1, op2), ((ObservableDoubleValue)exp).get(), EPSILON_DOUBLE); + } + }, + doubleData + }, + + + + // int + { + int1, int2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.add((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.add((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public Binding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.add(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, ObservableValue exp) { + assertEquals(op1 + op2, ((ObservableIntegerValue)exp).get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.subtract((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.subtract((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public Binding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.subtract(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, ObservableValue exp) { + assertEquals(op1 - op2, ((ObservableIntegerValue)exp).get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.multiply((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.multiply((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public Binding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.multiply(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, ObservableValue exp) { + assertEquals(op1 * op2, ((ObservableIntegerValue)exp).get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.divide((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.divide((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public Binding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.divide(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, ObservableValue exp) { + assertEquals(op1 / op2, ((ObservableIntegerValue)exp).get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.min((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.min((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public Binding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.min(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, ObservableValue exp) { + assertEquals(Math.min(op1, op2), ((ObservableIntegerValue)exp).get()); + } + }, + integerData + }, + { + int1, int2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.max((ObservableIntegerValue)op1, (ObservableIntegerValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Integer op2) { + return Bindings.max((ObservableIntegerValue)op1, op2.intValue()); + } + @Override + public Binding generatePrimitiveExpression(Integer op1, Object op2) { + return Bindings.max(op1.intValue(), (ObservableIntegerValue)op2); + } + @Override + public void setOp1(Integer value) {int1.set(value);} + @Override + public void setOp2(Integer value) {int2.set(value);} + @Override + public void check(Integer op1, Integer op2, ObservableValue exp) { + assertEquals(Math.max(op1, op2), ((ObservableIntegerValue)exp).get()); + } + }, + integerData + }, + + + + // long + { + long1, long2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.add((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.add((ObservableLongValue)op1, op2.longValue()); + } + @Override + public Binding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.add(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, ObservableValue exp) { + assertEquals(op1 + op2, ((ObservableLongValue)exp).get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.subtract((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.subtract((ObservableLongValue)op1, op2.longValue()); + } + @Override + public Binding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.subtract(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, ObservableValue exp) { + assertEquals(op1 - op2, ((ObservableLongValue)exp).get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.multiply((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.multiply((ObservableLongValue)op1, op2.longValue()); + } + @Override + public Binding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.multiply(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, ObservableValue exp) { + assertEquals(op1 * op2, ((ObservableLongValue)exp).get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.divide((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.divide((ObservableLongValue)op1, op2.longValue()); + } + @Override + public Binding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.divide(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, ObservableValue exp) { + assertEquals(op1 / op2, ((ObservableLongValue)exp).get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.min((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.min((ObservableLongValue)op1, op2.longValue()); + } + @Override + public Binding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.min(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, ObservableValue exp) { + assertEquals(Math.min(op1, op2), ((ObservableLongValue)exp).get()); + } + }, + longData + }, + { + long1, long2, + new Functions() { + @Override + public Binding generateExpressionExpression(Object op1, Object op2) { + return Bindings.max((ObservableLongValue)op1, (ObservableLongValue)op2); + } + @Override + public Binding generateExpressionPrimitive(Object op1, Long op2) { + return Bindings.max((ObservableLongValue)op1, op2.longValue()); + } + @Override + public Binding generatePrimitiveExpression(Long op1, Object op2) { + return Bindings.max(op1.longValue(), (ObservableLongValue)op2); + } + @Override + public void setOp1(Long value) {long1.set(value);} + @Override + public void setOp2(Long value) {long2.set(value);} + @Override + public void check(Long op1, Long op2, ObservableValue exp) { + assertEquals(Math.max(op1, op2), ((ObservableLongValue)exp).get()); + } + }, + longData + }, + }); + }; +} --- old/modules/base/src/test/java/javafx/binding/BindingsNumberCastTest.java 2015-08-31 10:24:28.745216785 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,287 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.Collection; - -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.binding.BooleanExpression; -import javafx.beans.binding.DoubleExpression; -import javafx.beans.binding.FloatExpression; -import javafx.beans.binding.IntegerExpression; -import javafx.beans.binding.LongExpression; -import javafx.beans.binding.NumberExpression; -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.FloatProperty; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.LongProperty; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleLongProperty; -import javafx.beans.value.ObservableNumberValue; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -@RunWith(Parameterized.class) -public class BindingsNumberCastTest { - - public static interface Functions { - Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2); - void check(double op1, double op2, Binding binding); - } - - private static final double EPSILON = 1e-5; - - private final Functions func; - - private Double double0; - private Float float0; - private Long long0; - private Integer integer0; - - private DoubleProperty double1; - private FloatProperty float1; - private LongProperty long1; - private IntegerProperty integer1; - - public BindingsNumberCastTest(Functions func) { - this.func = func; - } - - @Before - public void setUp() { - double0 = Double.valueOf(3.1415); - float0 = Float.valueOf(2.71f); - long0 = Long.valueOf(111L); - integer0 = Integer.valueOf(42); - - double1 = new SimpleDoubleProperty(double0); - float1 = new SimpleFloatProperty(float0); - long1 = new SimpleLongProperty(long0); - integer1 = new SimpleIntegerProperty(integer0); - } - - @Test - public void testDouble() { - Binding binding = func.generateExpression(double1, double1); - assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); - func.check(double0, double0, binding); - - binding = func.generateExpression(double1, float1); - assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); - func.check(double0, float0, binding); - - binding = func.generateExpression(double1, long1); - assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); - func.check(double0, long0, binding); - - binding = func.generateExpression(double1, integer1); - assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); - func.check(double0, integer0, binding); - } - - @Test - public void testFloat() { - Binding binding = func.generateExpression(float1, double1); - assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); - func.check(float0, double0, binding); - - binding = func.generateExpression(float1, float1); - assertTrue(binding instanceof FloatExpression || binding instanceof BooleanExpression); - func.check(float0, float0, binding); - - binding = func.generateExpression(float1, long1); - assertTrue(binding instanceof FloatExpression || binding instanceof BooleanExpression); - func.check(float0, long0, binding); - - binding = func.generateExpression(float1, integer1); - assertTrue(binding instanceof FloatExpression || binding instanceof BooleanExpression); - func.check(float0, integer0, binding); - } - - @Test - public void testLong() { - Binding binding = func.generateExpression(long1, double1); - assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); - func.check(long0, double0, binding); - - binding = func.generateExpression(long1, float1); - assertTrue(binding instanceof FloatExpression || binding instanceof BooleanExpression); - func.check(long0, float0, binding); - - binding = func.generateExpression(long1, long1); - assertTrue(binding instanceof LongExpression || binding instanceof BooleanExpression); - func.check(long0, long0, binding); - - binding = func.generateExpression(long1, integer1); - assertTrue(binding instanceof LongExpression || binding instanceof BooleanExpression); - func.check(long0, integer0, binding); - } - - @Test - public void testInteger() { - Binding binding = func.generateExpression(integer1, double1); - assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); - func.check(integer0, double0, binding); - - binding = func.generateExpression(integer1, float1); - assertTrue(binding instanceof FloatExpression || binding instanceof BooleanExpression); - func.check(integer0, float0, binding); - - binding = func.generateExpression(integer1, long1); - assertTrue(binding instanceof LongExpression || binding instanceof BooleanExpression); - func.check(integer0, long0, binding); - - binding = func.generateExpression(integer1, integer1); - assertTrue(binding instanceof IntegerExpression || binding instanceof BooleanExpression); - func.check(integer0, integer0, binding); - } - - @Parameterized.Parameters - public static Collection parameters() { - return Arrays.asList(new Object[][] { - { - new Functions() { - @Override - public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { - return Bindings.add(op1, op2); - } - - @Override - public void check(double op1, double op2, Binding binding) { - assertTrue(binding instanceof NumberExpression); - assertEquals(op1 + op2, ((NumberExpression)binding).doubleValue(), EPSILON); - } - - } - }, - { - new Functions() { - @Override - public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { - return Bindings.multiply(op1, op2); - } - - @Override - public void check(double op1, double op2, Binding binding) { - assertTrue(binding instanceof NumberExpression); - assertEquals(op1 * op2, ((NumberExpression)binding).doubleValue(), EPSILON); - } - - } - }, - { - new Functions() { - @Override - public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { - return Bindings.divide(op1, op2); - } - - @Override - public void check(double op1, double op2, Binding binding) { - assertTrue(binding instanceof NumberExpression); - if ((binding instanceof DoubleExpression) || (binding instanceof FloatExpression)) { - assertEquals(op1 / op2, ((NumberExpression)binding).doubleValue(), EPSILON); - } else { - assertEquals((long)op1 / (long)op2, ((NumberExpression)binding).longValue()); - } - } - - } - }, - { - new Functions() { - @Override - public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { - return Bindings.min(op1, op2); - } - - @Override - public void check(double op1, double op2, Binding binding) { - assertTrue(binding instanceof NumberExpression); - assertEquals(Math.min(op1, op2), ((NumberExpression)binding).doubleValue(), EPSILON); - } - - } - }, - { - new Functions() { - @Override - public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { - return Bindings.max(op1, op2); - } - - @Override - public void check(double op1, double op2, Binding binding) { - assertTrue(binding instanceof NumberExpression); - assertEquals(Math.max(op1, op2), ((NumberExpression)binding).doubleValue(), EPSILON); - } - - } - }, - { - new Functions() { - @Override - public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { - return Bindings.equal(op1, op2); - } - - @Override - public void check(double op1, double op2, Binding binding) { - assertTrue(binding instanceof BooleanExpression); - assertEquals(Math.abs(op1 - op2) < EPSILON, ((BooleanExpression)binding).get()); - } - - } - }, - { - new Functions() { - @Override - public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { - return Bindings.greaterThan(op1, op2); - } - - @Override - public void check(double op1, double op2, Binding binding) { - assertTrue(binding instanceof BooleanExpression); - assertEquals(op1 > op2, ((BooleanExpression)binding).get()); - } - - } - }, - }); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/BindingsNumberCastTest.java 2015-08-31 10:24:28.613216786 -0400 @@ -0,0 +1,287 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.Collection; + +import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.binding.BooleanExpression; +import javafx.beans.binding.DoubleExpression; +import javafx.beans.binding.FloatExpression; +import javafx.beans.binding.IntegerExpression; +import javafx.beans.binding.LongExpression; +import javafx.beans.binding.NumberExpression; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.FloatProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.LongProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.value.ObservableNumberValue; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class BindingsNumberCastTest { + + public static interface Functions { + Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2); + void check(double op1, double op2, Binding binding); + } + + private static final double EPSILON = 1e-5; + + private final Functions func; + + private Double double0; + private Float float0; + private Long long0; + private Integer integer0; + + private DoubleProperty double1; + private FloatProperty float1; + private LongProperty long1; + private IntegerProperty integer1; + + public BindingsNumberCastTest(Functions func) { + this.func = func; + } + + @Before + public void setUp() { + double0 = Double.valueOf(3.1415); + float0 = Float.valueOf(2.71f); + long0 = Long.valueOf(111L); + integer0 = Integer.valueOf(42); + + double1 = new SimpleDoubleProperty(double0); + float1 = new SimpleFloatProperty(float0); + long1 = new SimpleLongProperty(long0); + integer1 = new SimpleIntegerProperty(integer0); + } + + @Test + public void testDouble() { + Binding binding = func.generateExpression(double1, double1); + assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); + func.check(double0, double0, binding); + + binding = func.generateExpression(double1, float1); + assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); + func.check(double0, float0, binding); + + binding = func.generateExpression(double1, long1); + assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); + func.check(double0, long0, binding); + + binding = func.generateExpression(double1, integer1); + assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); + func.check(double0, integer0, binding); + } + + @Test + public void testFloat() { + Binding binding = func.generateExpression(float1, double1); + assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); + func.check(float0, double0, binding); + + binding = func.generateExpression(float1, float1); + assertTrue(binding instanceof FloatExpression || binding instanceof BooleanExpression); + func.check(float0, float0, binding); + + binding = func.generateExpression(float1, long1); + assertTrue(binding instanceof FloatExpression || binding instanceof BooleanExpression); + func.check(float0, long0, binding); + + binding = func.generateExpression(float1, integer1); + assertTrue(binding instanceof FloatExpression || binding instanceof BooleanExpression); + func.check(float0, integer0, binding); + } + + @Test + public void testLong() { + Binding binding = func.generateExpression(long1, double1); + assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); + func.check(long0, double0, binding); + + binding = func.generateExpression(long1, float1); + assertTrue(binding instanceof FloatExpression || binding instanceof BooleanExpression); + func.check(long0, float0, binding); + + binding = func.generateExpression(long1, long1); + assertTrue(binding instanceof LongExpression || binding instanceof BooleanExpression); + func.check(long0, long0, binding); + + binding = func.generateExpression(long1, integer1); + assertTrue(binding instanceof LongExpression || binding instanceof BooleanExpression); + func.check(long0, integer0, binding); + } + + @Test + public void testInteger() { + Binding binding = func.generateExpression(integer1, double1); + assertTrue(binding instanceof DoubleExpression || binding instanceof BooleanExpression); + func.check(integer0, double0, binding); + + binding = func.generateExpression(integer1, float1); + assertTrue(binding instanceof FloatExpression || binding instanceof BooleanExpression); + func.check(integer0, float0, binding); + + binding = func.generateExpression(integer1, long1); + assertTrue(binding instanceof LongExpression || binding instanceof BooleanExpression); + func.check(integer0, long0, binding); + + binding = func.generateExpression(integer1, integer1); + assertTrue(binding instanceof IntegerExpression || binding instanceof BooleanExpression); + func.check(integer0, integer0, binding); + } + + @Parameterized.Parameters + public static Collection parameters() { + return Arrays.asList(new Object[][] { + { + new Functions() { + @Override + public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { + return Bindings.add(op1, op2); + } + + @Override + public void check(double op1, double op2, Binding binding) { + assertTrue(binding instanceof NumberExpression); + assertEquals(op1 + op2, ((NumberExpression)binding).doubleValue(), EPSILON); + } + + } + }, + { + new Functions() { + @Override + public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { + return Bindings.multiply(op1, op2); + } + + @Override + public void check(double op1, double op2, Binding binding) { + assertTrue(binding instanceof NumberExpression); + assertEquals(op1 * op2, ((NumberExpression)binding).doubleValue(), EPSILON); + } + + } + }, + { + new Functions() { + @Override + public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { + return Bindings.divide(op1, op2); + } + + @Override + public void check(double op1, double op2, Binding binding) { + assertTrue(binding instanceof NumberExpression); + if ((binding instanceof DoubleExpression) || (binding instanceof FloatExpression)) { + assertEquals(op1 / op2, ((NumberExpression)binding).doubleValue(), EPSILON); + } else { + assertEquals((long)op1 / (long)op2, ((NumberExpression)binding).longValue()); + } + } + + } + }, + { + new Functions() { + @Override + public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { + return Bindings.min(op1, op2); + } + + @Override + public void check(double op1, double op2, Binding binding) { + assertTrue(binding instanceof NumberExpression); + assertEquals(Math.min(op1, op2), ((NumberExpression)binding).doubleValue(), EPSILON); + } + + } + }, + { + new Functions() { + @Override + public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { + return Bindings.max(op1, op2); + } + + @Override + public void check(double op1, double op2, Binding binding) { + assertTrue(binding instanceof NumberExpression); + assertEquals(Math.max(op1, op2), ((NumberExpression)binding).doubleValue(), EPSILON); + } + + } + }, + { + new Functions() { + @Override + public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { + return Bindings.equal(op1, op2); + } + + @Override + public void check(double op1, double op2, Binding binding) { + assertTrue(binding instanceof BooleanExpression); + assertEquals(Math.abs(op1 - op2) < EPSILON, ((BooleanExpression)binding).get()); + } + + } + }, + { + new Functions() { + @Override + public Binding generateExpression(ObservableNumberValue op1, ObservableNumberValue op2) { + return Bindings.greaterThan(op1, op2); + } + + @Override + public void check(double op1, double op2, Binding binding) { + assertTrue(binding instanceof BooleanExpression); + assertEquals(op1 > op2, ((BooleanExpression)binding).get()); + } + + } + }, + }); + } + +} --- old/modules/base/src/test/java/javafx/binding/BindingsSetTest.java 2015-08-31 10:24:29.565216776 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import javafx.beans.binding.*; -import javafx.beans.property.SetProperty; -import javafx.beans.property.SimpleSetProperty; -import javafx.collections.FXCollections; -import javafx.collections.ObservableSet; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class BindingsSetTest { - - private static final Object data1 = new Object(); - private static final Object data2 = new Object(); - - private SetProperty property; - private ObservableSet set1; - private ObservableSet set2; - - @Before - public void setUp() { - property = new SimpleSetProperty(); - set1 = FXCollections.observableSet(data1, data2); - set2 = FXCollections.observableSet(); - } - - @Test - public void testSize() { - final IntegerBinding size = Bindings.size(property); - DependencyUtils.checkDependencies(size.getDependencies(), property); - - assertEquals(0, size.get()); - property.set(set1); - assertEquals(2, size.get()); - set1.remove(data2); - assertEquals(1, size.get()); - property.set(set2); - assertEquals(0, size.get()); - property.add(data2); - property.add(data2); - assertEquals(1, size.get()); - property.set(null); - assertEquals(0, size.get()); - } - - @Test(expected = NullPointerException.class) - public void testSize_Null() { - Bindings.size((ObservableSet) null); - } - - @Test - public void testIsEmpty() { - final BooleanBinding empty = Bindings.isEmpty(property); - DependencyUtils.checkDependencies(empty.getDependencies(), property); - - assertTrue(empty.get()); - property.set(set1); - assertFalse(empty.get()); - set1.remove(data2); - assertFalse(empty.get()); - property.set(set2); - assertTrue(empty.get()); - property.add(data2); - property.add(data2); - assertFalse(empty.get()); - property.set(null); - assertTrue(empty.get()); - } - - @Test(expected = NullPointerException.class) - public void testIsEmpty_Null() { - Bindings.isEmpty((ObservableSet) null); - } - - @Test - public void testIsNotEmpty() { - final BooleanBinding notEmpty = Bindings.isNotEmpty(property); - DependencyUtils.checkDependencies(notEmpty.getDependencies(), property); - - assertFalse(notEmpty.get()); - property.set(set1); - assertTrue(notEmpty.get()); - set1.remove(data2); - assertTrue(notEmpty.get()); - property.set(set2); - assertFalse(notEmpty.get()); - property.add(data2); - property.add(data2); - assertTrue(notEmpty.get()); - property.set(null); - assertFalse(notEmpty.get()); - } - - @Test(expected = NullPointerException.class) - public void testIsNotEmpty_Null() { - Bindings.isNotEmpty((ObservableSet) null); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/BindingsSetTest.java 2015-08-31 10:24:29.377216778 -0400 @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import javafx.beans.binding.*; +import javafx.beans.property.SetProperty; +import javafx.beans.property.SimpleSetProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableSet; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class BindingsSetTest { + + private static final Object data1 = new Object(); + private static final Object data2 = new Object(); + + private SetProperty property; + private ObservableSet set1; + private ObservableSet set2; + + @Before + public void setUp() { + property = new SimpleSetProperty(); + set1 = FXCollections.observableSet(data1, data2); + set2 = FXCollections.observableSet(); + } + + @Test + public void testSize() { + final IntegerBinding size = Bindings.size(property); + DependencyUtils.checkDependencies(size.getDependencies(), property); + + assertEquals(0, size.get()); + property.set(set1); + assertEquals(2, size.get()); + set1.remove(data2); + assertEquals(1, size.get()); + property.set(set2); + assertEquals(0, size.get()); + property.add(data2); + property.add(data2); + assertEquals(1, size.get()); + property.set(null); + assertEquals(0, size.get()); + } + + @Test(expected = NullPointerException.class) + public void testSize_Null() { + Bindings.size((ObservableSet) null); + } + + @Test + public void testIsEmpty() { + final BooleanBinding empty = Bindings.isEmpty(property); + DependencyUtils.checkDependencies(empty.getDependencies(), property); + + assertTrue(empty.get()); + property.set(set1); + assertFalse(empty.get()); + set1.remove(data2); + assertFalse(empty.get()); + property.set(set2); + assertTrue(empty.get()); + property.add(data2); + property.add(data2); + assertFalse(empty.get()); + property.set(null); + assertTrue(empty.get()); + } + + @Test(expected = NullPointerException.class) + public void testIsEmpty_Null() { + Bindings.isEmpty((ObservableSet) null); + } + + @Test + public void testIsNotEmpty() { + final BooleanBinding notEmpty = Bindings.isNotEmpty(property); + DependencyUtils.checkDependencies(notEmpty.getDependencies(), property); + + assertFalse(notEmpty.get()); + property.set(set1); + assertTrue(notEmpty.get()); + set1.remove(data2); + assertTrue(notEmpty.get()); + property.set(set2); + assertFalse(notEmpty.get()); + property.add(data2); + property.add(data2); + assertTrue(notEmpty.get()); + property.set(null); + assertFalse(notEmpty.get()); + } + + @Test(expected = NullPointerException.class) + public void testIsNotEmpty_Null() { + Bindings.isNotEmpty((ObservableSet) null); + } +} --- old/modules/base/src/test/java/javafx/binding/DependencyUtils.java 2015-08-31 10:24:30.173216769 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import java.util.ListIterator; - -import javafx.beans.binding.Binding; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import static org.junit.Assert.*; - -public class DependencyUtils { - - public static void checkDependencies(ObservableList seq, Object... deps) { - // we want to check the source dependencies, therefore we have to - // remove all intermediate bindings - final ObservableList copy = FXCollections.observableArrayList(seq); - final ListIterator it = copy.listIterator(); - while (it.hasNext()) { - final Object obj = it.next(); - if (obj instanceof Binding) { - it.remove(); - final Binding binding = (Binding)obj; - for (final Object newDep : binding.getDependencies()) { - it.add(newDep); - } - } - } - for (final Object obj : deps) { - assertTrue(copy.contains(obj)); - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/DependencyUtils.java 2015-08-31 10:24:30.041216770 -0400 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import java.util.ListIterator; + +import javafx.beans.binding.Binding; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import static org.junit.Assert.*; + +public class DependencyUtils { + + public static void checkDependencies(ObservableList seq, Object... deps) { + // we want to check the source dependencies, therefore we have to + // remove all intermediate bindings + final ObservableList copy = FXCollections.observableArrayList(seq); + final ListIterator it = copy.listIterator(); + while (it.hasNext()) { + final Object obj = it.next(); + if (obj instanceof Binding) { + it.remove(); + final Binding binding = (Binding)obj; + for (final Object newDep : binding.getDependencies()) { + it.add(newDep); + } + } + } + for (final Object obj : deps) { + assertTrue(copy.contains(obj)); + } + } + +} --- old/modules/base/src/test/java/javafx/binding/GenericBindingTest.java 2015-08-31 10:24:30.925216760 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,640 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import com.sun.javafx.collections.annotations.ReturnsUnmodifiableCollection; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.Observable; -import javafx.beans.binding.*; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableValueBase; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import java.util.Arrays; -import java.util.Collection; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -@RunWith(Parameterized.class) -public class GenericBindingTest { - - private static final Object UNDEFINED = null; - - private final ObservableStub dependency1; - private final ObservableStub dependency2; - private final BindingMock binding0; - private final BindingMock binding1; - private final BindingMock binding2; - private final T value1; - private final T value2; - private InvalidationListenerMock invalidationListener; - private ChangeListenerMock changeListener; - - public GenericBindingTest( - T value1, T value2, - ObservableStub dependency1, - ObservableStub dependency2, - BindingMock binding0, BindingMock binding1, BindingMock binding2) { - this.value1 = value1; - this.value2 = value2; - this.dependency1 = dependency1; - this.dependency2 = dependency2; - this.binding0 = binding0; - this.binding1 = binding1; - this.binding2 = binding2; - } - - @Before - public void setUp() { - invalidationListener = new InvalidationListenerMock(); - changeListener = new ChangeListenerMock(UNDEFINED); - binding0.setValue(value2); - binding1.setValue(value2); - binding2.setValue(value2); - } - - @After - public void tearDown() { - binding0.removeListener(invalidationListener); - binding0.removeListener(changeListener); - binding1.removeListener(invalidationListener); - binding1.removeListener(changeListener); - binding2.removeListener(invalidationListener); - binding2.removeListener(changeListener); - } - - @Test - public void testNoDependencyLazy() { - binding0.getValue(); - binding0.addListener(invalidationListener); - System.gc(); // making sure we did not not overdo weak references - assertEquals(true, binding0.isValid()); - - // calling getValue() - binding0.reset(); - binding0.getValue(); - assertEquals(0, binding0.getComputeValueCounter()); - invalidationListener.check(null, 0); - assertEquals(true, binding0.isValid()); - } - - @Test - public void testNoDependencyEager() { - binding0.getValue(); - binding0.addListener(changeListener); - System.gc(); // making sure we did not not overdo weak references - assertEquals(true, binding0.isValid()); - - // calling getValue() - binding0.reset(); - binding0.getValue(); - assertEquals(0, binding0.getComputeValueCounter()); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(true, binding0.isValid()); - } - - @Test - public void testSingleDependencyLazy() { - binding1.getValue(); - binding1.addListener(invalidationListener); - System.gc(); // making sure we did not not overdo weak references - assertEquals(true, binding1.isValid()); - - // fire single change event - binding1.reset(); - invalidationListener.reset(); - binding1.setValue(value1); - dependency1.fireValueChangedEvent(); - assertEquals(0, binding1.getComputeValueCounter()); - invalidationListener.check(binding1, 1); - assertEquals(false, binding1.isValid()); - - binding1.getValue(); - assertEquals(1, binding1.getComputeValueCounter()); - invalidationListener.check(null, 0); - assertEquals(true, binding1.isValid()); - - // fire single change event with same value - binding1.setValue(value1); - dependency1.fireValueChangedEvent(); - assertEquals(0, binding1.getComputeValueCounter()); - invalidationListener.check(binding1, 1); - assertEquals(false, binding1.isValid()); - - binding1.getValue(); - assertEquals(1, binding1.getComputeValueCounter()); - invalidationListener.check(null, 0); - assertEquals(true, binding1.isValid()); - - // fire two change events with different values - binding1.setValue(value2); - dependency1.fireValueChangedEvent(); - binding1.setValue(value1); - dependency1.fireValueChangedEvent(); - assertEquals(0, binding1.getComputeValueCounter()); - invalidationListener.check(binding1, 1); - assertEquals(false, binding1.isValid()); - - binding1.getValue(); - assertEquals(1, binding1.getComputeValueCounter()); - invalidationListener.check(null, 0); - assertEquals(true, binding1.isValid()); - - // fire two change events with same values - binding1.setValue(value2); - dependency1.fireValueChangedEvent(); - binding1.setValue(value2); - dependency1.fireValueChangedEvent(); - assertEquals(0, binding1.getComputeValueCounter()); - invalidationListener.check(binding1, 1); - assertEquals(false, binding1.isValid()); - - binding1.getValue(); - assertEquals(1, binding1.getComputeValueCounter()); - invalidationListener.check(null, 0); - assertEquals(true, binding1.isValid()); - } - - @Test - public void testSingleDependencyEager() { - binding1.getValue(); - binding1.addListener(changeListener); - System.gc(); // making sure we did not not overdo weak references - assertEquals(true, binding1.isValid()); - - // fire single change event - binding1.reset(); - changeListener.reset(); - binding1.setValue(value1); - dependency1.fireValueChangedEvent(); - assertEquals(1, binding1.getComputeValueCounter()); - changeListener.check(binding1, value2, value1, 1); - assertEquals(true, binding1.isValid()); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(true, binding1.isValid()); - - // fire single change event with same value - binding1.setValue(value1); - dependency1.fireValueChangedEvent(); - assertEquals(1, binding1.getComputeValueCounter()); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(true, binding1.isValid()); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(true, binding1.isValid()); - - // fire two change events - binding1.setValue(value2); - dependency1.fireValueChangedEvent(); - binding1.setValue(value1); - dependency1.fireValueChangedEvent(); - assertEquals(2, binding1.getComputeValueCounter()); - changeListener.check(binding1, value2, value1, 2); - assertEquals(true, binding1.isValid()); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(true, binding1.isValid()); - - // fire two change events with same value - binding1.setValue(value2); - dependency1.fireValueChangedEvent(); - binding1.setValue(value2); - dependency1.fireValueChangedEvent(); - assertEquals(2, binding1.getComputeValueCounter()); - changeListener.check(binding1, value1, value2, 1); - assertEquals(true, binding1.isValid()); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - changeListener.check(null, UNDEFINED, UNDEFINED, 0); - assertEquals(true, binding1.isValid()); - } - - @Test - public void testTwoDependencies() { - binding2.getValue(); - binding2.addListener(invalidationListener); - System.gc(); // making sure we did not not overdo weak references - assertEquals(true, binding2.isValid()); - - // fire single change event on first dependency - binding2.reset(); - invalidationListener.reset(); - dependency1.fireValueChangedEvent(); - assertEquals(0, binding2.getComputeValueCounter()); - invalidationListener.check(binding2, 1); - assertEquals(false, binding2.isValid()); - - binding2.getValue(); - assertEquals(1, binding2.getComputeValueCounter()); - invalidationListener.check(null, 0); - assertEquals(true, binding2.isValid()); - - // fire single change event on second dependency - binding2.reset(); - dependency2.fireValueChangedEvent(); - assertEquals(0, binding2.getComputeValueCounter()); - invalidationListener.check(binding2, 1); - assertEquals(false, binding2.isValid()); - - binding2.getValue(); - assertEquals(1, binding2.getComputeValueCounter()); - invalidationListener.check(null, 0); - assertEquals(true, binding2.isValid()); - - // fire change events on each dependency - binding2.reset(); - dependency1.fireValueChangedEvent(); - dependency2.fireValueChangedEvent(); - assertEquals(0, binding2.getComputeValueCounter()); - invalidationListener.check(binding2, 1); - assertEquals(false, binding2.isValid()); - - binding2.getValue(); - assertEquals(1, binding2.getComputeValueCounter()); - invalidationListener.check(null, 0); - assertEquals(true, binding2.isValid()); - } - - @Parameterized.Parameters - public static Collection parameters() { - final ObservableStub dependency1 = new ObservableStub(); - final ObservableStub dependency2 = new ObservableStub(); - return Arrays.asList(new Object[][] { - { - Float.MIN_VALUE, Float.MAX_VALUE, - dependency1, dependency2, - new FloatBindingImpl(), - new FloatBindingImpl(dependency1), - new FloatBindingImpl(dependency1, dependency2), - }, - { - Double.MIN_VALUE, Double.MAX_VALUE, - dependency1, dependency2, - new DoubleBindingImpl(), - new DoubleBindingImpl(dependency1), - new DoubleBindingImpl(dependency1, dependency2), - }, - { - Long.MIN_VALUE, Long.MAX_VALUE, - dependency1, dependency2, - new LongBindingImpl(), - new LongBindingImpl(dependency1), - new LongBindingImpl(dependency1, dependency2), - }, - { - Integer.MIN_VALUE, Integer.MAX_VALUE, - dependency1, dependency2, - new IntegerBindingImpl(), - new IntegerBindingImpl(dependency1), - new IntegerBindingImpl(dependency1, dependency2), - }, - { - true, false, - dependency1, dependency2, - new BooleanBindingImpl(), - new BooleanBindingImpl(dependency1), - new BooleanBindingImpl(dependency1, dependency2), - }, - { - "Hello World", "Goodbye", - dependency1, dependency2, - new StringBindingImpl(), - new StringBindingImpl(dependency1), - new StringBindingImpl(dependency1, dependency2), - }, - { - new Object(), new Object(), - dependency1, dependency2, - new ObjectBindingImpl(), - new ObjectBindingImpl(dependency1), - new ObjectBindingImpl(dependency1, dependency2), - }, - { - FXCollections.observableArrayList(), FXCollections.observableArrayList(), - dependency1, dependency2, - new ListBindingImpl(), - new ListBindingImpl(dependency1), - new ListBindingImpl(dependency1, dependency2), - }, - }); - } - - public static class ObservableStub extends ObservableValueBase { - @Override public void fireValueChangedEvent() {super.fireValueChangedEvent();} - - @Override - public Object getValue() { - return null; - } - } - - public static interface BindingMock extends Binding { - int getComputeValueCounter(); - void reset(); - void setValue(T value); - } - - private static class DoubleBindingImpl extends DoubleBinding implements BindingMock { - - private int computeValueCounter = 0; - private double value; - - @Override - public void setValue(Number value) {this.value = value.doubleValue();} - - public DoubleBindingImpl(Observable... dep) { - super.bind(dep); - } - - @Override public int getComputeValueCounter() { - final int result = computeValueCounter; - reset(); - return result; - } - - @Override public void reset() {computeValueCounter = 0;} - - @Override - public double computeValue() { - computeValueCounter++; - return value; - } - - @Override @ReturnsUnmodifiableCollection - public ObservableList getDependencies() { - fail("Should not reach here"); - return null; - } - } - - private static class FloatBindingImpl extends FloatBinding implements BindingMock { - - private int computeValueCounter = 0; - private float value; - - @Override - public void setValue(Number value) {this.value = value.floatValue();} - - public FloatBindingImpl(Observable... dep) { - super.bind(dep); - } - - @Override public int getComputeValueCounter() { - final int result = computeValueCounter; - reset(); - return result; - } - - @Override public void reset() {computeValueCounter = 0;} - - @Override - public float computeValue() { - computeValueCounter++; - return value; - } - - @Override @ReturnsUnmodifiableCollection - public ObservableList getDependencies() { - fail("Should not reach here"); - return null; - } - } - - private static class LongBindingImpl extends LongBinding implements BindingMock { - - private int computeValueCounter = 0; - private long value; - - @Override - public void setValue(Number value) {this.value = value.longValue();} - - public LongBindingImpl(Observable... dep) { - super.bind(dep); - } - - @Override public int getComputeValueCounter() { - final int result = computeValueCounter; - reset(); - return result; - } - - @Override public void reset() {computeValueCounter = 0;} - - @Override - public long computeValue() { - computeValueCounter++; - return value; - } - - @Override @ReturnsUnmodifiableCollection - public ObservableList getDependencies() { - fail("Should not reach here"); - return null; - } - } - - private static class IntegerBindingImpl extends IntegerBinding implements BindingMock { - - private int computeValueCounter = 0; - private int value; - - @Override - public void setValue(Number value) {this.value = value.intValue();} - - public IntegerBindingImpl(Observable... dep) { - super.bind(dep); - } - - @Override public int getComputeValueCounter() { - final int result = computeValueCounter; - reset(); - return result; - } - - @Override public void reset() {computeValueCounter = 0;} - - @Override - public int computeValue() { - computeValueCounter++; - return value; - } - - @Override @ReturnsUnmodifiableCollection - public ObservableList getDependencies() { - fail("Should not reach here"); - return null; - } - } - - private static class BooleanBindingImpl extends BooleanBinding implements BindingMock { - - private int computeValueCounter = 0; - private boolean value; - - @Override - public void setValue(Boolean value) {this.value = value;} - - public BooleanBindingImpl(Observable... dep) { - super.bind(dep); - } - - @Override public int getComputeValueCounter() { - final int result = computeValueCounter; - reset(); - return result; - } - - @Override public void reset() {computeValueCounter = 0;} - - @Override - public boolean computeValue() { - computeValueCounter++; - return value; - } - - @Override @ReturnsUnmodifiableCollection - public ObservableList getDependencies() { - fail("Should not reach here"); - return null; - } - } - - private static class ObjectBindingImpl extends ObjectBinding implements BindingMock { - - private int computeValueCounter = 0; - private Object value; - - @Override - public void setValue(Object value) {this.value = value;} - - public ObjectBindingImpl(Observable... dep) { - super.bind(dep); - } - - @Override public int getComputeValueCounter() { - final int result = computeValueCounter; - reset(); - return result; - } - - @Override public void reset() {computeValueCounter = 0;} - - @Override - public Object computeValue() { - computeValueCounter++; - return value; - } - - @Override @ReturnsUnmodifiableCollection - public ObservableList getDependencies() { - fail("Should not reach here"); - return null; - } - } - - private static class StringBindingImpl extends StringBinding implements BindingMock { - - private int computeValueCounter = 0; - private String value; - - @Override - public void setValue(String value) {this.value = value;} - - public StringBindingImpl(Observable... dep) { - super.bind(dep); - } - - @Override public int getComputeValueCounter() { - final int result = computeValueCounter; - reset(); - return result; - } - - @Override public void reset() {computeValueCounter = 0;} - - @Override - public String computeValue() { - computeValueCounter++; - return value; - } - - @Override @ReturnsUnmodifiableCollection - public ObservableList getDependencies() { - fail("Should not reach here"); - return null; - } - } - - private static class ListBindingImpl extends ListBinding implements BindingMock> { - - private int computeValueCounter = 0; - private ObservableList value; - - @Override - public void setValue(ObservableList value) {this.value = value;} - - public ListBindingImpl(Observable... dep) { - super.bind(dep); - } - - @Override public int getComputeValueCounter() { - final int result = computeValueCounter; - reset(); - return result; - } - - @Override public void reset() {computeValueCounter = 0;} - - @Override - public ObservableList computeValue() { - computeValueCounter++; - return value; - } - - @Override @ReturnsUnmodifiableCollection - public ObservableList getDependencies() { - fail("Should not reach here"); - return null; - } - } - - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/GenericBindingTest.java 2015-08-31 10:24:30.793216762 -0400 @@ -0,0 +1,640 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import com.sun.javafx.collections.annotations.ReturnsUnmodifiableCollection; +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.Observable; +import javafx.beans.binding.*; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableValueBase; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; +import java.util.Collection; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +@RunWith(Parameterized.class) +public class GenericBindingTest { + + private static final Object UNDEFINED = null; + + private final ObservableStub dependency1; + private final ObservableStub dependency2; + private final BindingMock binding0; + private final BindingMock binding1; + private final BindingMock binding2; + private final T value1; + private final T value2; + private InvalidationListenerMock invalidationListener; + private ChangeListenerMock changeListener; + + public GenericBindingTest( + T value1, T value2, + ObservableStub dependency1, + ObservableStub dependency2, + BindingMock binding0, BindingMock binding1, BindingMock binding2) { + this.value1 = value1; + this.value2 = value2; + this.dependency1 = dependency1; + this.dependency2 = dependency2; + this.binding0 = binding0; + this.binding1 = binding1; + this.binding2 = binding2; + } + + @Before + public void setUp() { + invalidationListener = new InvalidationListenerMock(); + changeListener = new ChangeListenerMock(UNDEFINED); + binding0.setValue(value2); + binding1.setValue(value2); + binding2.setValue(value2); + } + + @After + public void tearDown() { + binding0.removeListener(invalidationListener); + binding0.removeListener(changeListener); + binding1.removeListener(invalidationListener); + binding1.removeListener(changeListener); + binding2.removeListener(invalidationListener); + binding2.removeListener(changeListener); + } + + @Test + public void testNoDependencyLazy() { + binding0.getValue(); + binding0.addListener(invalidationListener); + System.gc(); // making sure we did not not overdo weak references + assertEquals(true, binding0.isValid()); + + // calling getValue() + binding0.reset(); + binding0.getValue(); + assertEquals(0, binding0.getComputeValueCounter()); + invalidationListener.check(null, 0); + assertEquals(true, binding0.isValid()); + } + + @Test + public void testNoDependencyEager() { + binding0.getValue(); + binding0.addListener(changeListener); + System.gc(); // making sure we did not not overdo weak references + assertEquals(true, binding0.isValid()); + + // calling getValue() + binding0.reset(); + binding0.getValue(); + assertEquals(0, binding0.getComputeValueCounter()); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(true, binding0.isValid()); + } + + @Test + public void testSingleDependencyLazy() { + binding1.getValue(); + binding1.addListener(invalidationListener); + System.gc(); // making sure we did not not overdo weak references + assertEquals(true, binding1.isValid()); + + // fire single change event + binding1.reset(); + invalidationListener.reset(); + binding1.setValue(value1); + dependency1.fireValueChangedEvent(); + assertEquals(0, binding1.getComputeValueCounter()); + invalidationListener.check(binding1, 1); + assertEquals(false, binding1.isValid()); + + binding1.getValue(); + assertEquals(1, binding1.getComputeValueCounter()); + invalidationListener.check(null, 0); + assertEquals(true, binding1.isValid()); + + // fire single change event with same value + binding1.setValue(value1); + dependency1.fireValueChangedEvent(); + assertEquals(0, binding1.getComputeValueCounter()); + invalidationListener.check(binding1, 1); + assertEquals(false, binding1.isValid()); + + binding1.getValue(); + assertEquals(1, binding1.getComputeValueCounter()); + invalidationListener.check(null, 0); + assertEquals(true, binding1.isValid()); + + // fire two change events with different values + binding1.setValue(value2); + dependency1.fireValueChangedEvent(); + binding1.setValue(value1); + dependency1.fireValueChangedEvent(); + assertEquals(0, binding1.getComputeValueCounter()); + invalidationListener.check(binding1, 1); + assertEquals(false, binding1.isValid()); + + binding1.getValue(); + assertEquals(1, binding1.getComputeValueCounter()); + invalidationListener.check(null, 0); + assertEquals(true, binding1.isValid()); + + // fire two change events with same values + binding1.setValue(value2); + dependency1.fireValueChangedEvent(); + binding1.setValue(value2); + dependency1.fireValueChangedEvent(); + assertEquals(0, binding1.getComputeValueCounter()); + invalidationListener.check(binding1, 1); + assertEquals(false, binding1.isValid()); + + binding1.getValue(); + assertEquals(1, binding1.getComputeValueCounter()); + invalidationListener.check(null, 0); + assertEquals(true, binding1.isValid()); + } + + @Test + public void testSingleDependencyEager() { + binding1.getValue(); + binding1.addListener(changeListener); + System.gc(); // making sure we did not not overdo weak references + assertEquals(true, binding1.isValid()); + + // fire single change event + binding1.reset(); + changeListener.reset(); + binding1.setValue(value1); + dependency1.fireValueChangedEvent(); + assertEquals(1, binding1.getComputeValueCounter()); + changeListener.check(binding1, value2, value1, 1); + assertEquals(true, binding1.isValid()); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(true, binding1.isValid()); + + // fire single change event with same value + binding1.setValue(value1); + dependency1.fireValueChangedEvent(); + assertEquals(1, binding1.getComputeValueCounter()); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(true, binding1.isValid()); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(true, binding1.isValid()); + + // fire two change events + binding1.setValue(value2); + dependency1.fireValueChangedEvent(); + binding1.setValue(value1); + dependency1.fireValueChangedEvent(); + assertEquals(2, binding1.getComputeValueCounter()); + changeListener.check(binding1, value2, value1, 2); + assertEquals(true, binding1.isValid()); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(true, binding1.isValid()); + + // fire two change events with same value + binding1.setValue(value2); + dependency1.fireValueChangedEvent(); + binding1.setValue(value2); + dependency1.fireValueChangedEvent(); + assertEquals(2, binding1.getComputeValueCounter()); + changeListener.check(binding1, value1, value2, 1); + assertEquals(true, binding1.isValid()); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + changeListener.check(null, UNDEFINED, UNDEFINED, 0); + assertEquals(true, binding1.isValid()); + } + + @Test + public void testTwoDependencies() { + binding2.getValue(); + binding2.addListener(invalidationListener); + System.gc(); // making sure we did not not overdo weak references + assertEquals(true, binding2.isValid()); + + // fire single change event on first dependency + binding2.reset(); + invalidationListener.reset(); + dependency1.fireValueChangedEvent(); + assertEquals(0, binding2.getComputeValueCounter()); + invalidationListener.check(binding2, 1); + assertEquals(false, binding2.isValid()); + + binding2.getValue(); + assertEquals(1, binding2.getComputeValueCounter()); + invalidationListener.check(null, 0); + assertEquals(true, binding2.isValid()); + + // fire single change event on second dependency + binding2.reset(); + dependency2.fireValueChangedEvent(); + assertEquals(0, binding2.getComputeValueCounter()); + invalidationListener.check(binding2, 1); + assertEquals(false, binding2.isValid()); + + binding2.getValue(); + assertEquals(1, binding2.getComputeValueCounter()); + invalidationListener.check(null, 0); + assertEquals(true, binding2.isValid()); + + // fire change events on each dependency + binding2.reset(); + dependency1.fireValueChangedEvent(); + dependency2.fireValueChangedEvent(); + assertEquals(0, binding2.getComputeValueCounter()); + invalidationListener.check(binding2, 1); + assertEquals(false, binding2.isValid()); + + binding2.getValue(); + assertEquals(1, binding2.getComputeValueCounter()); + invalidationListener.check(null, 0); + assertEquals(true, binding2.isValid()); + } + + @Parameterized.Parameters + public static Collection parameters() { + final ObservableStub dependency1 = new ObservableStub(); + final ObservableStub dependency2 = new ObservableStub(); + return Arrays.asList(new Object[][] { + { + Float.MIN_VALUE, Float.MAX_VALUE, + dependency1, dependency2, + new FloatBindingImpl(), + new FloatBindingImpl(dependency1), + new FloatBindingImpl(dependency1, dependency2), + }, + { + Double.MIN_VALUE, Double.MAX_VALUE, + dependency1, dependency2, + new DoubleBindingImpl(), + new DoubleBindingImpl(dependency1), + new DoubleBindingImpl(dependency1, dependency2), + }, + { + Long.MIN_VALUE, Long.MAX_VALUE, + dependency1, dependency2, + new LongBindingImpl(), + new LongBindingImpl(dependency1), + new LongBindingImpl(dependency1, dependency2), + }, + { + Integer.MIN_VALUE, Integer.MAX_VALUE, + dependency1, dependency2, + new IntegerBindingImpl(), + new IntegerBindingImpl(dependency1), + new IntegerBindingImpl(dependency1, dependency2), + }, + { + true, false, + dependency1, dependency2, + new BooleanBindingImpl(), + new BooleanBindingImpl(dependency1), + new BooleanBindingImpl(dependency1, dependency2), + }, + { + "Hello World", "Goodbye", + dependency1, dependency2, + new StringBindingImpl(), + new StringBindingImpl(dependency1), + new StringBindingImpl(dependency1, dependency2), + }, + { + new Object(), new Object(), + dependency1, dependency2, + new ObjectBindingImpl(), + new ObjectBindingImpl(dependency1), + new ObjectBindingImpl(dependency1, dependency2), + }, + { + FXCollections.observableArrayList(), FXCollections.observableArrayList(), + dependency1, dependency2, + new ListBindingImpl(), + new ListBindingImpl(dependency1), + new ListBindingImpl(dependency1, dependency2), + }, + }); + } + + public static class ObservableStub extends ObservableValueBase { + @Override public void fireValueChangedEvent() {super.fireValueChangedEvent();} + + @Override + public Object getValue() { + return null; + } + } + + public static interface BindingMock extends Binding { + int getComputeValueCounter(); + void reset(); + void setValue(T value); + } + + private static class DoubleBindingImpl extends DoubleBinding implements BindingMock { + + private int computeValueCounter = 0; + private double value; + + @Override + public void setValue(Number value) {this.value = value.doubleValue();} + + public DoubleBindingImpl(Observable... dep) { + super.bind(dep); + } + + @Override public int getComputeValueCounter() { + final int result = computeValueCounter; + reset(); + return result; + } + + @Override public void reset() {computeValueCounter = 0;} + + @Override + public double computeValue() { + computeValueCounter++; + return value; + } + + @Override @ReturnsUnmodifiableCollection + public ObservableList getDependencies() { + fail("Should not reach here"); + return null; + } + } + + private static class FloatBindingImpl extends FloatBinding implements BindingMock { + + private int computeValueCounter = 0; + private float value; + + @Override + public void setValue(Number value) {this.value = value.floatValue();} + + public FloatBindingImpl(Observable... dep) { + super.bind(dep); + } + + @Override public int getComputeValueCounter() { + final int result = computeValueCounter; + reset(); + return result; + } + + @Override public void reset() {computeValueCounter = 0;} + + @Override + public float computeValue() { + computeValueCounter++; + return value; + } + + @Override @ReturnsUnmodifiableCollection + public ObservableList getDependencies() { + fail("Should not reach here"); + return null; + } + } + + private static class LongBindingImpl extends LongBinding implements BindingMock { + + private int computeValueCounter = 0; + private long value; + + @Override + public void setValue(Number value) {this.value = value.longValue();} + + public LongBindingImpl(Observable... dep) { + super.bind(dep); + } + + @Override public int getComputeValueCounter() { + final int result = computeValueCounter; + reset(); + return result; + } + + @Override public void reset() {computeValueCounter = 0;} + + @Override + public long computeValue() { + computeValueCounter++; + return value; + } + + @Override @ReturnsUnmodifiableCollection + public ObservableList getDependencies() { + fail("Should not reach here"); + return null; + } + } + + private static class IntegerBindingImpl extends IntegerBinding implements BindingMock { + + private int computeValueCounter = 0; + private int value; + + @Override + public void setValue(Number value) {this.value = value.intValue();} + + public IntegerBindingImpl(Observable... dep) { + super.bind(dep); + } + + @Override public int getComputeValueCounter() { + final int result = computeValueCounter; + reset(); + return result; + } + + @Override public void reset() {computeValueCounter = 0;} + + @Override + public int computeValue() { + computeValueCounter++; + return value; + } + + @Override @ReturnsUnmodifiableCollection + public ObservableList getDependencies() { + fail("Should not reach here"); + return null; + } + } + + private static class BooleanBindingImpl extends BooleanBinding implements BindingMock { + + private int computeValueCounter = 0; + private boolean value; + + @Override + public void setValue(Boolean value) {this.value = value;} + + public BooleanBindingImpl(Observable... dep) { + super.bind(dep); + } + + @Override public int getComputeValueCounter() { + final int result = computeValueCounter; + reset(); + return result; + } + + @Override public void reset() {computeValueCounter = 0;} + + @Override + public boolean computeValue() { + computeValueCounter++; + return value; + } + + @Override @ReturnsUnmodifiableCollection + public ObservableList getDependencies() { + fail("Should not reach here"); + return null; + } + } + + private static class ObjectBindingImpl extends ObjectBinding implements BindingMock { + + private int computeValueCounter = 0; + private Object value; + + @Override + public void setValue(Object value) {this.value = value;} + + public ObjectBindingImpl(Observable... dep) { + super.bind(dep); + } + + @Override public int getComputeValueCounter() { + final int result = computeValueCounter; + reset(); + return result; + } + + @Override public void reset() {computeValueCounter = 0;} + + @Override + public Object computeValue() { + computeValueCounter++; + return value; + } + + @Override @ReturnsUnmodifiableCollection + public ObservableList getDependencies() { + fail("Should not reach here"); + return null; + } + } + + private static class StringBindingImpl extends StringBinding implements BindingMock { + + private int computeValueCounter = 0; + private String value; + + @Override + public void setValue(String value) {this.value = value;} + + public StringBindingImpl(Observable... dep) { + super.bind(dep); + } + + @Override public int getComputeValueCounter() { + final int result = computeValueCounter; + reset(); + return result; + } + + @Override public void reset() {computeValueCounter = 0;} + + @Override + public String computeValue() { + computeValueCounter++; + return value; + } + + @Override @ReturnsUnmodifiableCollection + public ObservableList getDependencies() { + fail("Should not reach here"); + return null; + } + } + + private static class ListBindingImpl extends ListBinding implements BindingMock> { + + private int computeValueCounter = 0; + private ObservableList value; + + @Override + public void setValue(ObservableList value) {this.value = value;} + + public ListBindingImpl(Observable... dep) { + super.bind(dep); + } + + @Override public int getComputeValueCounter() { + final int result = computeValueCounter; + reset(); + return result; + } + + @Override public void reset() {computeValueCounter = 0;} + + @Override + public ObservableList computeValue() { + computeValueCounter++; + return value; + } + + @Override @ReturnsUnmodifiableCollection + public ObservableList getDependencies() { + fail("Should not reach here"); + return null; + } + } + + +} --- old/modules/base/src/test/java/javafx/binding/ListBindingTest.java 2015-08-31 10:24:31.673216752 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,333 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import com.sun.javafx.collections.annotations.ReturnsUnmodifiableCollection; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.Observable; -import javafx.beans.binding.ListBinding; -import javafx.beans.property.ReadOnlyBooleanProperty; -import javafx.beans.property.ReadOnlyIntegerProperty; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableValueBase; -import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; -import org.junit.Before; -import org.junit.Test; - -import java.util.Collections; - -import static org.junit.Assert.*; -import static org.junit.Assert.assertEquals; - -/** - */ -public class ListBindingTest { - - private ObservableStub dependency1; - private ObservableStub dependency2; - - private ListBindingImpl binding0; - private ListBindingImpl binding1; - private ListBindingImpl binding2; - - private ObservableList emptyList; - private ObservableList list1; - private ObservableList list2; - - private ListChangeListenerMock listener; - - @Before - public void setUp() { - dependency1 = new ObservableStub(); - dependency2 = new ObservableStub(); - binding0 = new ListBindingImpl(); - binding1 = new ListBindingImpl(dependency1); - binding2 = new ListBindingImpl(dependency1, dependency2); - emptyList = FXCollections.observableArrayList(); - list1 = FXCollections.observableArrayList(new Object()); - list2 = FXCollections.observableArrayList(new Object(), new Object()); - listener = new ListChangeListenerMock(); - binding0.setValue(list2); - binding1.setValue(list2); - binding2.setValue(list2); - } - - @Test - public void testSizeProperty() { - assertEquals(binding0, binding0.sizeProperty().getBean()); - assertEquals(binding1, binding1.sizeProperty().getBean()); - assertEquals(binding2, binding2.sizeProperty().getBean()); - - final ReadOnlyIntegerProperty size = binding1.sizeProperty(); - assertEquals("size", size.getName()); - - assertEquals(2, size.get()); - binding1.setValue(emptyList); - dependency1.fireValueChangedEvent(); - assertEquals(0, size.get()); - binding1.setValue(null); - dependency1.fireValueChangedEvent(); - assertEquals(0, size.get()); - binding1.setValue(list1); - dependency1.fireValueChangedEvent(); - assertEquals(1, size.get()); - } - - @Test - public void testEmptyProperty() { - assertEquals(binding0, binding0.emptyProperty().getBean()); - assertEquals(binding1, binding1.emptyProperty().getBean()); - assertEquals(binding2, binding2.emptyProperty().getBean()); - - final ReadOnlyBooleanProperty empty = binding1.emptyProperty(); - assertEquals("empty", empty.getName()); - - assertFalse(empty.get()); - binding1.setValue(emptyList); - dependency1.fireValueChangedEvent(); - assertTrue(empty.get()); - binding1.setValue(null); - dependency1.fireValueChangedEvent(); - assertTrue(empty.get()); - binding1.setValue(list1); - dependency1.fireValueChangedEvent(); - assertFalse(empty.get()); - } - - @Test - public void testNoDependency_ListChangeListener() { - binding0.getValue(); - binding0.addListener(listener); - System.gc(); // making sure we did not not overdo weak references - assertEquals(true, binding0.isValid()); - - // calling getValue() - binding0.reset(); - binding0.getValue(); - assertEquals(0, binding0.getComputeValueCounter()); - listener.checkNotCalled(); - assertEquals(true, binding0.isValid()); - } - - @Test - public void testSingleDependency_ListChangeListener() { - binding1.getValue(); - binding1.addListener(listener); - System.gc(); // making sure we did not not overdo weak references - assertEquals(true, binding1.isValid()); - - // fire single change event - binding1.reset(); - listener.reset(); - binding1.setValue(list1); - dependency1.fireValueChangedEvent(); - assertEquals(1, binding1.getComputeValueCounter()); - listener.check(list2, list1, 1); - assertEquals(true, binding1.isValid()); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - listener.checkNotCalled(); - assertEquals(true, binding1.isValid()); - - // fire single change event with same value - binding1.setValue(list1); - dependency1.fireValueChangedEvent(); - assertEquals(1, binding1.getComputeValueCounter()); - listener.checkNotCalled(); - assertEquals(true, binding1.isValid()); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - listener.checkNotCalled(); - assertEquals(true, binding1.isValid()); - - // fire two change events - binding1.setValue(list2); - dependency1.fireValueChangedEvent(); - binding1.setValue(list1); - dependency1.fireValueChangedEvent(); - assertEquals(2, binding1.getComputeValueCounter()); - listener.check(list2, list1, 2); - assertEquals(true, binding1.isValid()); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - listener.checkNotCalled(); - assertEquals(true, binding1.isValid()); - - // fire two change events with same value - binding1.setValue(list2); - dependency1.fireValueChangedEvent(); - binding1.setValue(list2); - dependency1.fireValueChangedEvent(); - assertEquals(2, binding1.getComputeValueCounter()); - listener.check(list1, list2, 1); - assertEquals(true, binding1.isValid()); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - listener.checkNotCalled(); - assertEquals(true, binding1.isValid()); - } - - @Test - public void testChangeContent_InvalidationListener() { - final InvalidationListenerMock listenerMock = new InvalidationListenerMock(); - binding1.get(); - binding1.addListener(listenerMock); - assertTrue(binding1.isValid()); - - binding1.reset(); - listenerMock.reset(); - list2.add(new Object()); - assertEquals(0, binding1.getComputeValueCounter()); - listenerMock.check(binding1, 1); - assertTrue(binding1.isValid()); - } - - @Test - public void testChangeContent_ChangeListener() { - final ChangeListenerMock listenerMock = new ChangeListenerMock(null); - binding1.get(); - binding1.addListener(listenerMock); - assertTrue(binding1.isValid()); - - binding1.reset(); - listenerMock.reset(); - list2.add(new Object()); - assertEquals(0, binding1.getComputeValueCounter()); - listenerMock.check(binding1, list2, list2, 1); - assertTrue(binding1.isValid()); - } - - @Test - public void testChangeContent_ListChangeListener() { - binding1.get(); - binding1.addListener(listener); - assertTrue(binding1.isValid()); - - final int oldSize = list2.size(); - final Object newObject = new Object(); - binding1.reset(); - listener.reset(); - list2.add(newObject); - assertEquals(0, binding1.getComputeValueCounter()); - listener.check(oldSize, newObject, 1); - assertTrue(binding1.isValid()); - } - - public static class ObservableStub extends ObservableValueBase { - @Override public void fireValueChangedEvent() {super.fireValueChangedEvent();} - - @Override - public Object getValue() { - return null; - } - } - - private static class ListBindingImpl extends ListBinding { - - private int computeValueCounter = 0; - private ObservableList value; - - public void setValue(ObservableList value) { - this.value = value; - } - - public ListBindingImpl(Observable... dep) { - super.bind(dep); - } - - public int getComputeValueCounter() { - final int result = computeValueCounter; - reset(); - return result; - } - - public void reset() { - computeValueCounter = 0; - } - - @Override - public ObservableList computeValue() { - computeValueCounter++; - return value; - } - - @Override @ReturnsUnmodifiableCollection - public ObservableList getDependencies() { - fail("Should not reach here"); - return null; - } - } - - - private class ListChangeListenerMock implements ListChangeListener { - - private Change change; - private int counter; - - @Override - public void onChanged(Change change) { - this.change = change; - counter++; - } - - private void reset() { - change = null; - counter = 0; - } - - private void checkNotCalled() { - assertEquals(null, change); - assertEquals(0, counter); - reset(); - } - - private void check(ObservableList oldList, ObservableList newList, int counter) { - assertTrue(change.next()); - assertTrue(change.wasReplaced()); - assertEquals(oldList, change.getRemoved()); - assertEquals(newList, change.getList()); - assertFalse(change.next()); - assertEquals(counter, this.counter); - reset(); - } - - private void check(int pos, Object newObject, int counter) { - assertTrue(change.next()); - assertTrue(change.wasAdded()); - assertEquals(pos, change.getFrom()); - assertEquals(Collections.singletonList(newObject), change.getAddedSubList()); - assertFalse(change.next()); - assertEquals(counter, this.counter); - reset(); - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/ListBindingTest.java 2015-08-31 10:24:31.469216754 -0400 @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import com.sun.javafx.collections.annotations.ReturnsUnmodifiableCollection; +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.Observable; +import javafx.beans.binding.ListBinding; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableValueBase; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; + +import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + +/** + */ +public class ListBindingTest { + + private ObservableStub dependency1; + private ObservableStub dependency2; + + private ListBindingImpl binding0; + private ListBindingImpl binding1; + private ListBindingImpl binding2; + + private ObservableList emptyList; + private ObservableList list1; + private ObservableList list2; + + private ListChangeListenerMock listener; + + @Before + public void setUp() { + dependency1 = new ObservableStub(); + dependency2 = new ObservableStub(); + binding0 = new ListBindingImpl(); + binding1 = new ListBindingImpl(dependency1); + binding2 = new ListBindingImpl(dependency1, dependency2); + emptyList = FXCollections.observableArrayList(); + list1 = FXCollections.observableArrayList(new Object()); + list2 = FXCollections.observableArrayList(new Object(), new Object()); + listener = new ListChangeListenerMock(); + binding0.setValue(list2); + binding1.setValue(list2); + binding2.setValue(list2); + } + + @Test + public void testSizeProperty() { + assertEquals(binding0, binding0.sizeProperty().getBean()); + assertEquals(binding1, binding1.sizeProperty().getBean()); + assertEquals(binding2, binding2.sizeProperty().getBean()); + + final ReadOnlyIntegerProperty size = binding1.sizeProperty(); + assertEquals("size", size.getName()); + + assertEquals(2, size.get()); + binding1.setValue(emptyList); + dependency1.fireValueChangedEvent(); + assertEquals(0, size.get()); + binding1.setValue(null); + dependency1.fireValueChangedEvent(); + assertEquals(0, size.get()); + binding1.setValue(list1); + dependency1.fireValueChangedEvent(); + assertEquals(1, size.get()); + } + + @Test + public void testEmptyProperty() { + assertEquals(binding0, binding0.emptyProperty().getBean()); + assertEquals(binding1, binding1.emptyProperty().getBean()); + assertEquals(binding2, binding2.emptyProperty().getBean()); + + final ReadOnlyBooleanProperty empty = binding1.emptyProperty(); + assertEquals("empty", empty.getName()); + + assertFalse(empty.get()); + binding1.setValue(emptyList); + dependency1.fireValueChangedEvent(); + assertTrue(empty.get()); + binding1.setValue(null); + dependency1.fireValueChangedEvent(); + assertTrue(empty.get()); + binding1.setValue(list1); + dependency1.fireValueChangedEvent(); + assertFalse(empty.get()); + } + + @Test + public void testNoDependency_ListChangeListener() { + binding0.getValue(); + binding0.addListener(listener); + System.gc(); // making sure we did not not overdo weak references + assertEquals(true, binding0.isValid()); + + // calling getValue() + binding0.reset(); + binding0.getValue(); + assertEquals(0, binding0.getComputeValueCounter()); + listener.checkNotCalled(); + assertEquals(true, binding0.isValid()); + } + + @Test + public void testSingleDependency_ListChangeListener() { + binding1.getValue(); + binding1.addListener(listener); + System.gc(); // making sure we did not not overdo weak references + assertEquals(true, binding1.isValid()); + + // fire single change event + binding1.reset(); + listener.reset(); + binding1.setValue(list1); + dependency1.fireValueChangedEvent(); + assertEquals(1, binding1.getComputeValueCounter()); + listener.check(list2, list1, 1); + assertEquals(true, binding1.isValid()); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + listener.checkNotCalled(); + assertEquals(true, binding1.isValid()); + + // fire single change event with same value + binding1.setValue(list1); + dependency1.fireValueChangedEvent(); + assertEquals(1, binding1.getComputeValueCounter()); + listener.checkNotCalled(); + assertEquals(true, binding1.isValid()); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + listener.checkNotCalled(); + assertEquals(true, binding1.isValid()); + + // fire two change events + binding1.setValue(list2); + dependency1.fireValueChangedEvent(); + binding1.setValue(list1); + dependency1.fireValueChangedEvent(); + assertEquals(2, binding1.getComputeValueCounter()); + listener.check(list2, list1, 2); + assertEquals(true, binding1.isValid()); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + listener.checkNotCalled(); + assertEquals(true, binding1.isValid()); + + // fire two change events with same value + binding1.setValue(list2); + dependency1.fireValueChangedEvent(); + binding1.setValue(list2); + dependency1.fireValueChangedEvent(); + assertEquals(2, binding1.getComputeValueCounter()); + listener.check(list1, list2, 1); + assertEquals(true, binding1.isValid()); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + listener.checkNotCalled(); + assertEquals(true, binding1.isValid()); + } + + @Test + public void testChangeContent_InvalidationListener() { + final InvalidationListenerMock listenerMock = new InvalidationListenerMock(); + binding1.get(); + binding1.addListener(listenerMock); + assertTrue(binding1.isValid()); + + binding1.reset(); + listenerMock.reset(); + list2.add(new Object()); + assertEquals(0, binding1.getComputeValueCounter()); + listenerMock.check(binding1, 1); + assertTrue(binding1.isValid()); + } + + @Test + public void testChangeContent_ChangeListener() { + final ChangeListenerMock listenerMock = new ChangeListenerMock(null); + binding1.get(); + binding1.addListener(listenerMock); + assertTrue(binding1.isValid()); + + binding1.reset(); + listenerMock.reset(); + list2.add(new Object()); + assertEquals(0, binding1.getComputeValueCounter()); + listenerMock.check(binding1, list2, list2, 1); + assertTrue(binding1.isValid()); + } + + @Test + public void testChangeContent_ListChangeListener() { + binding1.get(); + binding1.addListener(listener); + assertTrue(binding1.isValid()); + + final int oldSize = list2.size(); + final Object newObject = new Object(); + binding1.reset(); + listener.reset(); + list2.add(newObject); + assertEquals(0, binding1.getComputeValueCounter()); + listener.check(oldSize, newObject, 1); + assertTrue(binding1.isValid()); + } + + public static class ObservableStub extends ObservableValueBase { + @Override public void fireValueChangedEvent() {super.fireValueChangedEvent();} + + @Override + public Object getValue() { + return null; + } + } + + private static class ListBindingImpl extends ListBinding { + + private int computeValueCounter = 0; + private ObservableList value; + + public void setValue(ObservableList value) { + this.value = value; + } + + public ListBindingImpl(Observable... dep) { + super.bind(dep); + } + + public int getComputeValueCounter() { + final int result = computeValueCounter; + reset(); + return result; + } + + public void reset() { + computeValueCounter = 0; + } + + @Override + public ObservableList computeValue() { + computeValueCounter++; + return value; + } + + @Override @ReturnsUnmodifiableCollection + public ObservableList getDependencies() { + fail("Should not reach here"); + return null; + } + } + + + private class ListChangeListenerMock implements ListChangeListener { + + private Change change; + private int counter; + + @Override + public void onChanged(Change change) { + this.change = change; + counter++; + } + + private void reset() { + change = null; + counter = 0; + } + + private void checkNotCalled() { + assertEquals(null, change); + assertEquals(0, counter); + reset(); + } + + private void check(ObservableList oldList, ObservableList newList, int counter) { + assertTrue(change.next()); + assertTrue(change.wasReplaced()); + assertEquals(oldList, change.getRemoved()); + assertEquals(newList, change.getList()); + assertFalse(change.next()); + assertEquals(counter, this.counter); + reset(); + } + + private void check(int pos, Object newObject, int counter) { + assertTrue(change.next()); + assertTrue(change.wasAdded()); + assertEquals(pos, change.getFrom()); + assertEquals(Collections.singletonList(newObject), change.getAddedSubList()); + assertFalse(change.next()); + assertEquals(counter, this.counter); + reset(); + } + } +} --- old/modules/base/src/test/java/javafx/binding/MapBindingTest.java 2015-08-31 10:24:32.429216743 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,354 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import com.sun.javafx.collections.annotations.ReturnsUnmodifiableCollection; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.Observable; -import javafx.beans.binding.MapBinding; -import javafx.beans.property.ReadOnlyBooleanProperty; -import javafx.beans.property.ReadOnlyIntegerProperty; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableValueBase; -import javafx.collections.FXCollections; -import javafx.collections.MockMapObserver; -import javafx.collections.ObservableList; -import javafx.collections.ObservableMap; -import org.junit.Before; -import org.junit.Test; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import static javafx.collections.MockMapObserver.Call; -import static org.junit.Assert.*; - -/** - */ -public class MapBindingTest { - - private final static Object KEY_1 = new Object(); - private final static Object KEY_2_0 = new Object(); - private final static Object KEY_2_1 = new Object(); - private final static Object DATA_1 = new Object(); - private final static Object DATA_2_0 = new Object(); - private final static Object DATA_2_1 = new Object(); - - private ObservableStub dependency1; - private ObservableStub dependency2; - - private MapBindingImpl binding0; - private MapBindingImpl binding1; - private MapBindingImpl binding2; - - private ObservableMap emptyMap; - private ObservableMap set1; - private ObservableMap set2; - - private MockMapObserver listener; - - @Before - public void setUp() { - dependency1 = new ObservableStub(); - dependency2 = new ObservableStub(); - binding0 = new MapBindingImpl(); - binding1 = new MapBindingImpl(dependency1); - binding2 = new MapBindingImpl(dependency1, dependency2); - emptyMap = FXCollections.observableMap(Collections.emptyMap()); - set1 = FXCollections.observableMap(Collections.singletonMap(KEY_1, DATA_1)); - final Map map = new HashMap(); - map.put(KEY_2_0, DATA_2_0); - map.put(KEY_2_1, DATA_2_1); - set2 = FXCollections.observableMap(map); - listener = new MockMapObserver(); - binding0.setValue(set2); - binding1.setValue(set2); - binding2.setValue(set2); - } - - @Test - public void testSizeProperty() { - assertEquals(binding0, binding0.sizeProperty().getBean()); - assertEquals(binding1, binding1.sizeProperty().getBean()); - assertEquals(binding2, binding2.sizeProperty().getBean()); - - final ReadOnlyIntegerProperty size = binding1.sizeProperty(); - assertEquals("size", size.getName()); - - assertEquals(2, size.get()); - binding1.setValue(emptyMap); - dependency1.fireValueChangedEvent(); - assertEquals(0, size.get()); - binding1.setValue(null); - dependency1.fireValueChangedEvent(); - assertEquals(0, size.get()); - binding1.setValue(set1); - dependency1.fireValueChangedEvent(); - assertEquals(1, size.get()); - } - - @Test - public void testEmptyProperty() { - assertEquals(binding0, binding0.emptyProperty().getBean()); - assertEquals(binding1, binding1.emptyProperty().getBean()); - assertEquals(binding2, binding2.emptyProperty().getBean()); - - final ReadOnlyBooleanProperty empty = binding1.emptyProperty(); - assertEquals("empty", empty.getName()); - - assertFalse(empty.get()); - binding1.setValue(emptyMap); - dependency1.fireValueChangedEvent(); - assertTrue(empty.get()); - binding1.setValue(null); - dependency1.fireValueChangedEvent(); - assertTrue(empty.get()); - binding1.setValue(set1); - dependency1.fireValueChangedEvent(); - assertFalse(empty.get()); - } - - @Test - public void testNoDependency_MapChangeListener() { - binding0.getValue(); - binding0.addListener(listener); - System.gc(); // making sure we did not not overdo weak references - assertEquals(true, binding0.isValid()); - - // calling getValue() - binding0.reset(); - binding0.getValue(); - assertEquals(0, binding0.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding0.isValid()); - } - - @Test - public void testSingleDependency_MapChangeListener() { - binding1.getValue(); - binding1.addListener(listener); - System.gc(); // making sure we did not not overdo weak references - assertEquals(true, binding1.isValid()); - - // fire single change event - binding1.reset(); - listener.clear(); - binding1.setValue(set1); - dependency1.fireValueChangedEvent(); - assertEquals(1, binding1.getComputeValueCounter()); - listener.assertMultipleCalls(new Call[]{new Call(KEY_2_0, DATA_2_0, null), new Call(KEY_2_1, DATA_2_1, null), new Call(KEY_1, null, DATA_1)}); - assertEquals(true, binding1.isValid()); - listener.clear(); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding1.isValid()); - listener.clear(); - - // fire single change event with same value - binding1.setValue(set1); - dependency1.fireValueChangedEvent(); - assertEquals(1, binding1.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding1.isValid()); - listener.clear(); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding1.isValid()); - listener.clear(); - - // fire two change events - binding1.setValue(set2); - dependency1.fireValueChangedEvent(); - listener.clear(); - binding1.setValue(set1); - dependency1.fireValueChangedEvent(); - assertEquals(2, binding1.getComputeValueCounter()); - listener.assertMultipleCalls(new Call[]{new Call(KEY_2_0, DATA_2_0, null), new Call(KEY_2_1, DATA_2_1, null), new Call(KEY_1, null, DATA_1)}); - assertEquals(true, binding1.isValid()); - listener.clear(); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding1.isValid()); - listener.clear(); - - // fire two change events with same value - binding1.setValue(set2); - dependency1.fireValueChangedEvent(); - binding1.setValue(set2); - dependency1.fireValueChangedEvent(); - assertEquals(2, binding1.getComputeValueCounter()); - listener.assertMultipleCalls(new Call[] {new Call(KEY_1, DATA_1, null), new Call(KEY_2_0, null, DATA_2_0), new Call(KEY_2_1, null, DATA_2_1)}); - assertEquals(true, binding1.isValid()); - listener.clear(); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding1.isValid()); - } - - @Test - public void testChangeContent_InvalidationListener() { - final InvalidationListenerMock listenerMock = new InvalidationListenerMock(); - binding1.get(); - binding1.addListener(listenerMock); - assertTrue(binding1.isValid()); - - binding1.reset(); - listenerMock.reset(); - set2.put(new Object(), new Object()); - assertEquals(0, binding1.getComputeValueCounter()); - listenerMock.check(binding1, 1); - assertTrue(binding1.isValid()); - } - - @Test - public void testChangeContent_ChangeListener() { - final ChangeListenerMock listenerMock = new ChangeListenerMock(null); - binding1.get(); - binding1.addListener(listenerMock); - assertTrue(binding1.isValid()); - - binding1.reset(); - listenerMock.reset(); - set2.put(new Object(), new Object()); - assertEquals(0, binding1.getComputeValueCounter()); - listenerMock.check(binding1, set2, set2, 1); - assertTrue(binding1.isValid()); - } - - @Test - public void testChangeContent_MapChangeListener() { - binding1.get(); - binding1.addListener(listener); - assertTrue(binding1.isValid()); - - final Object newKey = new Object(); - final Object newData = new Object(); - binding1.reset(); - listener.clear(); - set2.put(newKey, newData); - assertEquals(0, binding1.getComputeValueCounter()); - listener.assertAdded(MockMapObserver.Tuple.tup(newKey, newData)); - assertTrue(binding1.isValid()); - } - - public static class ObservableStub extends ObservableValueBase { - @Override public void fireValueChangedEvent() {super.fireValueChangedEvent();} - - @Override - public Object getValue() { - return null; - } - } - - private static class MapBindingImpl extends MapBinding { - - private int computeValueCounter = 0; - private ObservableMap value; - - public void setValue(ObservableMap value) { - this.value = value; - } - - public MapBindingImpl(Observable... dep) { - super.bind(dep); - } - - public int getComputeValueCounter() { - final int result = computeValueCounter; - reset(); - return result; - } - - public void reset() { - computeValueCounter = 0; - } - - @Override - public ObservableMap computeValue() { - computeValueCounter++; - return value; - } - - @Override @ReturnsUnmodifiableCollection - public ObservableList getDependencies() { - fail("Should not reach here"); - return null; - } - } - - -// private class MapChangeListenerMock implements MapChangeListener { -// -// private Change change; -// private int counter; -// -// @Override -// public void onChanged(Change change) { -// this.change = change; -// counter++; -// } -// -// private void reset() { -// change = null; -// counter = 0; -// } -// -// private void checkNotCalled() { -// assertEquals(null, change); -// assertEquals(0, counter); -// reset(); -// } -// -// private void check(ObservableMap oldMap, ObservableMap newMap, int counter) { -// assertTrue(change.next()); -// assertTrue(change.wasReplaced()); -// assertEquals(oldMap, change.getRemoved()); -// assertEquals(newMap, change.getMap()); -// assertFalse(change.next()); -// assertEquals(counter, this.counter); -// reset(); -// } -// -// private void check(int pos, Object newObject, int counter) { -// assertTrue(change.next()); -// assertTrue(change.wasAdded()); -// assertEquals(pos, change.getFrom()); -// assertEquals(Collections.singletonMap(newObject), change.getAddedSubMap()); -// assertFalse(change.next()); -// assertEquals(counter, this.counter); -// reset(); -// } -// } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/MapBindingTest.java 2015-08-31 10:24:32.293216745 -0400 @@ -0,0 +1,354 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import com.sun.javafx.collections.annotations.ReturnsUnmodifiableCollection; +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.Observable; +import javafx.beans.binding.MapBinding; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableValueBase; +import javafx.collections.FXCollections; +import test.javafx.collections.MockMapObserver; +import javafx.collections.ObservableList; +import javafx.collections.ObservableMap; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static test.javafx.collections.MockMapObserver.Call; +import static org.junit.Assert.*; + +/** + */ +public class MapBindingTest { + + private final static Object KEY_1 = new Object(); + private final static Object KEY_2_0 = new Object(); + private final static Object KEY_2_1 = new Object(); + private final static Object DATA_1 = new Object(); + private final static Object DATA_2_0 = new Object(); + private final static Object DATA_2_1 = new Object(); + + private ObservableStub dependency1; + private ObservableStub dependency2; + + private MapBindingImpl binding0; + private MapBindingImpl binding1; + private MapBindingImpl binding2; + + private ObservableMap emptyMap; + private ObservableMap set1; + private ObservableMap set2; + + private MockMapObserver listener; + + @Before + public void setUp() { + dependency1 = new ObservableStub(); + dependency2 = new ObservableStub(); + binding0 = new MapBindingImpl(); + binding1 = new MapBindingImpl(dependency1); + binding2 = new MapBindingImpl(dependency1, dependency2); + emptyMap = FXCollections.observableMap(Collections.emptyMap()); + set1 = FXCollections.observableMap(Collections.singletonMap(KEY_1, DATA_1)); + final Map map = new HashMap(); + map.put(KEY_2_0, DATA_2_0); + map.put(KEY_2_1, DATA_2_1); + set2 = FXCollections.observableMap(map); + listener = new MockMapObserver(); + binding0.setValue(set2); + binding1.setValue(set2); + binding2.setValue(set2); + } + + @Test + public void testSizeProperty() { + assertEquals(binding0, binding0.sizeProperty().getBean()); + assertEquals(binding1, binding1.sizeProperty().getBean()); + assertEquals(binding2, binding2.sizeProperty().getBean()); + + final ReadOnlyIntegerProperty size = binding1.sizeProperty(); + assertEquals("size", size.getName()); + + assertEquals(2, size.get()); + binding1.setValue(emptyMap); + dependency1.fireValueChangedEvent(); + assertEquals(0, size.get()); + binding1.setValue(null); + dependency1.fireValueChangedEvent(); + assertEquals(0, size.get()); + binding1.setValue(set1); + dependency1.fireValueChangedEvent(); + assertEquals(1, size.get()); + } + + @Test + public void testEmptyProperty() { + assertEquals(binding0, binding0.emptyProperty().getBean()); + assertEquals(binding1, binding1.emptyProperty().getBean()); + assertEquals(binding2, binding2.emptyProperty().getBean()); + + final ReadOnlyBooleanProperty empty = binding1.emptyProperty(); + assertEquals("empty", empty.getName()); + + assertFalse(empty.get()); + binding1.setValue(emptyMap); + dependency1.fireValueChangedEvent(); + assertTrue(empty.get()); + binding1.setValue(null); + dependency1.fireValueChangedEvent(); + assertTrue(empty.get()); + binding1.setValue(set1); + dependency1.fireValueChangedEvent(); + assertFalse(empty.get()); + } + + @Test + public void testNoDependency_MapChangeListener() { + binding0.getValue(); + binding0.addListener(listener); + System.gc(); // making sure we did not not overdo weak references + assertEquals(true, binding0.isValid()); + + // calling getValue() + binding0.reset(); + binding0.getValue(); + assertEquals(0, binding0.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding0.isValid()); + } + + @Test + public void testSingleDependency_MapChangeListener() { + binding1.getValue(); + binding1.addListener(listener); + System.gc(); // making sure we did not not overdo weak references + assertEquals(true, binding1.isValid()); + + // fire single change event + binding1.reset(); + listener.clear(); + binding1.setValue(set1); + dependency1.fireValueChangedEvent(); + assertEquals(1, binding1.getComputeValueCounter()); + listener.assertMultipleCalls(new Call[]{new Call(KEY_2_0, DATA_2_0, null), new Call(KEY_2_1, DATA_2_1, null), new Call(KEY_1, null, DATA_1)}); + assertEquals(true, binding1.isValid()); + listener.clear(); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding1.isValid()); + listener.clear(); + + // fire single change event with same value + binding1.setValue(set1); + dependency1.fireValueChangedEvent(); + assertEquals(1, binding1.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding1.isValid()); + listener.clear(); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding1.isValid()); + listener.clear(); + + // fire two change events + binding1.setValue(set2); + dependency1.fireValueChangedEvent(); + listener.clear(); + binding1.setValue(set1); + dependency1.fireValueChangedEvent(); + assertEquals(2, binding1.getComputeValueCounter()); + listener.assertMultipleCalls(new Call[]{new Call(KEY_2_0, DATA_2_0, null), new Call(KEY_2_1, DATA_2_1, null), new Call(KEY_1, null, DATA_1)}); + assertEquals(true, binding1.isValid()); + listener.clear(); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding1.isValid()); + listener.clear(); + + // fire two change events with same value + binding1.setValue(set2); + dependency1.fireValueChangedEvent(); + binding1.setValue(set2); + dependency1.fireValueChangedEvent(); + assertEquals(2, binding1.getComputeValueCounter()); + listener.assertMultipleCalls(new Call[] {new Call(KEY_1, DATA_1, null), new Call(KEY_2_0, null, DATA_2_0), new Call(KEY_2_1, null, DATA_2_1)}); + assertEquals(true, binding1.isValid()); + listener.clear(); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding1.isValid()); + } + + @Test + public void testChangeContent_InvalidationListener() { + final InvalidationListenerMock listenerMock = new InvalidationListenerMock(); + binding1.get(); + binding1.addListener(listenerMock); + assertTrue(binding1.isValid()); + + binding1.reset(); + listenerMock.reset(); + set2.put(new Object(), new Object()); + assertEquals(0, binding1.getComputeValueCounter()); + listenerMock.check(binding1, 1); + assertTrue(binding1.isValid()); + } + + @Test + public void testChangeContent_ChangeListener() { + final ChangeListenerMock listenerMock = new ChangeListenerMock(null); + binding1.get(); + binding1.addListener(listenerMock); + assertTrue(binding1.isValid()); + + binding1.reset(); + listenerMock.reset(); + set2.put(new Object(), new Object()); + assertEquals(0, binding1.getComputeValueCounter()); + listenerMock.check(binding1, set2, set2, 1); + assertTrue(binding1.isValid()); + } + + @Test + public void testChangeContent_MapChangeListener() { + binding1.get(); + binding1.addListener(listener); + assertTrue(binding1.isValid()); + + final Object newKey = new Object(); + final Object newData = new Object(); + binding1.reset(); + listener.clear(); + set2.put(newKey, newData); + assertEquals(0, binding1.getComputeValueCounter()); + listener.assertAdded(MockMapObserver.Tuple.tup(newKey, newData)); + assertTrue(binding1.isValid()); + } + + public static class ObservableStub extends ObservableValueBase { + @Override public void fireValueChangedEvent() {super.fireValueChangedEvent();} + + @Override + public Object getValue() { + return null; + } + } + + private static class MapBindingImpl extends MapBinding { + + private int computeValueCounter = 0; + private ObservableMap value; + + public void setValue(ObservableMap value) { + this.value = value; + } + + public MapBindingImpl(Observable... dep) { + super.bind(dep); + } + + public int getComputeValueCounter() { + final int result = computeValueCounter; + reset(); + return result; + } + + public void reset() { + computeValueCounter = 0; + } + + @Override + public ObservableMap computeValue() { + computeValueCounter++; + return value; + } + + @Override @ReturnsUnmodifiableCollection + public ObservableList getDependencies() { + fail("Should not reach here"); + return null; + } + } + + +// private class MapChangeListenerMock implements MapChangeListener { +// +// private Change change; +// private int counter; +// +// @Override +// public void onChanged(Change change) { +// this.change = change; +// counter++; +// } +// +// private void reset() { +// change = null; +// counter = 0; +// } +// +// private void checkNotCalled() { +// assertEquals(null, change); +// assertEquals(0, counter); +// reset(); +// } +// +// private void check(ObservableMap oldMap, ObservableMap newMap, int counter) { +// assertTrue(change.next()); +// assertTrue(change.wasReplaced()); +// assertEquals(oldMap, change.getRemoved()); +// assertEquals(newMap, change.getMap()); +// assertFalse(change.next()); +// assertEquals(counter, this.counter); +// reset(); +// } +// +// private void check(int pos, Object newObject, int counter) { +// assertTrue(change.next()); +// assertTrue(change.wasAdded()); +// assertEquals(pos, change.getFrom()); +// assertEquals(Collections.singletonMap(newObject), change.getAddedSubMap()); +// assertFalse(change.next()); +// assertEquals(counter, this.counter); +// reset(); +// } +// } +} --- old/modules/base/src/test/java/javafx/binding/SetBindingTest.java 2015-08-31 10:24:33.101216736 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,344 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import com.sun.javafx.collections.annotations.ReturnsUnmodifiableCollection; -import javafx.beans.InvalidationListenerMock; -import javafx.beans.Observable; -import javafx.beans.binding.SetBinding; -import javafx.beans.property.ReadOnlyBooleanProperty; -import javafx.beans.property.ReadOnlyIntegerProperty; -import javafx.beans.value.ChangeListenerMock; -import javafx.beans.value.ObservableValueBase; -import javafx.collections.FXCollections; -import javafx.collections.MockSetObserver; -import javafx.collections.ObservableList; -import javafx.collections.ObservableSet; -import org.junit.Before; -import org.junit.Test; - -import static javafx.collections.MockSetObserver.Call; -import static org.junit.Assert.*; - -/** - */ -public class SetBindingTest { - - private final static Object DATA_1 = new Object(); - private final static Object DATA_2_0 = new Object(); - private final static Object DATA_2_1 = new Object(); - - private ObservableStub dependency1; - private ObservableStub dependency2; - - private SetBindingImpl binding0; - private SetBindingImpl binding1; - private SetBindingImpl binding2; - - private ObservableSet emptySet; - private ObservableSet set1; - private ObservableSet set2; - - private MockSetObserver listener; - - @Before - public void setUp() { - dependency1 = new ObservableStub(); - dependency2 = new ObservableStub(); - binding0 = new SetBindingImpl(); - binding1 = new SetBindingImpl(dependency1); - binding2 = new SetBindingImpl(dependency1, dependency2); - emptySet = FXCollections.observableSet(); - set1 = FXCollections.observableSet(DATA_1); - set2 = FXCollections.observableSet(DATA_2_0, DATA_2_1); - listener = new MockSetObserver(); - binding0.setValue(set2); - binding1.setValue(set2); - binding2.setValue(set2); - } - - @Test - public void testSizeProperty() { - assertEquals(binding0, binding0.sizeProperty().getBean()); - assertEquals(binding1, binding1.sizeProperty().getBean()); - assertEquals(binding2, binding2.sizeProperty().getBean()); - - final ReadOnlyIntegerProperty size = binding1.sizeProperty(); - assertEquals("size", size.getName()); - - assertEquals(2, size.get()); - binding1.setValue(emptySet); - dependency1.fireValueChangedEvent(); - assertEquals(0, size.get()); - binding1.setValue(null); - dependency1.fireValueChangedEvent(); - assertEquals(0, size.get()); - binding1.setValue(set1); - dependency1.fireValueChangedEvent(); - assertEquals(1, size.get()); - } - - @Test - public void testEmptyProperty() { - assertEquals(binding0, binding0.emptyProperty().getBean()); - assertEquals(binding1, binding1.emptyProperty().getBean()); - assertEquals(binding2, binding2.emptyProperty().getBean()); - - final ReadOnlyBooleanProperty empty = binding1.emptyProperty(); - assertEquals("empty", empty.getName()); - - assertFalse(empty.get()); - binding1.setValue(emptySet); - dependency1.fireValueChangedEvent(); - assertTrue(empty.get()); - binding1.setValue(null); - dependency1.fireValueChangedEvent(); - assertTrue(empty.get()); - binding1.setValue(set1); - dependency1.fireValueChangedEvent(); - assertFalse(empty.get()); - } - - @Test - public void testNoDependency_SetChangeListener() { - binding0.getValue(); - binding0.addListener(listener); - System.gc(); // making sure we did not not overdo weak references - assertEquals(true, binding0.isValid()); - - // calling getValue() - binding0.reset(); - binding0.getValue(); - assertEquals(0, binding0.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding0.isValid()); - } - - @Test - public void testSingleDependency_SetChangeListener() { - binding1.getValue(); - binding1.addListener(listener); - System.gc(); // making sure we did not not overdo weak references - assertEquals(true, binding1.isValid()); - - // fire single change event - binding1.reset(); - listener.clear(); - binding1.setValue(set1); - dependency1.fireValueChangedEvent(); - assertEquals(1, binding1.getComputeValueCounter()); - listener.assertMultipleCalls(new Call[]{new Call(DATA_2_0, null), new Call(DATA_2_1, null), new Call(null, DATA_1)}); - assertEquals(true, binding1.isValid()); - listener.clear(); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding1.isValid()); - listener.clear(); - - // fire single change event with same value - binding1.setValue(set1); - dependency1.fireValueChangedEvent(); - assertEquals(1, binding1.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding1.isValid()); - listener.clear(); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding1.isValid()); - listener.clear(); - - // fire two change events - binding1.setValue(set2); - dependency1.fireValueChangedEvent(); - listener.clear(); - binding1.setValue(set1); - dependency1.fireValueChangedEvent(); - assertEquals(2, binding1.getComputeValueCounter()); - listener.assertMultipleCalls(new Call[]{new Call(DATA_2_0, null), new Call(DATA_2_1, null), new Call(null, DATA_1)}); - assertEquals(true, binding1.isValid()); - listener.clear(); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding1.isValid()); - listener.clear(); - - // fire two change events with same value - binding1.setValue(set2); - dependency1.fireValueChangedEvent(); - binding1.setValue(set2); - dependency1.fireValueChangedEvent(); - assertEquals(2, binding1.getComputeValueCounter()); - listener.assertMultipleCalls(new Call[] {new Call(DATA_1, null), new Call(null, DATA_2_0), new Call(null, DATA_2_1)}); - assertEquals(true, binding1.isValid()); - listener.clear(); - - binding1.getValue(); - assertEquals(0, binding1.getComputeValueCounter()); - assertEquals(0, listener.getCallsNumber()); - assertEquals(true, binding1.isValid()); - } - - @Test - public void testChangeContent_InvalidationListener() { - final InvalidationListenerMock listenerMock = new InvalidationListenerMock(); - binding1.get(); - binding1.addListener(listenerMock); - assertTrue(binding1.isValid()); - - binding1.reset(); - listenerMock.reset(); - set2.add(new Object()); - assertEquals(0, binding1.getComputeValueCounter()); - listenerMock.check(binding1, 1); - assertTrue(binding1.isValid()); - } - - @Test - public void testChangeContent_ChangeListener() { - final ChangeListenerMock listenerMock = new ChangeListenerMock(null); - binding1.get(); - binding1.addListener(listenerMock); - assertTrue(binding1.isValid()); - - binding1.reset(); - listenerMock.reset(); - set2.add(new Object()); - assertEquals(0, binding1.getComputeValueCounter()); - listenerMock.check(binding1, set2, set2, 1); - assertTrue(binding1.isValid()); - } - - @Test - public void testChangeContent_SetChangeListener() { - binding1.get(); - binding1.addListener(listener); - assertTrue(binding1.isValid()); - - final int oldSize = set2.size(); - final Object newObject = new Object(); - binding1.reset(); - listener.clear(); - set2.add(newObject); - assertEquals(0, binding1.getComputeValueCounter()); - listener.assertAdded(MockSetObserver.Tuple.tup(newObject)); - assertTrue(binding1.isValid()); - } - - public static class ObservableStub extends ObservableValueBase { - @Override public void fireValueChangedEvent() {super.fireValueChangedEvent();} - - @Override - public Object getValue() { - return null; - } - } - - private static class SetBindingImpl extends SetBinding { - - private int computeValueCounter = 0; - private ObservableSet value; - - public void setValue(ObservableSet value) { - this.value = value; - } - - public SetBindingImpl(Observable... dep) { - super.bind(dep); - } - - public int getComputeValueCounter() { - final int result = computeValueCounter; - reset(); - return result; - } - - public void reset() { - computeValueCounter = 0; - } - - @Override - public ObservableSet computeValue() { - computeValueCounter++; - return value; - } - - @Override @ReturnsUnmodifiableCollection - public ObservableList getDependencies() { - fail("Should not reach here"); - return null; - } - } - - -// private class SetChangeListenerMock implements SetChangeListener { -// -// private Change change; -// private int counter; -// -// @Override -// public void onChanged(Change change) { -// this.change = change; -// counter++; -// } -// -// private void reset() { -// change = null; -// counter = 0; -// } -// -// private void checkNotCalled() { -// assertEquals(null, change); -// assertEquals(0, counter); -// reset(); -// } -// -// private void check(ObservableSet oldSet, ObservableSet newSet, int counter) { -// assertTrue(change.next()); -// assertTrue(change.wasReplaced()); -// assertEquals(oldSet, change.getRemoved()); -// assertEquals(newSet, change.getSet()); -// assertFalse(change.next()); -// assertEquals(counter, this.counter); -// reset(); -// } -// -// private void check(int pos, Object newObject, int counter) { -// assertTrue(change.next()); -// assertTrue(change.wasAdded()); -// assertEquals(pos, change.getFrom()); -// assertEquals(Collections.singletonSet(newObject), change.getAddedSubSet()); -// assertFalse(change.next()); -// assertEquals(counter, this.counter); -// reset(); -// } -// } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/SetBindingTest.java 2015-08-31 10:24:32.913216738 -0400 @@ -0,0 +1,344 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import com.sun.javafx.collections.annotations.ReturnsUnmodifiableCollection; +import test.javafx.beans.InvalidationListenerMock; +import javafx.beans.Observable; +import javafx.beans.binding.SetBinding; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyIntegerProperty; +import test.javafx.beans.value.ChangeListenerMock; +import javafx.beans.value.ObservableValueBase; +import javafx.collections.FXCollections; +import test.javafx.collections.MockSetObserver; +import javafx.collections.ObservableList; +import javafx.collections.ObservableSet; +import org.junit.Before; +import org.junit.Test; + +import static test.javafx.collections.MockSetObserver.Call; +import static org.junit.Assert.*; + +/** + */ +public class SetBindingTest { + + private final static Object DATA_1 = new Object(); + private final static Object DATA_2_0 = new Object(); + private final static Object DATA_2_1 = new Object(); + + private ObservableStub dependency1; + private ObservableStub dependency2; + + private SetBindingImpl binding0; + private SetBindingImpl binding1; + private SetBindingImpl binding2; + + private ObservableSet emptySet; + private ObservableSet set1; + private ObservableSet set2; + + private MockSetObserver listener; + + @Before + public void setUp() { + dependency1 = new ObservableStub(); + dependency2 = new ObservableStub(); + binding0 = new SetBindingImpl(); + binding1 = new SetBindingImpl(dependency1); + binding2 = new SetBindingImpl(dependency1, dependency2); + emptySet = FXCollections.observableSet(); + set1 = FXCollections.observableSet(DATA_1); + set2 = FXCollections.observableSet(DATA_2_0, DATA_2_1); + listener = new MockSetObserver(); + binding0.setValue(set2); + binding1.setValue(set2); + binding2.setValue(set2); + } + + @Test + public void testSizeProperty() { + assertEquals(binding0, binding0.sizeProperty().getBean()); + assertEquals(binding1, binding1.sizeProperty().getBean()); + assertEquals(binding2, binding2.sizeProperty().getBean()); + + final ReadOnlyIntegerProperty size = binding1.sizeProperty(); + assertEquals("size", size.getName()); + + assertEquals(2, size.get()); + binding1.setValue(emptySet); + dependency1.fireValueChangedEvent(); + assertEquals(0, size.get()); + binding1.setValue(null); + dependency1.fireValueChangedEvent(); + assertEquals(0, size.get()); + binding1.setValue(set1); + dependency1.fireValueChangedEvent(); + assertEquals(1, size.get()); + } + + @Test + public void testEmptyProperty() { + assertEquals(binding0, binding0.emptyProperty().getBean()); + assertEquals(binding1, binding1.emptyProperty().getBean()); + assertEquals(binding2, binding2.emptyProperty().getBean()); + + final ReadOnlyBooleanProperty empty = binding1.emptyProperty(); + assertEquals("empty", empty.getName()); + + assertFalse(empty.get()); + binding1.setValue(emptySet); + dependency1.fireValueChangedEvent(); + assertTrue(empty.get()); + binding1.setValue(null); + dependency1.fireValueChangedEvent(); + assertTrue(empty.get()); + binding1.setValue(set1); + dependency1.fireValueChangedEvent(); + assertFalse(empty.get()); + } + + @Test + public void testNoDependency_SetChangeListener() { + binding0.getValue(); + binding0.addListener(listener); + System.gc(); // making sure we did not not overdo weak references + assertEquals(true, binding0.isValid()); + + // calling getValue() + binding0.reset(); + binding0.getValue(); + assertEquals(0, binding0.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding0.isValid()); + } + + @Test + public void testSingleDependency_SetChangeListener() { + binding1.getValue(); + binding1.addListener(listener); + System.gc(); // making sure we did not not overdo weak references + assertEquals(true, binding1.isValid()); + + // fire single change event + binding1.reset(); + listener.clear(); + binding1.setValue(set1); + dependency1.fireValueChangedEvent(); + assertEquals(1, binding1.getComputeValueCounter()); + listener.assertMultipleCalls(new Call[]{new Call(DATA_2_0, null), new Call(DATA_2_1, null), new Call(null, DATA_1)}); + assertEquals(true, binding1.isValid()); + listener.clear(); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding1.isValid()); + listener.clear(); + + // fire single change event with same value + binding1.setValue(set1); + dependency1.fireValueChangedEvent(); + assertEquals(1, binding1.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding1.isValid()); + listener.clear(); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding1.isValid()); + listener.clear(); + + // fire two change events + binding1.setValue(set2); + dependency1.fireValueChangedEvent(); + listener.clear(); + binding1.setValue(set1); + dependency1.fireValueChangedEvent(); + assertEquals(2, binding1.getComputeValueCounter()); + listener.assertMultipleCalls(new Call[]{new Call(DATA_2_0, null), new Call(DATA_2_1, null), new Call(null, DATA_1)}); + assertEquals(true, binding1.isValid()); + listener.clear(); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding1.isValid()); + listener.clear(); + + // fire two change events with same value + binding1.setValue(set2); + dependency1.fireValueChangedEvent(); + binding1.setValue(set2); + dependency1.fireValueChangedEvent(); + assertEquals(2, binding1.getComputeValueCounter()); + listener.assertMultipleCalls(new Call[] {new Call(DATA_1, null), new Call(null, DATA_2_0), new Call(null, DATA_2_1)}); + assertEquals(true, binding1.isValid()); + listener.clear(); + + binding1.getValue(); + assertEquals(0, binding1.getComputeValueCounter()); + assertEquals(0, listener.getCallsNumber()); + assertEquals(true, binding1.isValid()); + } + + @Test + public void testChangeContent_InvalidationListener() { + final InvalidationListenerMock listenerMock = new InvalidationListenerMock(); + binding1.get(); + binding1.addListener(listenerMock); + assertTrue(binding1.isValid()); + + binding1.reset(); + listenerMock.reset(); + set2.add(new Object()); + assertEquals(0, binding1.getComputeValueCounter()); + listenerMock.check(binding1, 1); + assertTrue(binding1.isValid()); + } + + @Test + public void testChangeContent_ChangeListener() { + final ChangeListenerMock listenerMock = new ChangeListenerMock(null); + binding1.get(); + binding1.addListener(listenerMock); + assertTrue(binding1.isValid()); + + binding1.reset(); + listenerMock.reset(); + set2.add(new Object()); + assertEquals(0, binding1.getComputeValueCounter()); + listenerMock.check(binding1, set2, set2, 1); + assertTrue(binding1.isValid()); + } + + @Test + public void testChangeContent_SetChangeListener() { + binding1.get(); + binding1.addListener(listener); + assertTrue(binding1.isValid()); + + final int oldSize = set2.size(); + final Object newObject = new Object(); + binding1.reset(); + listener.clear(); + set2.add(newObject); + assertEquals(0, binding1.getComputeValueCounter()); + listener.assertAdded(MockSetObserver.Tuple.tup(newObject)); + assertTrue(binding1.isValid()); + } + + public static class ObservableStub extends ObservableValueBase { + @Override public void fireValueChangedEvent() {super.fireValueChangedEvent();} + + @Override + public Object getValue() { + return null; + } + } + + private static class SetBindingImpl extends SetBinding { + + private int computeValueCounter = 0; + private ObservableSet value; + + public void setValue(ObservableSet value) { + this.value = value; + } + + public SetBindingImpl(Observable... dep) { + super.bind(dep); + } + + public int getComputeValueCounter() { + final int result = computeValueCounter; + reset(); + return result; + } + + public void reset() { + computeValueCounter = 0; + } + + @Override + public ObservableSet computeValue() { + computeValueCounter++; + return value; + } + + @Override @ReturnsUnmodifiableCollection + public ObservableList getDependencies() { + fail("Should not reach here"); + return null; + } + } + + +// private class SetChangeListenerMock implements SetChangeListener { +// +// private Change change; +// private int counter; +// +// @Override +// public void onChanged(Change change) { +// this.change = change; +// counter++; +// } +// +// private void reset() { +// change = null; +// counter = 0; +// } +// +// private void checkNotCalled() { +// assertEquals(null, change); +// assertEquals(0, counter); +// reset(); +// } +// +// private void check(ObservableSet oldSet, ObservableSet newSet, int counter) { +// assertTrue(change.next()); +// assertTrue(change.wasReplaced()); +// assertEquals(oldSet, change.getRemoved()); +// assertEquals(newSet, change.getSet()); +// assertFalse(change.next()); +// assertEquals(counter, this.counter); +// reset(); +// } +// +// private void check(int pos, Object newObject, int counter) { +// assertTrue(change.next()); +// assertTrue(change.wasAdded()); +// assertEquals(pos, change.getFrom()); +// assertEquals(Collections.singletonSet(newObject), change.getAddedSubSet()); +// assertFalse(change.next()); +// assertEquals(counter, this.counter); +// reset(); +// } +// } +} --- old/modules/base/src/test/java/javafx/binding/Variable.java 2015-08-31 10:24:33.877216727 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import javafx.beans.InvalidationListener; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; - -public class Variable { - public int numChangedListenersForNext = 0; - public int numChangedListenersForName = 0; - - public Variable(String name) { - this.name.set(name); - } - - private final ObjectProperty next = new SimpleObjectProperty() { - @Override - public void addListener(InvalidationListener listener) { - super.addListener(listener); - numChangedListenersForNext++; - } - @Override - public void removeListener(InvalidationListener listener) { - super.removeListener(listener); - numChangedListenersForNext = Math.max(0, numChangedListenersForNext-1); - } - }; - public Object getNext() {return next.get();} - public void setNext(Object value) {next.set(value);} - public ObjectProperty nextProperty() {return next;} - - - - private final StringProperty name = new SimpleStringProperty() { - @Override - public void addListener(InvalidationListener listener) { - super.addListener(listener); - numChangedListenersForName++; - } - @Override - public void removeListener(InvalidationListener listener) { - super.removeListener(listener); - numChangedListenersForName = Math.max(0, numChangedListenersForName-1); - } - }; - public final String getName() {return name.get();} - public void setName(String value) {name.set(value);} - public StringProperty nameProperty() {return name;} - - @Override public String toString() {return name.get();} -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/Variable.java 2015-08-31 10:24:33.673216729 -0400 @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import javafx.beans.InvalidationListener; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +public class Variable { + public int numChangedListenersForNext = 0; + public int numChangedListenersForName = 0; + + public Variable(String name) { + this.name.set(name); + } + + private final ObjectProperty next = new SimpleObjectProperty() { + @Override + public void addListener(InvalidationListener listener) { + super.addListener(listener); + numChangedListenersForNext++; + } + @Override + public void removeListener(InvalidationListener listener) { + super.removeListener(listener); + numChangedListenersForNext = Math.max(0, numChangedListenersForNext-1); + } + }; + public Object getNext() {return next.get();} + public void setNext(Object value) {next.set(value);} + public ObjectProperty nextProperty() {return next;} + + + + private final StringProperty name = new SimpleStringProperty() { + @Override + public void addListener(InvalidationListener listener) { + super.addListener(listener); + numChangedListenersForName++; + } + @Override + public void removeListener(InvalidationListener listener) { + super.removeListener(listener); + numChangedListenersForName = Math.max(0, numChangedListenersForName-1); + } + }; + public final String getName() {return name.get();} + public void setName(String value) {name.set(value);} + public StringProperty nameProperty() {return name;} + + @Override public String toString() {return name.get();} +} --- old/modules/base/src/test/java/javafx/binding/WhenTestBase.java 2015-08-31 10:24:34.613216719 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import static javafx.binding.DependencyUtils.checkDependencies; -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.value.ObservableValue; -import javafx.beans.value.WritableValue; - -import org.junit.Before; -import org.junit.Test; - -public abstract class WhenTestBase & ObservableValue> { - - static final float EPSILON_FLOAT = 1e-6f; - static final double EPSILON_DOUBLE = 1e-10; - - public abstract Binding[] generatePropertyPropertyList(P p0, P[] properties); - - public abstract Binding generatePropertyProperty(P p0, P p1); - - public abstract Binding[] generatePropertyPrimitive(P op0, T op1); - - public abstract Binding[] generatePrimitiveProperty(T op0, P op1); - - public abstract Binding[] generatePrimitivePrimitive(T op0, T op1); - - public abstract void check(T expected, Binding binding); - - final BooleanProperty cond = new SimpleBooleanProperty(); - final P p0; - final P[] properties; - private final T v0; - private final T v1; - private final T v2; - private final T v3; - - public WhenTestBase(T v0, T v1, T v2, T v3, P p0, P... properties) { - this.v0 = v0; - this.v1 = v1; - this.v2 = v2; - this.v3 = v3; - this.p0 = p0; - this.properties = properties; - } - - @Before - public void setUp() { - cond.set(false); - p0.setValue(v0); - for (final P p : properties) { - p.setValue(v1); - } - } - - @Test - public void test_expression_expression() { - final Binding[] bindings = generatePropertyPropertyList(p0, properties); - final int n = bindings.length; - for (int i=0; i binding = bindings[i]; - final P p1 = properties[i]; - // check initial state - checkDependencies(binding.getDependencies(), cond, p0, p1); - check(p1.getValue(), binding); - - // set first value - p0.setValue(v2); - check(p1.getValue(), binding); - - // set second value - p1.setValue(v3); - check(p1.getValue(), binding); - - // change condition - cond.set(true); - check(v2, binding); - - // set first value - p0.setValue(v0); - check(v0, binding); - - // set second value - p1.setValue(v1); - check(v0, binding); - - // change condition - cond.set(false); - check(p1.getValue(), binding); - } - } - - @Test - public void test_expression_primitive() { - final Binding[] bindings = generatePropertyPrimitive(p0, v1); - for (final Binding binding : bindings) { - // check initial state - checkDependencies(binding.getDependencies(), cond, p0); - check(v1, binding); - - // set first value - p0.setValue(v2); - check(v1, binding); - - // change condition - cond.set(true); - check(v2, binding); - - // set first value - p0.setValue(v0); - check(v0, binding); - - // change condition - cond.set(false); - check(v1, binding); - } - } - - @Test - public void test_primitive_expression() { - final Binding[] bindings = generatePrimitiveProperty(v1, p0); - for (final Binding binding : bindings) { - // check initial state - checkDependencies(binding.getDependencies(), cond, p0); - check(v0, binding); - - // set second value - p0.setValue(v3); - check(v3, binding); - - // change condition - cond.set(true); - check(v1, binding); - - // set second value - p0.setValue(v0); - check(v1, binding); - - // change condition - cond.set(false); - check(v0, binding); - } - } - - @Test - public void test_primitive_primitive() { - final Binding[] bindings = generatePrimitivePrimitive(v0, v1); - for (final Binding binding : bindings) { - // check initial state - checkDependencies(binding.getDependencies(), cond); - check(v1, binding); - - // change condition - cond.set(true); - check(v0, binding); - - // change condition - cond.set(false); - check(v1, binding); - } - } - - @Test(expected=NullPointerException.class) - public void test_Null() { - Bindings.when(null); - } - - @Test(expected=NullPointerException.class) - public void test_Null_expression() { - generatePropertyProperty(null, p0); - } - - @Test(expected=NullPointerException.class) - public void test_expression_Null() { - generatePropertyProperty(p0, null); - } - - @Test(expected=NullPointerException.class) - public void test_Null_primitive() { - generatePropertyPrimitive(null, v1); - } - - @Test(expected=NullPointerException.class) - public void test_primitive_Null() { - generatePrimitiveProperty(v0, null); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/WhenTestBase.java 2015-08-31 10:24:34.417216721 -0400 @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import static test.javafx.binding.DependencyUtils.checkDependencies; +import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.WritableValue; + +import org.junit.Before; +import org.junit.Test; + +public abstract class WhenTestBase & ObservableValue> { + + static final float EPSILON_FLOAT = 1e-6f; + static final double EPSILON_DOUBLE = 1e-10; + + public abstract Binding[] generatePropertyPropertyList(P p0, P[] properties); + + public abstract Binding generatePropertyProperty(P p0, P p1); + + public abstract Binding[] generatePropertyPrimitive(P op0, T op1); + + public abstract Binding[] generatePrimitiveProperty(T op0, P op1); + + public abstract Binding[] generatePrimitivePrimitive(T op0, T op1); + + public abstract void check(T expected, Binding binding); + + final BooleanProperty cond = new SimpleBooleanProperty(); + final P p0; + final P[] properties; + private final T v0; + private final T v1; + private final T v2; + private final T v3; + + public WhenTestBase(T v0, T v1, T v2, T v3, P p0, P... properties) { + this.v0 = v0; + this.v1 = v1; + this.v2 = v2; + this.v3 = v3; + this.p0 = p0; + this.properties = properties; + } + + @Before + public void setUp() { + cond.set(false); + p0.setValue(v0); + for (final P p : properties) { + p.setValue(v1); + } + } + + @Test + public void test_expression_expression() { + final Binding[] bindings = generatePropertyPropertyList(p0, properties); + final int n = bindings.length; + for (int i=0; i binding = bindings[i]; + final P p1 = properties[i]; + // check initial state + checkDependencies(binding.getDependencies(), cond, p0, p1); + check(p1.getValue(), binding); + + // set first value + p0.setValue(v2); + check(p1.getValue(), binding); + + // set second value + p1.setValue(v3); + check(p1.getValue(), binding); + + // change condition + cond.set(true); + check(v2, binding); + + // set first value + p0.setValue(v0); + check(v0, binding); + + // set second value + p1.setValue(v1); + check(v0, binding); + + // change condition + cond.set(false); + check(p1.getValue(), binding); + } + } + + @Test + public void test_expression_primitive() { + final Binding[] bindings = generatePropertyPrimitive(p0, v1); + for (final Binding binding : bindings) { + // check initial state + checkDependencies(binding.getDependencies(), cond, p0); + check(v1, binding); + + // set first value + p0.setValue(v2); + check(v1, binding); + + // change condition + cond.set(true); + check(v2, binding); + + // set first value + p0.setValue(v0); + check(v0, binding); + + // change condition + cond.set(false); + check(v1, binding); + } + } + + @Test + public void test_primitive_expression() { + final Binding[] bindings = generatePrimitiveProperty(v1, p0); + for (final Binding binding : bindings) { + // check initial state + checkDependencies(binding.getDependencies(), cond, p0); + check(v0, binding); + + // set second value + p0.setValue(v3); + check(v3, binding); + + // change condition + cond.set(true); + check(v1, binding); + + // set second value + p0.setValue(v0); + check(v1, binding); + + // change condition + cond.set(false); + check(v0, binding); + } + } + + @Test + public void test_primitive_primitive() { + final Binding[] bindings = generatePrimitivePrimitive(v0, v1); + for (final Binding binding : bindings) { + // check initial state + checkDependencies(binding.getDependencies(), cond); + check(v1, binding); + + // change condition + cond.set(true); + check(v0, binding); + + // change condition + cond.set(false); + check(v1, binding); + } + } + + @Test(expected=NullPointerException.class) + public void test_Null() { + Bindings.when(null); + } + + @Test(expected=NullPointerException.class) + public void test_Null_expression() { + generatePropertyProperty(null, p0); + } + + @Test(expected=NullPointerException.class) + public void test_expression_Null() { + generatePropertyProperty(p0, null); + } + + @Test(expected=NullPointerException.class) + public void test_Null_primitive() { + generatePropertyPrimitive(null, v1); + } + + @Test(expected=NullPointerException.class) + public void test_primitive_Null() { + generatePrimitiveProperty(v0, null); + } +} --- old/modules/base/src/test/java/javafx/binding/When_Boolean_Test.java 2015-08-31 10:24:35.225216712 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.SimpleBooleanProperty; - -public class When_Boolean_Test extends WhenTestBase { - public When_Boolean_Test() { - super( - false, true, true, false, - new SimpleBooleanProperty(), new SimpleBooleanProperty() - ); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPropertyList(BooleanProperty p0, BooleanProperty[] probs) { - return new Binding[] { - Bindings.when(cond).then(p0).otherwise(probs[0]) - }; - } - - @Override - public Binding generatePropertyProperty(BooleanProperty op0, BooleanProperty op1) { - return Bindings.when(cond).then(op0).otherwise(op1); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPrimitive(BooleanProperty op0, Boolean op1) { - return new Binding[] { - Bindings.when(cond).then(op0).otherwise(op1) - }; - } - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitiveProperty(Boolean op0, BooleanProperty op1) { - return new Binding[] { - Bindings.when(cond).then(op0.booleanValue()).otherwise(op1) - }; - } - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitivePrimitive(Boolean op0, Boolean op1) { - return new Binding[] { - Bindings.when(cond).then(op0.booleanValue()).otherwise(op1) - }; - } - @Override - public void check(Boolean expected, Binding binding) { - org.junit.Assert.assertEquals(expected, binding.getValue()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/When_Boolean_Test.java 2015-08-31 10:24:35.093216713 -0400 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; + +public class When_Boolean_Test extends WhenTestBase { + public When_Boolean_Test() { + super( + false, true, true, false, + new SimpleBooleanProperty(), new SimpleBooleanProperty() + ); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPropertyList(BooleanProperty p0, BooleanProperty[] probs) { + return new Binding[] { + Bindings.when(cond).then(p0).otherwise(probs[0]) + }; + } + + @Override + public Binding generatePropertyProperty(BooleanProperty op0, BooleanProperty op1) { + return Bindings.when(cond).then(op0).otherwise(op1); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPrimitive(BooleanProperty op0, Boolean op1) { + return new Binding[] { + Bindings.when(cond).then(op0).otherwise(op1) + }; + } + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitiveProperty(Boolean op0, BooleanProperty op1) { + return new Binding[] { + Bindings.when(cond).then(op0.booleanValue()).otherwise(op1) + }; + } + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitivePrimitive(Boolean op0, Boolean op1) { + return new Binding[] { + Bindings.when(cond).then(op0.booleanValue()).otherwise(op1) + }; + } + @Override + public void check(Boolean expected, Binding binding) { + org.junit.Assert.assertEquals(expected, binding.getValue()); + } +} --- old/modules/base/src/test/java/javafx/binding/When_Double_Test.java 2015-08-31 10:24:35.901216704 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import static org.junit.Assert.assertEquals; -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.property.Property; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleLongProperty; -import javafx.beans.value.ObservableNumberValue; - -public class When_Double_Test extends WhenTestBase> { - @SuppressWarnings("unchecked") - public When_Double_Test() { - super( - -EPSILON_DOUBLE, 0.0, Math.E, Double.MAX_VALUE, - new SimpleDoubleProperty(), new SimpleDoubleProperty(), new SimpleFloatProperty(), new SimpleLongProperty(), new SimpleIntegerProperty() - ); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPropertyList(Property p0, Property[] props) { - final int n = props.length; - final Binding[] result = new Binding[n]; - for (int i=0; i generatePropertyProperty(Property op0, Property op1) { - return Bindings.when(cond).then((ObservableNumberValue)op0).otherwise((ObservableNumberValue)op1); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPrimitive(Property op0, Number op1) { - final ObservableNumberValue p0 = (ObservableNumberValue)op0; - return new Binding[] { - Bindings.when(cond).then(p0).otherwise(op1.doubleValue()), - Bindings.when(cond).then(p0).otherwise(op1.floatValue()), - Bindings.when(cond).then(p0).otherwise(op1.longValue()), - Bindings.when(cond).then(p0).otherwise(op1.intValue()) - }; - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitiveProperty(Number op0, Property op1) { - final ObservableNumberValue p1 = (ObservableNumberValue)op1; - return new Binding[] { - Bindings.when(cond).then(op0.doubleValue()).otherwise(p1), - Bindings.when(cond).then(op0.floatValue()).otherwise(p1), - Bindings.when(cond).then(op0.longValue()).otherwise(p1), - Bindings.when(cond).then(op0.intValue()).otherwise(p1) - }; - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitivePrimitive(Number op0, Number op1) { - return new Binding[] { - Bindings.when(cond).then(op0.doubleValue()).otherwise(op1.doubleValue()), - Bindings.when(cond).then(op0.doubleValue()).otherwise(op1.floatValue()), - Bindings.when(cond).then(op0.doubleValue()).otherwise(op1.longValue()), - Bindings.when(cond).then(op0.doubleValue()).otherwise(op1.intValue()) - }; - } - - @Override - public void check(Number expected, Binding binding) { - assertEquals(expected.doubleValue(), binding.getValue().doubleValue(), EPSILON_DOUBLE); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/When_Double_Test.java 2015-08-31 10:24:35.689216707 -0400 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import static org.junit.Assert.assertEquals; +import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.property.Property; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.value.ObservableNumberValue; + +public class When_Double_Test extends WhenTestBase> { + @SuppressWarnings("unchecked") + public When_Double_Test() { + super( + -EPSILON_DOUBLE, 0.0, Math.E, Double.MAX_VALUE, + new SimpleDoubleProperty(), new SimpleDoubleProperty(), new SimpleFloatProperty(), new SimpleLongProperty(), new SimpleIntegerProperty() + ); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPropertyList(Property p0, Property[] props) { + final int n = props.length; + final Binding[] result = new Binding[n]; + for (int i=0; i generatePropertyProperty(Property op0, Property op1) { + return Bindings.when(cond).then((ObservableNumberValue)op0).otherwise((ObservableNumberValue)op1); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPrimitive(Property op0, Number op1) { + final ObservableNumberValue p0 = (ObservableNumberValue)op0; + return new Binding[] { + Bindings.when(cond).then(p0).otherwise(op1.doubleValue()), + Bindings.when(cond).then(p0).otherwise(op1.floatValue()), + Bindings.when(cond).then(p0).otherwise(op1.longValue()), + Bindings.when(cond).then(p0).otherwise(op1.intValue()) + }; + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitiveProperty(Number op0, Property op1) { + final ObservableNumberValue p1 = (ObservableNumberValue)op1; + return new Binding[] { + Bindings.when(cond).then(op0.doubleValue()).otherwise(p1), + Bindings.when(cond).then(op0.floatValue()).otherwise(p1), + Bindings.when(cond).then(op0.longValue()).otherwise(p1), + Bindings.when(cond).then(op0.intValue()).otherwise(p1) + }; + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitivePrimitive(Number op0, Number op1) { + return new Binding[] { + Bindings.when(cond).then(op0.doubleValue()).otherwise(op1.doubleValue()), + Bindings.when(cond).then(op0.doubleValue()).otherwise(op1.floatValue()), + Bindings.when(cond).then(op0.doubleValue()).otherwise(op1.longValue()), + Bindings.when(cond).then(op0.doubleValue()).otherwise(op1.intValue()) + }; + } + + @Override + public void check(Number expected, Binding binding) { + assertEquals(expected.doubleValue(), binding.getValue().doubleValue(), EPSILON_DOUBLE); + } +} --- old/modules/base/src/test/java/javafx/binding/When_Float_Test.java 2015-08-31 10:24:36.657216696 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import static org.junit.Assert.assertEquals; -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.property.Property; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleLongProperty; -import javafx.beans.value.ObservableNumberValue; - -public class When_Float_Test extends WhenTestBase> { - @SuppressWarnings("unchecked") - public When_Float_Test() { - super( - -(float) Math.PI, 0.0f, EPSILON_FLOAT, Float.MAX_VALUE, - new SimpleFloatProperty(), new SimpleDoubleProperty(), new SimpleFloatProperty(), new SimpleLongProperty(), new SimpleIntegerProperty() - ); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPropertyList(Property p0, Property[] props) { - final int n = props.length; - final Binding[] result = new Binding[n]; - for (int i=0; i generatePropertyProperty(Property op0, Property op1) { - return Bindings.when(cond).then((ObservableNumberValue)op0).otherwise((ObservableNumberValue)op1); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPrimitive(Property op0, Number op1) { - final ObservableNumberValue p0 = (ObservableNumberValue)op0; - return new Binding[] { - Bindings.when(cond).then(p0).otherwise(op1.doubleValue()), - Bindings.when(cond).then(p0).otherwise(op1.floatValue()), - Bindings.when(cond).then(p0).otherwise(op1.longValue()), - Bindings.when(cond).then(p0).otherwise(op1.intValue()) - }; - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitiveProperty(Number op0, Property op1) { - final ObservableNumberValue p1 = (ObservableNumberValue)op1; - return new Binding[] { - Bindings.when(cond).then(op0.doubleValue()).otherwise(p1), - Bindings.when(cond).then(op0.floatValue()).otherwise(p1), - Bindings.when(cond).then(op0.longValue()).otherwise(p1), - Bindings.when(cond).then(op0.intValue()).otherwise(p1) - }; - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitivePrimitive(Number op0, Number op1) { - return new Binding[] { - Bindings.when(cond).then(op0.floatValue()).otherwise(op1.doubleValue()), - Bindings.when(cond).then(op0.floatValue()).otherwise(op1.floatValue()), - Bindings.when(cond).then(op0.floatValue()).otherwise(op1.longValue()), - Bindings.when(cond).then(op0.floatValue()).otherwise(op1.intValue()) - }; - } - - @Override - public void check(Number expected, Binding binding) { - assertEquals(expected.floatValue(), binding.getValue().floatValue(), EPSILON_FLOAT); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/When_Float_Test.java 2015-08-31 10:24:36.473216698 -0400 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import static org.junit.Assert.assertEquals; +import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.property.Property; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.value.ObservableNumberValue; + +public class When_Float_Test extends WhenTestBase> { + @SuppressWarnings("unchecked") + public When_Float_Test() { + super( + -(float) Math.PI, 0.0f, EPSILON_FLOAT, Float.MAX_VALUE, + new SimpleFloatProperty(), new SimpleDoubleProperty(), new SimpleFloatProperty(), new SimpleLongProperty(), new SimpleIntegerProperty() + ); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPropertyList(Property p0, Property[] props) { + final int n = props.length; + final Binding[] result = new Binding[n]; + for (int i=0; i generatePropertyProperty(Property op0, Property op1) { + return Bindings.when(cond).then((ObservableNumberValue)op0).otherwise((ObservableNumberValue)op1); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPrimitive(Property op0, Number op1) { + final ObservableNumberValue p0 = (ObservableNumberValue)op0; + return new Binding[] { + Bindings.when(cond).then(p0).otherwise(op1.doubleValue()), + Bindings.when(cond).then(p0).otherwise(op1.floatValue()), + Bindings.when(cond).then(p0).otherwise(op1.longValue()), + Bindings.when(cond).then(p0).otherwise(op1.intValue()) + }; + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitiveProperty(Number op0, Property op1) { + final ObservableNumberValue p1 = (ObservableNumberValue)op1; + return new Binding[] { + Bindings.when(cond).then(op0.doubleValue()).otherwise(p1), + Bindings.when(cond).then(op0.floatValue()).otherwise(p1), + Bindings.when(cond).then(op0.longValue()).otherwise(p1), + Bindings.when(cond).then(op0.intValue()).otherwise(p1) + }; + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitivePrimitive(Number op0, Number op1) { + return new Binding[] { + Bindings.when(cond).then(op0.floatValue()).otherwise(op1.doubleValue()), + Bindings.when(cond).then(op0.floatValue()).otherwise(op1.floatValue()), + Bindings.when(cond).then(op0.floatValue()).otherwise(op1.longValue()), + Bindings.when(cond).then(op0.floatValue()).otherwise(op1.intValue()) + }; + } + + @Override + public void check(Number expected, Binding binding) { + assertEquals(expected.floatValue(), binding.getValue().floatValue(), EPSILON_FLOAT); + } +} --- old/modules/base/src/test/java/javafx/binding/When_Integer_Test.java 2015-08-31 10:24:37.277216689 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import static org.junit.Assert.assertEquals; -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.property.Property; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleLongProperty; -import javafx.beans.value.ObservableNumberValue; - -public class When_Integer_Test extends WhenTestBase> { - @SuppressWarnings("unchecked") - public When_Integer_Test() { - super( - Integer.MIN_VALUE, 0, Integer.MAX_VALUE, 1, - new SimpleIntegerProperty(), new SimpleDoubleProperty(), new SimpleFloatProperty(), new SimpleLongProperty(), new SimpleIntegerProperty() - ); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPropertyList(Property p0, Property[] props) { - final int n = props.length; - final Binding[] result = new Binding[n]; - for (int i=0; i generatePropertyProperty(Property op0, Property op1) { - return Bindings.when(cond).then((ObservableNumberValue)op0).otherwise((ObservableNumberValue)op1); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPrimitive(Property op0, Number op1) { - final ObservableNumberValue p0 = (ObservableNumberValue)op0; - return new Binding[] { - Bindings.when(cond).then(p0).otherwise(op1.doubleValue()), - Bindings.when(cond).then(p0).otherwise(op1.floatValue()), - Bindings.when(cond).then(p0).otherwise(op1.longValue()), - Bindings.when(cond).then(p0).otherwise(op1.intValue()) - }; - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitiveProperty(Number op0, Property op1) { - final ObservableNumberValue p1 = (ObservableNumberValue)op1; - return new Binding[] { - Bindings.when(cond).then(op0.doubleValue()).otherwise(p1), - Bindings.when(cond).then(op0.floatValue()).otherwise(p1), - Bindings.when(cond).then(op0.longValue()).otherwise(p1), - Bindings.when(cond).then(op0.intValue()).otherwise(p1) - }; - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitivePrimitive(Number op0, Number op1) { - return new Binding[] { - Bindings.when(cond).then(op0.intValue()).otherwise(op1.doubleValue()), - Bindings.when(cond).then(op0.intValue()).otherwise(op1.floatValue()), - Bindings.when(cond).then(op0.intValue()).otherwise(op1.longValue()), - Bindings.when(cond).then(op0.intValue()).otherwise(op1.intValue()) - }; - } - - @Override - public void check(Number expected, Binding binding) { - assertEquals(expected.intValue(), binding.getValue().intValue()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/When_Integer_Test.java 2015-08-31 10:24:37.141216690 -0400 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import static org.junit.Assert.assertEquals; +import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.property.Property; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.value.ObservableNumberValue; + +public class When_Integer_Test extends WhenTestBase> { + @SuppressWarnings("unchecked") + public When_Integer_Test() { + super( + Integer.MIN_VALUE, 0, Integer.MAX_VALUE, 1, + new SimpleIntegerProperty(), new SimpleDoubleProperty(), new SimpleFloatProperty(), new SimpleLongProperty(), new SimpleIntegerProperty() + ); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPropertyList(Property p0, Property[] props) { + final int n = props.length; + final Binding[] result = new Binding[n]; + for (int i=0; i generatePropertyProperty(Property op0, Property op1) { + return Bindings.when(cond).then((ObservableNumberValue)op0).otherwise((ObservableNumberValue)op1); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPrimitive(Property op0, Number op1) { + final ObservableNumberValue p0 = (ObservableNumberValue)op0; + return new Binding[] { + Bindings.when(cond).then(p0).otherwise(op1.doubleValue()), + Bindings.when(cond).then(p0).otherwise(op1.floatValue()), + Bindings.when(cond).then(p0).otherwise(op1.longValue()), + Bindings.when(cond).then(p0).otherwise(op1.intValue()) + }; + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitiveProperty(Number op0, Property op1) { + final ObservableNumberValue p1 = (ObservableNumberValue)op1; + return new Binding[] { + Bindings.when(cond).then(op0.doubleValue()).otherwise(p1), + Bindings.when(cond).then(op0.floatValue()).otherwise(p1), + Bindings.when(cond).then(op0.longValue()).otherwise(p1), + Bindings.when(cond).then(op0.intValue()).otherwise(p1) + }; + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitivePrimitive(Number op0, Number op1) { + return new Binding[] { + Bindings.when(cond).then(op0.intValue()).otherwise(op1.doubleValue()), + Bindings.when(cond).then(op0.intValue()).otherwise(op1.floatValue()), + Bindings.when(cond).then(op0.intValue()).otherwise(op1.longValue()), + Bindings.when(cond).then(op0.intValue()).otherwise(op1.intValue()) + }; + } + + @Override + public void check(Number expected, Binding binding) { + assertEquals(expected.intValue(), binding.getValue().intValue()); + } +} --- old/modules/base/src/test/java/javafx/binding/When_Long_Test.java 2015-08-31 10:24:38.005216681 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import static org.junit.Assert.assertEquals; -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.property.Property; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleLongProperty; -import javafx.beans.value.ObservableNumberValue; - -public class When_Long_Test extends WhenTestBase> { - @SuppressWarnings("unchecked") - public When_Long_Test() { - super( - -1L, 0L, Long.MIN_VALUE, Long.MAX_VALUE, - new SimpleDoubleProperty(), new SimpleDoubleProperty(), new SimpleFloatProperty(), new SimpleLongProperty(), new SimpleIntegerProperty() - ); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPropertyList(Property p0, Property[] props) { - final int n = props.length; - final Binding[] result = new Binding[n]; - for (int i=0; i generatePropertyProperty(Property op0, Property op1) { - return Bindings.when(cond).then((ObservableNumberValue)op0).otherwise((ObservableNumberValue)op1); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPrimitive(Property op0, Number op1) { - final ObservableNumberValue p0 = (ObservableNumberValue)op0; - return new Binding[] { - Bindings.when(cond).then(p0).otherwise(op1.doubleValue()), - Bindings.when(cond).then(p0).otherwise(op1.floatValue()), - Bindings.when(cond).then(p0).otherwise(op1.longValue()), - Bindings.when(cond).then(p0).otherwise(op1.intValue()) - }; - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitiveProperty(Number op0, Property op1) { - final ObservableNumberValue p1 = (ObservableNumberValue)op1; - return new Binding[] { - Bindings.when(cond).then(op0.doubleValue()).otherwise(p1), - Bindings.when(cond).then(op0.floatValue()).otherwise(p1), - Bindings.when(cond).then(op0.longValue()).otherwise(p1), - Bindings.when(cond).then(op0.intValue()).otherwise(p1) - }; - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitivePrimitive(Number op0, Number op1) { - return new Binding[] { - Bindings.when(cond).then(op0.longValue()).otherwise(op1.doubleValue()), - Bindings.when(cond).then(op0.longValue()).otherwise(op1.floatValue()), - Bindings.when(cond).then(op0.longValue()).otherwise(op1.longValue()), - Bindings.when(cond).then(op0.longValue()).otherwise(op1.intValue()) - }; - } - - @Override - public void check(Number expected, Binding binding) { - assertEquals(expected.longValue(), binding.getValue().longValue()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/When_Long_Test.java 2015-08-31 10:24:37.821216683 -0400 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import static org.junit.Assert.assertEquals; +import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.property.Property; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.value.ObservableNumberValue; + +public class When_Long_Test extends WhenTestBase> { + @SuppressWarnings("unchecked") + public When_Long_Test() { + super( + -1L, 0L, Long.MIN_VALUE, Long.MAX_VALUE, + new SimpleDoubleProperty(), new SimpleDoubleProperty(), new SimpleFloatProperty(), new SimpleLongProperty(), new SimpleIntegerProperty() + ); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPropertyList(Property p0, Property[] props) { + final int n = props.length; + final Binding[] result = new Binding[n]; + for (int i=0; i generatePropertyProperty(Property op0, Property op1) { + return Bindings.when(cond).then((ObservableNumberValue)op0).otherwise((ObservableNumberValue)op1); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPrimitive(Property op0, Number op1) { + final ObservableNumberValue p0 = (ObservableNumberValue)op0; + return new Binding[] { + Bindings.when(cond).then(p0).otherwise(op1.doubleValue()), + Bindings.when(cond).then(p0).otherwise(op1.floatValue()), + Bindings.when(cond).then(p0).otherwise(op1.longValue()), + Bindings.when(cond).then(p0).otherwise(op1.intValue()) + }; + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitiveProperty(Number op0, Property op1) { + final ObservableNumberValue p1 = (ObservableNumberValue)op1; + return new Binding[] { + Bindings.when(cond).then(op0.doubleValue()).otherwise(p1), + Bindings.when(cond).then(op0.floatValue()).otherwise(p1), + Bindings.when(cond).then(op0.longValue()).otherwise(p1), + Bindings.when(cond).then(op0.intValue()).otherwise(p1) + }; + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitivePrimitive(Number op0, Number op1) { + return new Binding[] { + Bindings.when(cond).then(op0.longValue()).otherwise(op1.doubleValue()), + Bindings.when(cond).then(op0.longValue()).otherwise(op1.floatValue()), + Bindings.when(cond).then(op0.longValue()).otherwise(op1.longValue()), + Bindings.when(cond).then(op0.longValue()).otherwise(op1.intValue()) + }; + } + + @Override + public void check(Number expected, Binding binding) { + assertEquals(expected.longValue(), binding.getValue().longValue()); + } +} --- old/modules/base/src/test/java/javafx/binding/When_Object_Test.java 2015-08-31 10:24:38.605216674 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleObjectProperty; - -public class When_Object_Test extends WhenTestBase> { - @SuppressWarnings("unchecked") - public When_Object_Test() { - super( - new Object(), new Object(), new Object(), new Object(), - new SimpleObjectProperty(), new SimpleObjectProperty() - ); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPropertyList(ObjectProperty p0, ObjectProperty[] probs) { - return new Binding[] { - Bindings.when(cond).then(p0).otherwise(probs[0]) - }; - } - - @Override - public Binding generatePropertyProperty(ObjectProperty op0, ObjectProperty op1) { - return Bindings.when(cond).then(op0).otherwise(op1); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPrimitive(ObjectProperty op0, Object op1) { - return new Binding[] { - Bindings.when(cond).then(op0).otherwise(op1) - }; - } - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitiveProperty(Object op0, ObjectProperty op1) { - return new Binding[] { - Bindings.when(cond).then(op0).otherwise(op1) - }; - } - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitivePrimitive(Object op0, Object op1) { - return new Binding[] { - Bindings.when(cond).then(op0).otherwise(op1) - }; - } - @Override - public void check(Object expected, Binding binding) { - org.junit.Assert.assertEquals(expected, binding.getValue()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/When_Object_Test.java 2015-08-31 10:24:38.469216675 -0400 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; + +public class When_Object_Test extends WhenTestBase> { + @SuppressWarnings("unchecked") + public When_Object_Test() { + super( + new Object(), new Object(), new Object(), new Object(), + new SimpleObjectProperty(), new SimpleObjectProperty() + ); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPropertyList(ObjectProperty p0, ObjectProperty[] probs) { + return new Binding[] { + Bindings.when(cond).then(p0).otherwise(probs[0]) + }; + } + + @Override + public Binding generatePropertyProperty(ObjectProperty op0, ObjectProperty op1) { + return Bindings.when(cond).then(op0).otherwise(op1); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPrimitive(ObjectProperty op0, Object op1) { + return new Binding[] { + Bindings.when(cond).then(op0).otherwise(op1) + }; + } + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitiveProperty(Object op0, ObjectProperty op1) { + return new Binding[] { + Bindings.when(cond).then(op0).otherwise(op1) + }; + } + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitivePrimitive(Object op0, Object op1) { + return new Binding[] { + Bindings.when(cond).then(op0).otherwise(op1) + }; + } + @Override + public void check(Object expected, Binding binding) { + org.junit.Assert.assertEquals(expected, binding.getValue()); + } +} --- old/modules/base/src/test/java/javafx/binding/When_String_Test.java 2015-08-31 10:24:39.281216666 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.binding; - -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; - -public class When_String_Test extends WhenTestBase { - public When_String_Test() { - super( - null, "Hello", "Hello World", "", - new SimpleStringProperty(), new SimpleStringProperty() - ); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPropertyList(StringProperty p0, StringProperty[] probs) { - return new Binding[] { - Bindings.when(cond).then(p0).otherwise(probs[0]) - }; - } - - @Override - public Binding generatePropertyProperty(StringProperty op0, StringProperty op1) { - return Bindings.when(cond).then(op0).otherwise(op1); - } - - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePropertyPrimitive(StringProperty op0, String op1) { - return new Binding[] { - Bindings.when(cond).then(op0).otherwise(op1) - }; - } - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitiveProperty(String op0, StringProperty op1) { - return new Binding[] { - Bindings.when(cond).then(op0).otherwise(op1) - }; - } - @SuppressWarnings("unchecked") - @Override - public Binding[] generatePrimitivePrimitive(String op0, String op1) { - return new Binding[] { - Bindings.when(cond).then(op0).otherwise(op1) - }; - } - @Override - public void check(String expected, Binding binding) { - org.junit.Assert.assertEquals(expected, binding.getValue()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/When_String_Test.java 2015-08-31 10:24:39.141216668 -0400 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding; + +import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +public class When_String_Test extends WhenTestBase { + public When_String_Test() { + super( + null, "Hello", "Hello World", "", + new SimpleStringProperty(), new SimpleStringProperty() + ); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPropertyList(StringProperty p0, StringProperty[] probs) { + return new Binding[] { + Bindings.when(cond).then(p0).otherwise(probs[0]) + }; + } + + @Override + public Binding generatePropertyProperty(StringProperty op0, StringProperty op1) { + return Bindings.when(cond).then(op0).otherwise(op1); + } + + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePropertyPrimitive(StringProperty op0, String op1) { + return new Binding[] { + Bindings.when(cond).then(op0).otherwise(op1) + }; + } + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitiveProperty(String op0, StringProperty op1) { + return new Binding[] { + Bindings.when(cond).then(op0).otherwise(op1) + }; + } + @SuppressWarnings("unchecked") + @Override + public Binding[] generatePrimitivePrimitive(String op0, String op1) { + return new Binding[] { + Bindings.when(cond).then(op0).otherwise(op1) + }; + } + @Override + public void check(String expected, Binding binding) { + org.junit.Assert.assertEquals(expected, binding.getValue()); + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/expression/AbstractNumberExpressionTest.java 2015-08-31 10:24:39.833216660 -0400 @@ -0,0 +1,495 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding.expression; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Locale; + +import javafx.beans.InvalidationListener; +import javafx.beans.binding.BooleanBinding; +import javafx.beans.binding.DoubleBinding; +import javafx.beans.binding.FloatBinding; +import javafx.beans.binding.IntegerBinding; +import javafx.beans.binding.LongBinding; +import javafx.beans.binding.NumberBinding; +import javafx.beans.binding.NumberExpressionBase; +import javafx.beans.binding.StringBinding; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableDoubleValueStub; +import javafx.beans.value.ObservableFloatValueStub; +import javafx.beans.value.ObservableIntegerValueStub; +import javafx.beans.value.ObservableLongValueStub; +import javafx.beans.value.ObservableNumberValue; +import test.javafx.binding.DependencyUtils; +import javafx.collections.FXCollections; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +@SuppressWarnings("WebTest") +public class AbstractNumberExpressionTest { + + private static final float EPSILON = 1e-6f; + + private double data1; + private int data2; + private DoubleProperty op1; + private IntegerProperty op2; + private double double1; + private float float1; + private long long1; + private int integer1; + private short short1; + private byte byte1; + + @Before + public void setUp() { + data1 = 90224.8923; + data2 = -13; + op1 = new SimpleDoubleProperty(data1); + op2 = new SimpleIntegerProperty(data2); + double1 = -234.234; + float1 = 111.9f; + long1 = 2009234L; + integer1 = -234734; + short1 = 9824; + byte1 = -123; + } + + @Test + public void testArithmetic() { + final NumberBinding binding1 = op1.add(op2); + assertEquals(data1 + data2, binding1.doubleValue(), EPSILON); + + final NumberBinding binding2 = op1.subtract(op2); + assertEquals(data1 - data2, binding2.doubleValue(), EPSILON); + + final NumberBinding binding3 = op1.multiply(op2); + assertEquals(data1 * data2, binding3.doubleValue(), EPSILON); + + final NumberBinding binding4 = op1.divide(op2); + assertEquals(data1 / data2, binding4.doubleValue(), EPSILON); + + } + + @Test + public void testEquals() { + BooleanBinding binding = op1.isEqualTo(op1, EPSILON); + assertEquals(true, binding.get()); + + binding = op2.isEqualTo(op2); + assertEquals(true, binding.get()); + + binding = op1.isEqualTo(op2, EPSILON); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(data1, EPSILON); + assertEquals(true, binding.get()); + + binding = op1.isEqualTo(data2, EPSILON); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(double1, EPSILON); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(float1, EPSILON); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(long1, EPSILON); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(long1); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(integer1, EPSILON); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(integer1); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(short1, EPSILON); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(short1); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(byte1, EPSILON); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(byte1); + assertEquals(false, binding.get()); + } + + @Test + public void testNotEquals() { + BooleanBinding binding = op1.isNotEqualTo(op1, EPSILON); + assertEquals(false, binding.get()); + + binding = op2.isNotEqualTo(op2); + assertEquals(false, binding.get()); + + binding = op1.isNotEqualTo(op2, EPSILON); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(data1, EPSILON); + assertEquals(false, binding.get()); + + binding = op1.isNotEqualTo(data2, EPSILON); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(double1, EPSILON); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(float1, EPSILON); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(long1, EPSILON); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(long1); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(integer1, EPSILON); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(integer1); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(short1, EPSILON); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(short1); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(byte1, EPSILON); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(byte1); + assertEquals(true, binding.get()); + } + + @Test + public void testGreater() { + BooleanBinding binding = op1.greaterThan(op1); + assertEquals(data1 > data1, binding.get()); + + binding = op1.greaterThan(op2); + assertEquals(data1 > data2, binding.get()); + + binding = op2.greaterThan(op1); + assertEquals(data2 > data1, binding.get()); + + binding = op2.greaterThan(op2); + assertEquals(data2 > data2, binding.get()); + + binding = op1.greaterThan(data1); + assertEquals(data1 > data1, binding.get()); + + binding = op1.greaterThan(data2); + assertEquals(data1 > data2, binding.get()); + + binding = op2.greaterThan(data1); + assertEquals(data2 > data1, binding.get()); + + binding = op2.greaterThan(data2); + assertEquals(data2 > data2, binding.get()); + + binding = op1.greaterThan(double1); + assertEquals(data1 > double1, binding.get()); + + binding = op1.greaterThan(float1); + assertEquals(data1 > float1, binding.get()); + + binding = op1.greaterThan(long1); + assertEquals(data1 > long1, binding.get()); + + binding = op1.greaterThan(integer1); + assertEquals(data1 > integer1, binding.get()); + + binding = op1.greaterThan(short1); + assertEquals(data1 > short1, binding.get()); + + binding = op1.greaterThan(byte1); + assertEquals(data1 > byte1, binding.get()); + } + + @Test + public void testLesser() { + BooleanBinding binding = op1.lessThan(op1); + assertEquals(data1 < data1, binding.get()); + + binding = op1.lessThan(op2); + assertEquals(data1 < data2, binding.get()); + + binding = op2.lessThan(op1); + assertEquals(data2 < data1, binding.get()); + + binding = op2.lessThan(op2); + assertEquals(data2 < data2, binding.get()); + + binding = op1.lessThan(data1); + assertEquals(data1 < data1, binding.get()); + + binding = op1.lessThan(data2); + assertEquals(data1 < data2, binding.get()); + + binding = op2.lessThan(data1); + assertEquals(data2 < data1, binding.get()); + + binding = op2.lessThan(data2); + assertEquals(data2 < data2, binding.get()); + + binding = op1.lessThan(double1); + assertEquals(data1 < double1, binding.get()); + + binding = op1.lessThan(float1); + assertEquals(data1 < float1, binding.get()); + + binding = op1.lessThan(long1); + assertEquals(data1 < long1, binding.get()); + + binding = op1.lessThan(integer1); + assertEquals(data1 < integer1, binding.get()); + + binding = op1.lessThan(short1); + assertEquals(data1 < short1, binding.get()); + + binding = op1.lessThan(byte1); + assertEquals(data1 < byte1, binding.get()); + } + + @Test + public void testGreaterOrEqual() { + BooleanBinding binding = op1.greaterThanOrEqualTo(op1); + assertEquals(data1 >= data1, binding.get()); + + binding = op1.greaterThanOrEqualTo(op2); + assertEquals(data1 >= data2, binding.get()); + + binding = op2.greaterThanOrEqualTo(op1); + assertEquals(data2 >= data1, binding.get()); + + binding = op2.greaterThanOrEqualTo(op2); + assertEquals(data2 >= data2, binding.get()); + + binding = op1.greaterThanOrEqualTo(data1); + assertEquals(data1 >= data1, binding.get()); + + binding = op1.greaterThanOrEqualTo(data2); + assertEquals(data1 >= data2, binding.get()); + + binding = op2.greaterThanOrEqualTo(data1); + assertEquals(data2 >= data1, binding.get()); + + binding = op2.greaterThanOrEqualTo(data2); + assertEquals(data2 >= data2, binding.get()); + + binding = op1.greaterThanOrEqualTo(double1); + assertEquals(data1 >= double1, binding.get()); + + binding = op1.greaterThanOrEqualTo(float1); + assertEquals(data1 >= float1, binding.get()); + + binding = op1.greaterThanOrEqualTo(long1); + assertEquals(data1 >= long1, binding.get()); + + binding = op1.greaterThanOrEqualTo(integer1); + assertEquals(data1 >= integer1, binding.get()); + + binding = op1.greaterThanOrEqualTo(short1); + assertEquals(data1 >= short1, binding.get()); + + binding = op1.greaterThanOrEqualTo(byte1); + assertEquals(data1 >= byte1, binding.get()); + } + + @Test + public void testLesserOrEqual() { + BooleanBinding binding = op1.lessThanOrEqualTo(op1); + assertEquals(data1 <= data1, binding.get()); + + binding = op1.lessThanOrEqualTo(op2); + assertEquals(data1 <= data2, binding.get()); + + binding = op2.lessThanOrEqualTo(op1); + assertEquals(data2 <= data1, binding.get()); + + binding = op2.lessThanOrEqualTo(op2); + assertEquals(data2 <= data2, binding.get()); + + binding = op1.lessThanOrEqualTo(data1); + assertEquals(data1 <= data1, binding.get()); + + binding = op1.lessThanOrEqualTo(data2); + assertEquals(data1 <= data2, binding.get()); + + binding = op2.lessThanOrEqualTo(data1); + assertEquals(data2 <= data1, binding.get()); + + binding = op2.lessThanOrEqualTo(data2); + assertEquals(data2 <= data2, binding.get()); + + binding = op1.lessThanOrEqualTo(double1); + assertEquals(data1 <= double1, binding.get()); + + binding = op1.lessThanOrEqualTo(float1); + assertEquals(data1 <= float1, binding.get()); + + binding = op1.lessThanOrEqualTo(long1); + assertEquals(data1 <= long1, binding.get()); + + binding = op1.lessThanOrEqualTo(integer1); + assertEquals(data1 <= integer1, binding.get()); + + binding = op1.lessThanOrEqualTo(short1); + assertEquals(data1 <= short1, binding.get()); + + binding = op1.lessThanOrEqualTo(byte1); + assertEquals(data1 <= byte1, binding.get()); + } + + public void testFactory() { + assertEquals(op1, NumberExpressionBase.numberExpression(op1)); + + final ObservableDoubleValueStub double2 = new ObservableDoubleValueStub(); + double2.set(double1); + NumberExpressionBase exp = NumberExpressionBase.numberExpression(double2); + assertTrue(exp instanceof DoubleBinding); + assertEquals(FXCollections.singletonObservableList(double2), ((NumberBinding)exp).getDependencies()); + assertEquals(double1, exp.doubleValue(), EPSILON); + double2.set(0.0); + assertEquals(0.0, exp.doubleValue(), EPSILON); + + final ObservableFloatValueStub float2 = new ObservableFloatValueStub(); + float2.set(float1); + exp = NumberExpressionBase.numberExpression(float2); + assertTrue(exp instanceof FloatBinding); + assertEquals(FXCollections.singletonObservableList(float2), ((NumberBinding)exp).getDependencies()); + assertEquals(float1, exp.floatValue(), EPSILON); + float2.set(0.0f); + assertEquals(0.0f, exp.floatValue(), EPSILON); + + final ObservableLongValueStub long2 = new ObservableLongValueStub(); + long2.set(long1); + exp = NumberExpressionBase.numberExpression(long2); + assertTrue(exp instanceof LongBinding); + assertEquals(FXCollections.singletonObservableList(long2), ((NumberBinding)exp).getDependencies()); + assertEquals(long1, exp.longValue()); + long2.set(0L); + assertEquals(0, exp.longValue()); + + final ObservableIntegerValueStub integer2 = new ObservableIntegerValueStub(); + integer2.set(integer1); + exp = NumberExpressionBase.numberExpression(integer2); + assertTrue(exp instanceof IntegerBinding); + assertEquals(FXCollections.singletonObservableList(integer2), ((NumberBinding)exp).getDependencies()); + assertEquals(integer1, exp.intValue()); + integer2.set(0); + assertEquals(0, exp.intValue()); + } + + @Test(expected=NullPointerException.class) + public void testFactory_Null() { + NumberExpressionBase.numberExpression(null); + } + + @Test(expected=IllegalArgumentException.class) + public void testFactory_UnknownClass() { + NumberExpressionBase.numberExpression(new ObservableNumberValue() { + @Override public void addListener(InvalidationListener observer) {} + @Override public void addListener(ChangeListener observer) {} + @Override public void removeListener(InvalidationListener observer) {} + @Override public void removeListener(ChangeListener observer) {} + @Override public Number getValue() {return null;} + @Override public int intValue() {return 0;} + @Override public long longValue() {return 0L;} + @Override public float floatValue() {return 0.0f;} + @Override public double doubleValue() {return 0.0;} + }); + } + + @Test + public void testAsString() { + final IntegerProperty i = new SimpleIntegerProperty(); + final StringBinding s = i.asString(); + DependencyUtils.checkDependencies(s.getDependencies(), i); + assertEquals("0", s.get()); + i.set(42); + assertEquals("42", s.get()); + } + + @Ignore("RT-33413") + @Test + public void testAsString_Format() { + final Locale defaultLocale = Locale.getDefault(); + try { + // checking German default + Locale.setDefault(Locale.GERMAN); + final DoubleProperty d = new SimpleDoubleProperty(Math.PI); + StringBinding s = d.asString("%.4f"); + DependencyUtils.checkDependencies(s.getDependencies(), d); + assertEquals("3,1416", s.get()); + d.set(Math.E); + assertEquals("2,7183", s.get()); + + // checking US default + Locale.setDefault(Locale.US); + d.set(Math.PI); + assertEquals("3.1416", s.get()); + d.set(Math.E); + assertEquals("2.7183", s.get()); + } finally { + Locale.setDefault(defaultLocale); + } + } + + @Ignore("RT-33413") + @Test + public void testAsString_LocaleFormat() { + // checking German default + final DoubleProperty d = new SimpleDoubleProperty(Math.PI); + StringBinding s = d.asString(Locale.GERMAN, "%.4f"); + DependencyUtils.checkDependencies(s.getDependencies(), d); + assertEquals("3,1416", s.get()); + d.set(Math.E); + assertEquals("2,7183", s.get()); + + // checking US default + s = d.asString(Locale.US, "%.4f"); + DependencyUtils.checkDependencies(s.getDependencies(), d); + d.set(Math.PI); + assertEquals("3.1416", s.get()); + d.set(Math.E); + assertEquals("2.7183", s.get()); + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/expression/BooleanExpressionTest.java 2015-08-31 10:24:40.569216652 -0400 @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding.expression; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import javafx.beans.binding.BooleanBinding; +import javafx.beans.binding.BooleanExpression; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.binding.StringBinding; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.value.ObservableBooleanValueStub; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.ObservableValueStub; +import test.javafx.binding.DependencyUtils; +import javafx.collections.FXCollections; + +import org.junit.Before; +import org.junit.Test; + +public class BooleanExpressionTest { + + private BooleanProperty op1; + private BooleanProperty op2; + + @Before + public void setUp() { + op1 = new SimpleBooleanProperty(true); + op2 = new SimpleBooleanProperty(false); + } + + @Test + public void testGetters() { + assertEquals(true, op1.get()); + assertEquals(Boolean.TRUE, op1.getValue()); + + assertEquals(false, op2.get()); + assertEquals(Boolean.FALSE, op2.getValue()); + } + + @Test + public void testAND() { + final BooleanExpression exp = op1.and(op2); + assertEquals(true && false, exp.get()); + + op1.set(false); + assertEquals(false && false, exp.get()); + + op2.set(true); + assertEquals(false && true, exp.get()); + + op1.set(true); + assertEquals(true && true, exp.get()); + } + + @Test + public void testOR() { + final BooleanExpression exp = op1.or(op2); + assertEquals(true || false, exp.get()); + + op1.set(false); + assertEquals(false || false, exp.get()); + + op2.set(true); + assertEquals(false || true, exp.get()); + + op1.set(true); + assertEquals(true || true, exp.get()); + } + + @Test + public void testNOT() { + final BooleanExpression exp = op1.not(); + assertEquals(false, exp.get()); + + op1.set(false); + assertEquals(true, exp.get()); + + op1.set(true); + assertEquals(false, exp.get()); + } + + @Test + public void testEquals() { + final BooleanExpression exp = op1.isEqualTo(op2); + assertEquals(true == false, exp.get()); + + op1.set(false); + assertEquals(false == false, exp.get()); + + op2.set(true); + assertEquals(false == true, exp.get()); + + op1.set(true); + assertEquals(true == true, exp.get()); + } + + @Test + public void testNotEquals() { + final BooleanExpression exp = op1.isNotEqualTo(op2); + assertEquals(true != false, exp.get()); + + op1.set(false); + assertEquals(false != false, exp.get()); + + op2.set(true); + assertEquals(false != true, exp.get()); + + op1.set(true); + assertEquals(true != true, exp.get()); + } + + @Test + public void testAsString() { + final StringBinding binding = op1.asString(); + DependencyUtils.checkDependencies(binding.getDependencies(), op1); + assertEquals("true", binding.get()); + + op1.set(false); + assertEquals("false", binding.get()); + + op1.set(true); + assertEquals("true", binding.get()); + } + + @Test + public void testAsObject() { + final ObservableBooleanValueStub valueModel = new ObservableBooleanValueStub(); + final ObjectExpression exp = BooleanExpression.booleanExpression(valueModel).asObject(); + + assertEquals(Boolean.FALSE, exp.get()); + valueModel.set(true); + assertEquals(Boolean.TRUE, exp.get()); + valueModel.set(false); + assertEquals(Boolean.FALSE, exp.get()); + } + + @Test + public void testFactory() { + final ObservableBooleanValueStub valueModel = new ObservableBooleanValueStub(); + final BooleanExpression exp = BooleanExpression.booleanExpression(valueModel); + + assertTrue(exp instanceof BooleanBinding); + assertEquals(FXCollections.singletonObservableList(valueModel), ((BooleanBinding)exp).getDependencies()); + + assertEquals(false, exp.get()); + valueModel.set(true); + assertEquals(true, exp.get()); + valueModel.set(false); + assertEquals(false, exp.get()); + + // make sure we do not create unnecessary bindings + assertEquals(op1, BooleanExpression.booleanExpression(op1)); + } + + @Test + public void testObjectToBoolean() { + final ObservableValueStub valueModel = new ObservableValueStub(); + final BooleanExpression exp = BooleanExpression.booleanExpression(valueModel); + + assertTrue(exp instanceof BooleanBinding); + assertEquals(FXCollections.singletonObservableList(valueModel), ((BooleanBinding)exp).getDependencies()); + + assertEquals(false, exp.get()); + valueModel.set(true); + assertEquals(true, exp.get()); + valueModel.set(false); + assertEquals(false, exp.get()); + + // make sure we do not create unnecessary bindings + assertEquals(op1, BooleanExpression.booleanExpression((ObservableValue)op1)); + } + + @Test(expected=NullPointerException.class) + public void testFactory_Null() { + BooleanExpression.booleanExpression(null); + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/expression/DoubleExpressionTest.java 2015-08-31 10:24:41.233216644 -0400 @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding.expression; + +import static org.junit.Assert.assertTrue; +import javafx.beans.binding.DoubleBinding; +import javafx.beans.binding.DoubleExpression; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.value.ObservableDoubleValueStub; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.ObservableValueStub; +import javafx.collections.FXCollections; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class DoubleExpressionTest { + + private static final float EPSILON = 1e-6f; + + private double data; + private DoubleProperty op1; + private double double1; + private float float1; + private long long1; + private int integer1; + private short short1; + private byte byte1; + + @Before + public void setUp() { + data = -67.0975; + op1 = new SimpleDoubleProperty(data); + double1 = -234.234; + float1 = 111.9f; + long1 = 2009234L; + integer1 = -234734; + short1 = 9824; + byte1 = -123; + } + + @Test + public void testGetters() { + assertEquals((double)data, op1.doubleValue(), EPSILON); + assertEquals((float)data, op1.floatValue(), EPSILON); + assertEquals((long)data, op1.longValue()); + assertEquals((int)data, op1.intValue()); + } + + @Test + public void testNegation() { + final DoubleBinding binding1 = op1.negate(); + assertEquals(-data, binding1.doubleValue(), EPSILON); + } + + @Test + public void testPlus() { + final DoubleBinding binding1 = op1.add(double1); + assertEquals(data + double1, binding1.doubleValue(), EPSILON); + + final DoubleBinding binding2 = op1.add(float1); + assertEquals(data + float1, binding2.doubleValue(), EPSILON); + + final DoubleBinding binding3 = op1.add(long1); + assertEquals(data + long1, binding3.doubleValue(), EPSILON); + + final DoubleBinding binding4 = op1.add(integer1); + assertEquals(data + integer1, binding4.doubleValue(), EPSILON); + + final DoubleBinding binding5 = op1.add(short1); + assertEquals(data + short1, binding5.doubleValue(), EPSILON); + + final DoubleBinding binding6 = op1.add(byte1); + assertEquals(data + byte1, binding6.doubleValue(), EPSILON); + } + + @Test + public void testMinus() { + final DoubleBinding binding1 = op1.subtract(double1); + assertEquals(data - double1, binding1.doubleValue(), EPSILON); + + final DoubleBinding binding2 = op1.subtract(float1); + assertEquals(data - float1, binding2.doubleValue(), EPSILON); + + final DoubleBinding binding3 = op1.subtract(long1); + assertEquals(data - long1, binding3.doubleValue(), EPSILON); + + final DoubleBinding binding4 = op1.subtract(integer1); + assertEquals(data - integer1, binding4.doubleValue(), EPSILON); + + final DoubleBinding binding5 = op1.subtract(short1); + assertEquals(data - short1, binding5.doubleValue(), EPSILON); + + final DoubleBinding binding6 = op1.subtract(byte1); + assertEquals(data - byte1, binding6.doubleValue(), EPSILON); + } + + @Test + public void testTimes() { + final DoubleBinding binding1 = op1.multiply(double1); + assertEquals(data * double1, binding1.doubleValue(), EPSILON); + + final DoubleBinding binding2 = op1.multiply(float1); + assertEquals(data * float1, binding2.doubleValue(), EPSILON); + + final DoubleBinding binding3 = op1.multiply(long1); + assertEquals(data * long1, binding3.doubleValue(), EPSILON); + + final DoubleBinding binding4 = op1.multiply(integer1); + assertEquals(data * integer1, binding4.doubleValue(), EPSILON); + + final DoubleBinding binding5 = op1.multiply(short1); + assertEquals(data * short1, binding5.doubleValue(), EPSILON); + + final DoubleBinding binding6 = op1.multiply(byte1); + assertEquals(data * byte1, binding6.doubleValue(), EPSILON); + } + + @Test + public void testDividedBy() { + final DoubleBinding binding1 = op1.divide(double1); + assertEquals(data / double1, binding1.doubleValue(), EPSILON); + + final DoubleBinding binding2 = op1.divide(float1); + assertEquals(data / float1, binding2.doubleValue(), EPSILON); + + final DoubleBinding binding3 = op1.divide(long1); + assertEquals(data / long1, binding3.doubleValue(), EPSILON); + + final DoubleBinding binding4 = op1.divide(integer1); + assertEquals(data / integer1, binding4.doubleValue(), EPSILON); + + final DoubleBinding binding5 = op1.divide(short1); + assertEquals(data / short1, binding5.doubleValue(), EPSILON); + + final DoubleBinding binding6 = op1.divide(byte1); + assertEquals(data / byte1, binding6.doubleValue(), EPSILON); + } + + @Test + public void testAsObject() { + final ObservableDoubleValueStub valueModel = new ObservableDoubleValueStub(); + final ObjectExpression exp = DoubleExpression.doubleExpression(valueModel).asObject(); + + assertEquals(0.0, exp.getValue(), EPSILON); + valueModel.set(data); + assertEquals(data, exp.getValue(), EPSILON); + valueModel.set(double1); + assertEquals(double1, exp.getValue(), EPSILON); + } + + @Test + public void testFactory() { + final ObservableDoubleValueStub valueModel = new ObservableDoubleValueStub(); + final DoubleExpression exp = DoubleExpression.doubleExpression(valueModel); + + assertTrue(exp instanceof DoubleBinding); + assertEquals(FXCollections.singletonObservableList(valueModel), ((DoubleBinding)exp).getDependencies()); + + assertEquals(0.0f, exp.doubleValue(), EPSILON); + valueModel.set(data); + assertEquals(data, exp.doubleValue(), EPSILON); + valueModel.set(double1); + assertEquals(double1, exp.doubleValue(), EPSILON); + + // make sure we do not create unnecessary bindings + assertEquals(op1, DoubleExpression.doubleExpression(op1)); + } + + @Test + public void testObjectToDouble() { + final ObservableValueStub valueModel = new ObservableValueStub(); + final DoubleExpression exp = DoubleExpression.doubleExpression(valueModel); + + assertTrue(exp instanceof DoubleBinding); + assertEquals(FXCollections.singletonObservableList(valueModel), ((DoubleBinding)exp).getDependencies()); + + assertEquals(0.0, exp.doubleValue(), EPSILON); + valueModel.set(data); + assertEquals(data, exp.doubleValue(), EPSILON); + valueModel.set(double1); + assertEquals(double1, exp.doubleValue(), EPSILON); + + // make sure we do not create unnecessary bindings + assertEquals(op1, DoubleExpression.doubleExpression((ObservableValue)op1)); + } + + @Test(expected=NullPointerException.class) + public void testFactory_Null() { + DoubleExpression.doubleExpression(null); + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/expression/FloatExpressionTest.java 2015-08-31 10:24:41.881216637 -0400 @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding.expression; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import javafx.beans.binding.DoubleBinding; +import javafx.beans.binding.FloatBinding; +import javafx.beans.binding.FloatExpression; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.property.FloatProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.value.ObservableFloatValueStub; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.ObservableValueStub; +import javafx.collections.FXCollections; + +import org.junit.Before; +import org.junit.Test; + +public class FloatExpressionTest { + + private static final float EPSILON = 1e-6f; + + private float data; + private FloatProperty op1; + private double double1; + private float float1; + private long long1; + private int integer1; + private short short1; + private byte byte1; + + @Before + public void setUp() { + data = 2.1f; + op1 = new SimpleFloatProperty(data); + double1 = -234.234; + float1 = 111.9f; + long1 = 2009234L; + integer1 = -234734; + short1 = 9824; + byte1 = -123; + } + + @Test + public void testGetters() { + assertEquals((double)data, op1.doubleValue(), EPSILON); + assertEquals((float)data, op1.floatValue(), EPSILON); + assertEquals((long)data, op1.longValue()); + assertEquals((int)data, op1.intValue()); + } + + @Test + public void testNegation() { + final FloatBinding binding1 = op1.negate(); + assertEquals(-data, binding1.floatValue(), EPSILON); + } + + @Test + public void testPlus() { + final DoubleBinding binding1 = op1.add(double1); + assertEquals(data + double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.add(float1); + assertEquals(data + float1, binding2.floatValue(), EPSILON); + + final FloatBinding binding3 = op1.add(long1); + assertEquals(data + long1, binding3.floatValue(), EPSILON); + + final FloatBinding binding4 = op1.add(integer1); + assertEquals(data + integer1, binding4.floatValue(), EPSILON); + + final FloatBinding binding5 = op1.add(short1); + assertEquals(data + short1, binding5.floatValue(), EPSILON); + + final FloatBinding binding6 = op1.add(byte1); + assertEquals(data + byte1, binding6.floatValue(), EPSILON); + } + + @Test + public void testMinus() { + final DoubleBinding binding1 = op1.subtract(double1); + assertEquals(data - double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.subtract(float1); + assertEquals(data - float1, binding2.floatValue(), EPSILON); + + final FloatBinding binding3 = op1.subtract(long1); + assertEquals(data - long1, binding3.floatValue(), EPSILON); + + final FloatBinding binding4 = op1.subtract(integer1); + assertEquals(data - integer1, binding4.floatValue(), EPSILON); + + final FloatBinding binding5 = op1.subtract(short1); + assertEquals(data - short1, binding5.floatValue(), EPSILON); + + final FloatBinding binding6 = op1.subtract(byte1); + assertEquals(data - byte1, binding6.floatValue(), EPSILON); + } + + @Test + public void testTimes() { + final DoubleBinding binding1 = op1.multiply(double1); + assertEquals(data * double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.multiply(float1); + assertEquals(data * float1, binding2.floatValue(), EPSILON); + + final FloatBinding binding3 = op1.multiply(long1); + assertEquals(data * long1, binding3.floatValue(), EPSILON); + + final FloatBinding binding4 = op1.multiply(integer1); + assertEquals(data * integer1, binding4.floatValue(), EPSILON); + + final FloatBinding binding5 = op1.multiply(short1); + assertEquals(data * short1, binding5.floatValue(), EPSILON); + + final FloatBinding binding6 = op1.multiply(byte1); + assertEquals(data * byte1, binding6.floatValue(), EPSILON); + } + + @Test + public void testDividedBy() { + final DoubleBinding binding1 = op1.divide(double1); + assertEquals(data / double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.divide(float1); + assertEquals(data / float1, binding2.floatValue(), EPSILON); + + final FloatBinding binding3 = op1.divide(long1); + assertEquals(data / long1, binding3.floatValue(), EPSILON); + + final FloatBinding binding4 = op1.divide(integer1); + assertEquals(data / integer1, binding4.floatValue(), EPSILON); + + final FloatBinding binding5 = op1.divide(short1); + assertEquals(data / short1, binding5.floatValue(), EPSILON); + + final FloatBinding binding6 = op1.divide(byte1); + assertEquals(data / byte1, binding6.floatValue(), EPSILON); + } + + @Test + public void testFactory() { + final ObservableFloatValueStub valueModel = new ObservableFloatValueStub(); + final FloatExpression exp = FloatExpression.floatExpression(valueModel); + + assertTrue(exp instanceof FloatBinding); + assertEquals(FXCollections.singletonObservableList(valueModel), ((FloatBinding)exp).getDependencies()); + + assertEquals(0.0f, exp.floatValue(), EPSILON); + valueModel.set(data); + assertEquals(data, exp.floatValue(), EPSILON); + valueModel.set(float1); + assertEquals(float1, exp.floatValue(), EPSILON); + + // make sure we do not create unnecessary bindings + assertEquals(op1, FloatExpression.floatExpression(op1)); + } + + @Test + public void testAsObject() { + final ObservableFloatValueStub valueModel = new ObservableFloatValueStub(); + final ObjectExpression exp = FloatExpression.floatExpression(valueModel).asObject(); + + assertEquals(0.0f, exp.getValue(), EPSILON); + valueModel.set(data); + assertEquals(data, exp.getValue(), EPSILON); + valueModel.set(float1); + assertEquals(float1, exp.getValue(), EPSILON); + + } + + @Test + public void testObjectToFloat() { + final ObservableValueStub valueModel = new ObservableValueStub(); + final FloatExpression exp = FloatExpression.floatExpression(valueModel); + + assertTrue(exp instanceof FloatBinding); + assertEquals(FXCollections.singletonObservableList(valueModel), ((FloatBinding)exp).getDependencies()); + + assertEquals(0.0f, exp.floatValue(), EPSILON); + valueModel.set(data); + assertEquals(data, exp.floatValue(), EPSILON); + valueModel.set(float1); + assertEquals(float1, exp.floatValue(), EPSILON); + + // make sure we do not create unnecessary bindings + assertEquals(op1, FloatExpression.floatExpression((ObservableValue)op1)); + } + + @Test(expected=NullPointerException.class) + public void testFactory_Null() { + FloatExpression.floatExpression(null); + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/expression/IntegerExpressionTest.java 2015-08-31 10:24:42.545216630 -0400 @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding.expression; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import javafx.beans.binding.DoubleBinding; +import javafx.beans.binding.FloatBinding; +import javafx.beans.binding.IntegerBinding; +import javafx.beans.binding.IntegerExpression; +import javafx.beans.binding.LongBinding; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.value.ObservableIntegerValueStub; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.ObservableValueStub; +import javafx.collections.FXCollections; + +import org.junit.Before; +import org.junit.Test; + +public class IntegerExpressionTest { + + private static final float EPSILON = 1e-6f; + + private int data; + private IntegerProperty op1; + private double double1; + private float float1; + private long long1; + private int integer1; + private short short1; + private byte byte1; + + @Before + public void setUp() { + data = 34258; + op1 = new SimpleIntegerProperty(data); + double1 = -234.234; + float1 = 111.9f; + long1 = 2009234L; + integer1 = -234734; + short1 = 9824; + byte1 = -123; + } + + @Test + public void testGetters() { + assertEquals((double)data, op1.doubleValue(), EPSILON); + assertEquals((float)data, op1.floatValue(), EPSILON); + assertEquals((long)data, op1.longValue()); + assertEquals((int)data, op1.intValue()); + } + + @Test + public void testNegation() { + final IntegerBinding binding1 = op1.negate(); + assertEquals(-data, binding1.intValue()); + } + + @Test + public void testPlus() { + final DoubleBinding binding1 = op1.add(double1); + assertEquals(data + double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.add(float1); + assertEquals(data + float1, binding2.floatValue(), EPSILON); + + final LongBinding binding3 = op1.add(long1); + assertEquals(data + long1, binding3.longValue()); + + final IntegerBinding binding4 = op1.add(integer1); + assertEquals(data + integer1, binding4.intValue()); + + final IntegerBinding binding5 = op1.add(short1); + assertEquals(data + short1, binding5.intValue()); + + final IntegerBinding binding6 = op1.add(byte1); + assertEquals(data + byte1, binding6.intValue()); + } + + @Test + public void testMinus() { + final DoubleBinding binding1 = op1.subtract(double1); + assertEquals(data - double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.subtract(float1); + assertEquals(data - float1, binding2.floatValue(), EPSILON); + + final LongBinding binding3 = op1.subtract(long1); + assertEquals(data - long1, binding3.longValue()); + + final IntegerBinding binding4 = op1.subtract(integer1); + assertEquals(data - integer1, binding4.intValue()); + + final IntegerBinding binding5 = op1.subtract(short1); + assertEquals(data - short1, binding5.intValue()); + + final IntegerBinding binding6 = op1.subtract(byte1); + assertEquals(data - byte1, binding6.intValue()); + } + + @Test + public void testTimes() { + final DoubleBinding binding1 = op1.multiply(double1); + assertEquals(data * double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.multiply(float1); + assertEquals(data * float1, binding2.floatValue(), EPSILON); + + final LongBinding binding3 = op1.multiply(long1); + assertEquals(data * long1, binding3.longValue()); + + final IntegerBinding binding4 = op1.multiply(integer1); + assertEquals(data * integer1, binding4.intValue()); + + final IntegerBinding binding5 = op1.multiply(short1); + assertEquals(data * short1, binding5.intValue()); + + final IntegerBinding binding6 = op1.multiply(byte1); + assertEquals(data * byte1, binding6.intValue()); + } + + @Test + public void testDividedBy() { + final DoubleBinding binding1 = op1.divide(double1); + assertEquals(data / double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.divide(float1); + assertEquals(data / float1, binding2.floatValue(), EPSILON); + + final LongBinding binding3 = op1.divide(long1); + assertEquals(data / long1, binding3.longValue()); + + final IntegerBinding binding4 = op1.divide(integer1); + assertEquals(data / integer1, binding4.intValue()); + + final IntegerBinding binding5 = op1.divide(short1); + assertEquals(data / short1, binding5.intValue()); + + final IntegerBinding binding6 = op1.divide(byte1); + assertEquals(data / byte1, binding6.intValue()); + } + + @Test + public void testFactory() { + final ObservableIntegerValueStub valueModel = new ObservableIntegerValueStub(); + final IntegerExpression exp = IntegerExpression.integerExpression(valueModel); + + assertTrue(exp instanceof IntegerBinding); + assertEquals(FXCollections.singletonObservableList(valueModel), ((IntegerBinding)exp).getDependencies()); + + assertEquals(0, exp.intValue()); + valueModel.set(data); + assertEquals(data, exp.intValue()); + valueModel.set(integer1); + assertEquals(integer1, exp.intValue()); + + // make sure we do not create unnecessary bindings + assertEquals(op1, IntegerExpression.integerExpression(op1)); + } + + @Test + public void testAsObject() { + final ObservableIntegerValueStub valueModel = new ObservableIntegerValueStub(); + final ObjectExpression exp = IntegerExpression.integerExpression(valueModel).asObject(); + + assertEquals(Integer.valueOf(0), exp.getValue()); + valueModel.set(data); + assertEquals(Integer.valueOf(data), exp.getValue()); + valueModel.set(integer1); + assertEquals(Integer.valueOf(integer1), exp.getValue()); + } + + @Test + public void testObjectToInteger() { + final ObservableValueStub valueModel = new ObservableValueStub(); + final IntegerExpression exp = IntegerExpression.integerExpression(valueModel); + + assertTrue(exp instanceof IntegerBinding); + assertEquals(FXCollections.singletonObservableList(valueModel), ((IntegerBinding)exp).getDependencies()); + + assertEquals(0, exp.intValue()); + valueModel.set(data); + assertEquals(data, exp.intValue()); + valueModel.set(integer1); + assertEquals(integer1, exp.intValue()); + + // make sure we do not create unnecessary bindings + assertEquals(op1, IntegerExpression.integerExpression((ObservableValue)op1)); + } + + @Test(expected=NullPointerException.class) + public void testFactory_Null() { + IntegerExpression.integerExpression(null); + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/expression/ListExpressionTest.java 2015-08-31 10:24:43.205216622 -0400 @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding.expression; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import javafx.beans.binding.BooleanBinding; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import test.com.sun.javafx.binding.ErrorLoggingUtiltity; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ListExpressionTest { + + private static final Integer data1_0 = 7; + private static final Integer data2_0 = 42; + private static final Integer data2_1 = -3; + private static final Integer datax = Integer.MAX_VALUE; + + private static final ErrorLoggingUtiltity log = new ErrorLoggingUtiltity(); + + private ListProperty opNull; + private ListProperty opEmpty; + private ListProperty op1; + private ListProperty op2; + + @Before + public void setUp() { + opNull = new SimpleListProperty(); + opEmpty = new SimpleListProperty(FXCollections.observableArrayList()); + op1 = new SimpleListProperty(FXCollections.observableArrayList(data1_0)); + op2 = new SimpleListProperty(FXCollections.observableArrayList(data2_0, data2_1)); + } + + @BeforeClass + public static void setUpClass() { + log.start(); + } + + @AfterClass + public static void tearDownClass() { + log.stop(); + } + + @Test + public void testGetSize() { + assertEquals(0, opNull.getSize()); + assertEquals(0, opEmpty.getSize()); + assertEquals(1, op1.getSize()); + assertEquals(2, op2.getSize()); + } + + @Test + public void testValueAt_Constant() { + assertNull(opNull.valueAt(0).get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(opEmpty.valueAt(0).get()); + log.checkFine(IndexOutOfBoundsException.class); + + assertEquals(data1_0, op1.valueAt(0).get()); + assertNull(op1.valueAt(1).get()); + log.checkFine(IndexOutOfBoundsException.class); + + assertEquals(data2_0, op2.valueAt(0).get()); + assertEquals(data2_1, op2.valueAt(1).get()); + assertNull(op2.valueAt(2).get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test(expected = IllegalArgumentException.class) + public void testValueAt_Constant_NegativeIndex() { + op1.valueAt(-1); + } + + @Test + public void testValueAt_Variable() { + final IntegerProperty index = new SimpleIntegerProperty(-1); + + assertNull(opNull.valueAt(index).get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(opEmpty.valueAt(index).get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + assertNull(op1.valueAt(index).get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + assertNull(op2.valueAt(index).get()); + log.checkFine(ArrayIndexOutOfBoundsException.class); + + index.set(0); + assertNull(opNull.valueAt(index).get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(opEmpty.valueAt(index).get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(data1_0, op1.valueAt(index).get()); + assertEquals(data2_0, op2.valueAt(index).get()); + + index.set(1); + assertNull(opNull.valueAt(index).get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(opEmpty.valueAt(index).get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(op1.valueAt(index).get()); + log.checkFine(IndexOutOfBoundsException.class); + assertEquals(data2_1, op2.valueAt(index).get()); + + index.set(2); + assertNull(opNull.valueAt(index).get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(opEmpty.valueAt(index).get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(op1.valueAt(index).get()); + log.checkFine(IndexOutOfBoundsException.class); + assertNull(op2.valueAt(index).get()); + log.checkFine(IndexOutOfBoundsException.class); + } + + @Test + public void testIsEqualTo() { + final ObservableList emptyList = FXCollections.emptyObservableList(); + final ObservableList list1 = FXCollections.observableArrayList(data1_0); + final ObservableList list2 = FXCollections.observableArrayList(data2_0, data2_1); + + BooleanBinding binding = opNull.isEqualTo(emptyList); + assertEquals(false, binding.get()); + binding = opNull.isEqualTo(list1); + assertEquals(false, binding.get()); + binding = opNull.isEqualTo(list2); + assertEquals(false, binding.get()); + + binding = opEmpty.isEqualTo(emptyList); + assertEquals(true, binding.get()); + binding = opEmpty.isEqualTo(list1); + assertEquals(false, binding.get()); + binding = opEmpty.isEqualTo(list2); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(emptyList); + assertEquals(false, binding.get()); + binding = op1.isEqualTo(list1); + assertEquals(true, binding.get()); + binding = op1.isEqualTo(list2); + assertEquals(false, binding.get()); + + binding = op2.isEqualTo(emptyList); + assertEquals(false, binding.get()); + binding = op2.isEqualTo(list1); + assertEquals(false, binding.get()); + binding = op2.isEqualTo(list2); + assertEquals(true, binding.get()); + } + + + @Test + public void testIsNotEqualTo() { + final ObservableList emptyList = FXCollections.emptyObservableList(); + final ObservableList list1 = FXCollections.observableArrayList(data1_0); + final ObservableList list2 = FXCollections.observableArrayList(data2_0, data2_1); + + BooleanBinding binding = opNull.isNotEqualTo(emptyList); + assertEquals(true, binding.get()); + binding = opNull.isNotEqualTo(list1); + assertEquals(true, binding.get()); + binding = opNull.isNotEqualTo(list2); + assertEquals(true, binding.get()); + + binding = opEmpty.isNotEqualTo(emptyList); + assertEquals(false, binding.get()); + binding = opEmpty.isNotEqualTo(list1); + assertEquals(true, binding.get()); + binding = opEmpty.isNotEqualTo(list2); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(emptyList); + assertEquals(true, binding.get()); + binding = op1.isNotEqualTo(list1); + assertEquals(false, binding.get()); + binding = op1.isNotEqualTo(list2); + assertEquals(true, binding.get()); + + binding = op2.isNotEqualTo(emptyList); + assertEquals(true, binding.get()); + binding = op2.isNotEqualTo(list1); + assertEquals(true, binding.get()); + binding = op2.isNotEqualTo(list2); + assertEquals(false, binding.get()); + } + + @Test + public void testIsNull() { + assertTrue(opNull.isNull().get()); + assertFalse(opEmpty.isNull().get()); + assertFalse(op1.isNull().get()); + assertFalse(op2.isNull().get()); + } + + @Test + public void testIsNotNull() { + assertFalse(opNull.isNotNull().get()); + assertTrue(opEmpty.isNotNull().get()); + assertTrue(op1.isNotNull().get()); + assertTrue(op2.isNotNull().get()); + } + + @Test + public void testAsString() { + assertEquals("null", opNull.asString().get()); + assertEquals(Collections.emptyList().toString(), opEmpty.asString().get()); + assertEquals(Arrays.asList(data1_0).toString(), op1.asString().get()); + assertEquals(Arrays.asList(data2_0, data2_1).toString(), op2.asString().get()); + } + + @Test + public void testSize() { + assertEquals(0, opNull.size()); + assertEquals(0, opEmpty.size()); + assertEquals(1, op1.size()); + assertEquals(2, op2.size()); + } + + @Test + public void testIsEmpty() { + assertTrue(opNull.isEmpty()); + assertTrue(opEmpty.isEmpty()); + assertFalse(op1.isEmpty()); + assertFalse(op2.isEmpty()); + } + + @Test + public void testContains() { + assertFalse(opNull.contains(data1_0)); + assertFalse(opNull.contains(data2_0)); + assertFalse(opNull.contains(data2_1)); + + assertFalse(opEmpty.contains(data1_0)); + assertFalse(opEmpty.contains(data2_0)); + assertFalse(opEmpty.contains(data2_1)); + + assertTrue(op1.contains(data1_0)); + assertFalse(op1.contains(data2_0)); + assertFalse(op1.contains(data2_1)); + + assertFalse(op2.contains(data1_0)); + assertTrue(op2.contains(data2_0)); + assertTrue(op2.contains(data2_1)); + } + + @Test + public void testIterator() { + assertFalse(opNull.iterator().hasNext()); + assertFalse(opEmpty.iterator().hasNext()); + + Iterator iterator = op1.iterator(); + assertTrue(iterator.hasNext()); + assertEquals(data1_0, iterator.next()); + assertFalse(iterator.hasNext()); + + iterator = op2.iterator(); + assertTrue(iterator.hasNext()); + assertEquals(data2_0, iterator.next()); + assertTrue(iterator.hasNext()); + assertEquals(data2_1, iterator.next()); + assertFalse(iterator.hasNext()); + } + + @Test + public void testToArray_NoArg() { + assertArrayEquals(new Object[0], opNull.toArray()); + assertArrayEquals(new Object[0], opEmpty.toArray()); + assertArrayEquals(new Object[] {data1_0}, op1.toArray()); + assertArrayEquals(new Object[] {data2_0, data2_1}, op2.toArray()); + } + + @Test + public void testToArray_WithArg() { + Integer[] arrayIn = new Integer[] {datax}; + Integer[] arrayOut = opNull.toArray(arrayIn); + assertArrayEquals(new Integer[] {null}, arrayIn); + assertArrayEquals(new Integer[] {null}, arrayOut); + + arrayIn = new Integer[] {datax}; + arrayOut = new Integer[] {datax}; + arrayOut = opEmpty.toArray(arrayIn); + assertArrayEquals(new Integer[] {null}, arrayIn); + assertArrayEquals(new Integer[] {null}, arrayOut); + + arrayIn = new Integer[] {datax}; + arrayOut = new Integer[] {datax}; + arrayOut = op1.toArray(arrayIn); + assertArrayEquals(new Integer[] {data1_0}, arrayIn); + assertArrayEquals(new Integer[] {data1_0}, arrayOut); + + arrayIn = new Integer[] {datax}; + arrayOut = new Integer[] {datax}; + arrayOut = op2.toArray(arrayIn); + assertArrayEquals(new Integer[] {datax}, arrayIn); + assertArrayEquals(new Integer[] {data2_0, data2_1}, arrayOut); + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/expression/LongExpressionTest.java 2015-08-31 10:24:43.797216616 -0400 @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding.expression; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import javafx.beans.binding.DoubleBinding; +import javafx.beans.binding.FloatBinding; +import javafx.beans.binding.LongBinding; +import javafx.beans.binding.LongExpression; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.property.LongProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.value.ObservableLongValueStub; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.ObservableValueStub; +import javafx.collections.FXCollections; + +import org.junit.Before; +import org.junit.Test; + +public class LongExpressionTest { + + private static final float EPSILON = 1e-6f; + + private long data; + private LongProperty op1; + private double double1; + private float float1; + private long long1; + private int integer1; + private short short1; + private byte byte1; + + @Before + public void setUp() { + data = 34258; + op1 = new SimpleLongProperty(data); + double1 = -234.234; + float1 = 111.9f; + long1 = 2009234L; + integer1 = -234734; + short1 = 9824; + byte1 = -123; + } + + @Test + public void testGetters() { + assertEquals((double)data, op1.doubleValue(), EPSILON); + assertEquals((float)data, op1.floatValue(), EPSILON); + assertEquals((long)data, op1.longValue()); + assertEquals((int)data, op1.intValue()); + } + + @Test + public void testNegation() { + final LongBinding binding1 = op1.negate(); + assertEquals(-data, binding1.longValue()); + } + + @Test + public void testPlus() { + final DoubleBinding binding1 = op1.add(double1); + assertEquals(data + double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.add(float1); + assertEquals(data + float1, binding2.floatValue(), EPSILON); + + final LongBinding binding3 = op1.add(long1); + assertEquals(data + long1, binding3.longValue()); + + final LongBinding binding4 = op1.add(integer1); + assertEquals(data + integer1, binding4.longValue()); + + final LongBinding binding5 = op1.add(short1); + assertEquals(data + short1, binding5.longValue()); + + final LongBinding binding6 = op1.add(byte1); + assertEquals(data + byte1, binding6.longValue()); + } + + @Test + public void testMinus() { + final DoubleBinding binding1 = op1.subtract(double1); + assertEquals(data - double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.subtract(float1); + assertEquals(data - float1, binding2.floatValue(), EPSILON); + + final LongBinding binding3 = op1.subtract(long1); + assertEquals(data - long1, binding3.longValue()); + + final LongBinding binding4 = op1.subtract(integer1); + assertEquals(data - integer1, binding4.longValue()); + + final LongBinding binding5 = op1.subtract(short1); + assertEquals(data - short1, binding5.longValue()); + + final LongBinding binding6 = op1.subtract(byte1); + assertEquals(data - byte1, binding6.longValue()); + } + + @Test + public void testTimes() { + final DoubleBinding binding1 = op1.multiply(double1); + assertEquals(data * double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.multiply(float1); + assertEquals(data * float1, binding2.floatValue(), EPSILON); + + final LongBinding binding3 = op1.multiply(long1); + assertEquals(data * long1, binding3.longValue()); + + final LongBinding binding4 = op1.multiply(integer1); + assertEquals(data * integer1, binding4.longValue()); + + final LongBinding binding5 = op1.multiply(short1); + assertEquals(data * short1, binding5.longValue()); + + final LongBinding binding6 = op1.multiply(byte1); + assertEquals(data * byte1, binding6.longValue()); + } + + @Test + public void testDividedBy() { + final DoubleBinding binding1 = op1.divide(double1); + assertEquals(data / double1, binding1.doubleValue(), EPSILON); + + final FloatBinding binding2 = op1.divide(float1); + assertEquals(data / float1, binding2.floatValue(), EPSILON); + + final LongBinding binding3 = op1.divide(long1); + assertEquals(data / long1, binding3.longValue()); + + final LongBinding binding4 = op1.divide(integer1); + assertEquals(data / integer1, binding4.longValue()); + + final LongBinding binding5 = op1.divide(short1); + assertEquals(data / short1, binding5.longValue()); + + final LongBinding binding6 = op1.divide(byte1); + assertEquals(data / byte1, binding6.longValue()); + } + + @Test + public void testFactory() { + final ObservableLongValueStub valueModel = new ObservableLongValueStub(); + final LongExpression exp = LongExpression.longExpression(valueModel); + + assertTrue(exp instanceof LongBinding); + assertEquals(FXCollections.singletonObservableList(valueModel), ((LongBinding)exp).getDependencies()); + + assertEquals(0L, exp.longValue()); + valueModel.set(data); + assertEquals(data, exp.longValue()); + valueModel.set(long1); + assertEquals(long1, exp.longValue()); + + // make sure we do not create unnecessary bindings + assertEquals(op1, LongExpression.longExpression(op1)); + } + + @Test + public void testAsObject() { + final ObservableLongValueStub valueModel = new ObservableLongValueStub(); + final ObjectExpression exp = LongExpression.longExpression(valueModel).asObject(); + + assertEquals(Long.valueOf(0L), exp.getValue()); + valueModel.set(data); + assertEquals(Long.valueOf(data), exp.getValue()); + valueModel.set(long1); + assertEquals(Long.valueOf(long1), exp.getValue()); + } + + @Test + public void testObjectToLong() { + final ObservableValueStub valueModel = new ObservableValueStub(); + final LongExpression exp = LongExpression.longExpression(valueModel); + + assertTrue(exp instanceof LongBinding); + assertEquals(FXCollections.singletonObservableList(valueModel), ((LongBinding)exp).getDependencies()); + + assertEquals(0L, exp.longValue()); + valueModel.set(data); + assertEquals(data, exp.longValue()); + valueModel.set(long1); + assertEquals(long1, exp.longValue()); + + // make sure we do not create unnecessary bindings + assertEquals(op1, LongExpression.longExpression((ObservableValue)op1)); + } + + @Test(expected=NullPointerException.class) + public void testFactory_Null() { + LongExpression.longExpression(null); + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/expression/MapExpressionTest.java 2015-08-31 10:24:44.437216608 -0400 @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding.expression; + +import javafx.beans.binding.BooleanBinding; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.MapProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleMapProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableMap; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +public class MapExpressionTest { + + private static final Number key1_0 = 4711; + private static final Number key2_0 = 4711; + private static final Number key2_1 = 4712; + private static final Number keyx = 4710; + private static final Integer data1_0 = 7; + private static final Integer data2_0 = 42; + private static final Integer data2_1 = -3; + private static final Integer datax = Integer.MAX_VALUE; + + private MapProperty opNull; + private MapProperty opEmpty; + private MapProperty op1; + private MapProperty op2; + + @Before + public void setUp() { + opNull = new SimpleMapProperty(); + opEmpty = new SimpleMapProperty(FXCollections.observableMap(Collections.emptyMap())); + op1 = new SimpleMapProperty(FXCollections.observableMap(Collections.singletonMap(key1_0, data1_0))); + final Map map = new HashMap(); + map.put(key2_0, data2_0); + map.put(key2_1, data2_1); + op2 = new SimpleMapProperty(FXCollections.observableMap(map)); + } + + @Test + public void testGetSize() { + assertEquals(0, opNull.getSize()); + assertEquals(0, opEmpty.getSize()); + assertEquals(1, op1.getSize()); + assertEquals(2, op2.getSize()); + } + + @Test + public void testValueAt_Constant() { + assertNull(opNull.valueAt(0).get()); + assertNull(opEmpty.valueAt(0).get()); + + assertEquals(data1_0, op1.valueAt(key1_0).get()); + assertNull(op1.valueAt(keyx).get()); + + assertEquals(data2_0, op2.valueAt(key2_0).get()); + assertEquals(data2_1, op2.valueAt(key2_1).get()); + assertNull(op2.valueAt(keyx).get()); + } + + @Test + public void testValueAt_Variable() { + final IntegerProperty index = new SimpleIntegerProperty(keyx.intValue()); + + assertNull(opNull.valueAt(index).get()); + assertNull(opNull.valueAt(index).get()); + assertNull(opEmpty.valueAt(index).get()); + assertNull(op1.valueAt(index).get()); + assertNull(op2.valueAt(index).get()); + + index.set(key1_0.intValue()); + assertNull(opNull.valueAt(index).get()); + assertNull(opEmpty.valueAt(index).get()); + assertEquals(data1_0, op1.valueAt(index).get()); + assertEquals(data2_0, op2.valueAt(index).get()); + + index.set(key2_1.intValue()); + assertNull(opNull.valueAt(index).get()); + assertNull(opEmpty.valueAt(index).get()); + assertNull(op1.valueAt(index).get()); + assertEquals(data2_1, op2.valueAt(index).get()); + } + + @Test + public void testIsEqualTo() { + final ObservableMap emptyMap = FXCollections.observableMap(Collections.emptyMap()); + final ObservableMap map1 = FXCollections.observableMap(Collections.singletonMap(key1_0, data1_0)); + final Map map = new HashMap(); + map.put(key2_0, data2_0); + map.put(key2_1, data2_1); + final ObservableMap map2= FXCollections.observableMap(map); + + BooleanBinding binding = opNull.isEqualTo(emptyMap); + assertEquals(false, binding.get()); + binding = opNull.isEqualTo(map1); + assertEquals(false, binding.get()); + binding = opNull.isEqualTo(map2); + assertEquals(false, binding.get()); + + binding = opEmpty.isEqualTo(emptyMap); + assertEquals(true, binding.get()); + binding = opEmpty.isEqualTo(map1); + assertEquals(false, binding.get()); + binding = opEmpty.isEqualTo(map2); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(emptyMap); + assertEquals(false, binding.get()); + binding = op1.isEqualTo(map1); + assertEquals(true, binding.get()); + binding = op1.isEqualTo(map2); + assertEquals(false, binding.get()); + + binding = op2.isEqualTo(emptyMap); + assertEquals(false, binding.get()); + binding = op2.isEqualTo(map1); + assertEquals(false, binding.get()); + binding = op2.isEqualTo(map2); + assertEquals(true, binding.get()); + } + + + @Test + public void testIsNotEqualTo() { + final ObservableMap emptyMap = FXCollections.observableMap(Collections.emptyMap()); + final ObservableMap list1 = FXCollections.observableMap(Collections.singletonMap(key1_0, data1_0)); + final Map map = new HashMap(); + map.put(key2_0, data2_0); + map.put(key2_1, data2_1); + final ObservableMap list2 = FXCollections.observableMap(map); + + BooleanBinding binding = opNull.isNotEqualTo(emptyMap); + assertEquals(true, binding.get()); + binding = opNull.isNotEqualTo(list1); + assertEquals(true, binding.get()); + binding = opNull.isNotEqualTo(list2); + assertEquals(true, binding.get()); + + binding = opEmpty.isNotEqualTo(emptyMap); + assertEquals(false, binding.get()); + binding = opEmpty.isNotEqualTo(list1); + assertEquals(true, binding.get()); + binding = opEmpty.isNotEqualTo(list2); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(emptyMap); + assertEquals(true, binding.get()); + binding = op1.isNotEqualTo(list1); + assertEquals(false, binding.get()); + binding = op1.isNotEqualTo(list2); + assertEquals(true, binding.get()); + + binding = op2.isNotEqualTo(emptyMap); + assertEquals(true, binding.get()); + binding = op2.isNotEqualTo(list1); + assertEquals(true, binding.get()); + binding = op2.isNotEqualTo(list2); + assertEquals(false, binding.get()); + } + + @Test + public void testIsNull() { + assertTrue(opNull.isNull().get()); + assertFalse(opEmpty.isNull().get()); + assertFalse(op1.isNull().get()); + assertFalse(op2.isNull().get()); + } + + @Test + public void testIsNotNull() { + assertFalse(opNull.isNotNull().get()); + assertTrue(opEmpty.isNotNull().get()); + assertTrue(op1.isNotNull().get()); + assertTrue(op2.isNotNull().get()); + } + + @Test + public void testAsString() { + assertEquals("null", opNull.asString().get()); + assertEquals(Collections.emptyMap().toString(), opEmpty.asString().get()); + assertEquals(Collections.singletonMap(key1_0, data1_0).toString(), op1.asString().get()); + } + + @Test + public void testSize() { + assertEquals(0, opNull.size()); + assertEquals(0, opEmpty.size()); + assertEquals(1, op1.size()); + assertEquals(2, op2.size()); + } + + @Test + public void testIsEmpty() { + assertTrue(opNull.isEmpty()); + assertTrue(opEmpty.isEmpty()); + assertFalse(op1.isEmpty()); + assertFalse(op2.isEmpty()); + } + + @Test + public void testContainsKey() { + assertFalse(opNull.containsKey(key1_0)); + assertFalse(opNull.containsKey(key2_0)); + assertFalse(opNull.containsKey(key2_1)); + + assertFalse(opEmpty.containsKey(key1_0)); + assertFalse(opEmpty.containsKey(key2_0)); + assertFalse(opEmpty.containsKey(key2_1)); + + assertTrue(op1.containsKey(key1_0)); + assertFalse(op1.containsKey(key2_1)); + + assertTrue(op2.containsKey(key2_0)); + assertTrue(op2.containsKey(key2_1)); + } + + @Test + public void testContainsValue() { + assertFalse(opNull.containsValue(data1_0)); + assertFalse(opNull.containsValue(data2_0)); + assertFalse(opNull.containsValue(data2_1)); + + assertFalse(opEmpty.containsValue(data1_0)); + assertFalse(opEmpty.containsValue(data2_0)); + assertFalse(opEmpty.containsValue(data2_1)); + + assertTrue(op1.containsValue(data1_0)); + assertFalse(op1.containsValue(data2_0)); + assertFalse(op1.containsValue(data2_1)); + + assertFalse(op2.containsValue(data1_0)); + assertTrue(op2.containsValue(data2_0)); + assertTrue(op2.containsValue(data2_1)); + } + + +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/expression/ObjectExpressionTest.java 2015-08-31 10:24:45.105216601 -0400 @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding.expression; + +import java.util.Locale; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import javafx.beans.binding.BooleanBinding; +import javafx.beans.binding.ObjectBinding; +import javafx.beans.binding.ObjectExpression; +import javafx.beans.binding.StringBinding; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ObservableObjectValueStub; +import test.javafx.binding.DependencyUtils; +import javafx.collections.FXCollections; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class ObjectExpressionTest { + + private Object data1; + private Object data2; + private ObjectProperty op1; + private ObjectProperty op2; + + @Before + public void setUp() { + data1 = new Object(); + data2 = new Object(); + op1 = new SimpleObjectProperty(data1); + op2 = new SimpleObjectProperty(data2); + } + + @Test + public void testEquals() { + BooleanBinding binding = op1.isEqualTo(op1); + assertEquals(true, binding.get()); + + binding = op1.isEqualTo(op2); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(data1); + assertEquals(true, binding.get()); + + binding = op1.isEqualTo(data2); + assertEquals(false, binding.get()); + } + + @Test + public void testNotEquals() { + BooleanBinding binding = op1.isNotEqualTo(op1); + assertEquals(false, binding.get()); + + binding = op1.isNotEqualTo(op2); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(data1); + assertEquals(false, binding.get()); + + binding = op1.isNotEqualTo(data2); + assertEquals(true, binding.get()); + } + + @Test + public void testIsNull() { + BooleanBinding binding = op1.isNull(); + assertEquals(false, binding.get()); + + ObjectProperty op3 = new SimpleObjectProperty(null); + binding = op3.isNull(); + assertEquals(true, binding.get()); + } + + @Test + public void testIsNotNull() { + BooleanBinding binding = op1.isNotNull(); + assertEquals(true, binding.get()); + + ObjectProperty op3 = new SimpleObjectProperty(null); + binding = op3.isNotNull(); + assertEquals(false, binding.get()); + } + + @Test + public void testFactory() { + final ObservableObjectValueStub valueModel = new ObservableObjectValueStub(); + final ObjectExpression exp = ObjectExpression.objectExpression(valueModel); + + assertTrue(exp instanceof ObjectBinding); + assertEquals(FXCollections.singletonObservableList(valueModel), ((ObjectBinding)exp).getDependencies()); + + assertEquals(null, exp.get()); + valueModel.set(data1); + assertEquals(data1, exp.get()); + valueModel.set(data2); + assertEquals(data2, exp.get()); + + // make sure we do not create unnecessary bindings + assertEquals(op1, ObjectExpression.objectExpression(op1)); + } + + @Test(expected=NullPointerException.class) + public void testFactory_Null() { + ObjectExpression.objectExpression(null); + } + + @Test + public void testAsString() { + final StringBinding binding = op1.asString(); + DependencyUtils.checkDependencies(binding.getDependencies(), op1); + + assertEquals(op1.get().toString(), binding.get()); + + op1.set(new Object() { + + @Override + public String toString() { + return "foo"; + } + + }); + assertEquals("foo", binding.get()); + } + + @Test + public void testAsString_Format() { + final StringBinding binding = op1.asString("%h"); + op1.set(new Object() { + + @Override + public String toString() { + return "foo"; + } + + }); + DependencyUtils.checkDependencies(binding.getDependencies(), op1); + assertEquals(Integer.toHexString(op1.get().hashCode()), binding.get()); + + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/expression/SetExpressionTest.java 2015-08-31 10:24:45.869216592 -0400 @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding.expression; + +import javafx.beans.binding.BooleanBinding; +import javafx.beans.property.SetProperty; +import javafx.beans.property.SimpleSetProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableSet; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import java.util.Iterator; + +import static org.junit.Assert.*; + +public class SetExpressionTest { + + private static final Integer data1_0 = 7; + private static final Integer data2_0 = 42; + private static final Integer data2_1 = -3; + private static final Integer datax = Integer.MAX_VALUE; + + private SetProperty opNull; + private SetProperty opEmpty; + private SetProperty op1; + private SetProperty op2; + + @Before + public void setUp() { + opNull = new SimpleSetProperty(); + opEmpty = new SimpleSetProperty(FXCollections.observableSet()); + op1 = new SimpleSetProperty(FXCollections.observableSet(data1_0)); + op2 = new SimpleSetProperty(FXCollections.observableSet(data2_0, data2_1)); + } + + @Test + public void testGetSize() { + assertEquals(0, opNull.getSize()); + assertEquals(0, opEmpty.getSize()); + assertEquals(1, op1.getSize()); + assertEquals(2, op2.getSize()); + } + + @Test + public void testIsEqualTo() { + final ObservableSet emptySet = FXCollections.observableSet(Collections.emptySet()); + final ObservableSet set1 = FXCollections.observableSet(data1_0); + final ObservableSet set2 = FXCollections.observableSet(data2_0, data2_1); + + BooleanBinding binding = opNull.isEqualTo(emptySet); + assertEquals(false, binding.get()); + binding = opNull.isEqualTo(set1); + assertEquals(false, binding.get()); + binding = opNull.isEqualTo(set2); + assertEquals(false, binding.get()); + + binding = opEmpty.isEqualTo(emptySet); + assertEquals(true, binding.get()); + binding = opEmpty.isEqualTo(set1); + assertEquals(false, binding.get()); + binding = opEmpty.isEqualTo(set2); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(emptySet); + assertEquals(false, binding.get()); + binding = op1.isEqualTo(set1); + assertEquals(true, binding.get()); + binding = op1.isEqualTo(set2); + assertEquals(false, binding.get()); + + binding = op2.isEqualTo(emptySet); + assertEquals(false, binding.get()); + binding = op2.isEqualTo(set1); + assertEquals(false, binding.get()); + binding = op2.isEqualTo(set2); + assertEquals(true, binding.get()); + } + + + @Test + public void testIsNotEqualTo() { + final ObservableSet emptySet = FXCollections.observableSet(Collections.emptySet()); + final ObservableSet list1 = FXCollections.observableSet(data1_0); + final ObservableSet list2 = FXCollections.observableSet(data2_0, data2_1); + + BooleanBinding binding = opNull.isNotEqualTo(emptySet); + assertEquals(true, binding.get()); + binding = opNull.isNotEqualTo(list1); + assertEquals(true, binding.get()); + binding = opNull.isNotEqualTo(list2); + assertEquals(true, binding.get()); + + binding = opEmpty.isNotEqualTo(emptySet); + assertEquals(false, binding.get()); + binding = opEmpty.isNotEqualTo(list1); + assertEquals(true, binding.get()); + binding = opEmpty.isNotEqualTo(list2); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(emptySet); + assertEquals(true, binding.get()); + binding = op1.isNotEqualTo(list1); + assertEquals(false, binding.get()); + binding = op1.isNotEqualTo(list2); + assertEquals(true, binding.get()); + + binding = op2.isNotEqualTo(emptySet); + assertEquals(true, binding.get()); + binding = op2.isNotEqualTo(list1); + assertEquals(true, binding.get()); + binding = op2.isNotEqualTo(list2); + assertEquals(false, binding.get()); + } + + @Test + public void testIsNull() { + assertTrue(opNull.isNull().get()); + assertFalse(opEmpty.isNull().get()); + assertFalse(op1.isNull().get()); + assertFalse(op2.isNull().get()); + } + + @Test + public void testIsNotNull() { + assertFalse(opNull.isNotNull().get()); + assertTrue(opEmpty.isNotNull().get()); + assertTrue(op1.isNotNull().get()); + assertTrue(op2.isNotNull().get()); + } + + @Test + public void testAsString() { + assertEquals("null", opNull.asString().get()); + assertEquals(Collections.emptySet().toString(), opEmpty.asString().get()); + assertEquals(Collections.singleton(data1_0).toString(), op1.asString().get()); + } + + @Test + public void testSize() { + assertEquals(0, opNull.size()); + assertEquals(0, opEmpty.size()); + assertEquals(1, op1.size()); + assertEquals(2, op2.size()); + } + + @Test + public void testIsEmpty() { + assertTrue(opNull.isEmpty()); + assertTrue(opEmpty.isEmpty()); + assertFalse(op1.isEmpty()); + assertFalse(op2.isEmpty()); + } + + @Test + public void testContains() { + assertFalse(opNull.contains(data1_0)); + assertFalse(opNull.contains(data2_0)); + assertFalse(opNull.contains(data2_1)); + + assertFalse(opEmpty.contains(data1_0)); + assertFalse(opEmpty.contains(data2_0)); + assertFalse(opEmpty.contains(data2_1)); + + assertTrue(op1.contains(data1_0)); + assertFalse(op1.contains(data2_0)); + assertFalse(op1.contains(data2_1)); + + assertFalse(op2.contains(data1_0)); + assertTrue(op2.contains(data2_0)); + assertTrue(op2.contains(data2_1)); + } + + @Test + public void testIterator() { + assertFalse(opNull.iterator().hasNext()); + assertFalse(opEmpty.iterator().hasNext()); + + Iterator iterator = op1.iterator(); + assertTrue(iterator.hasNext()); + assertEquals(data1_0, iterator.next()); + assertFalse(iterator.hasNext()); + + iterator = op2.iterator(); + assertTrue(iterator.hasNext()); + final Integer next = iterator.next(); + if (data2_0.equals(next)) { + assertTrue(iterator.hasNext()); + assertEquals(data2_1, iterator.next()); + } else if (data2_1.equals(next)) { + assertTrue(iterator.hasNext()); + assertEquals(data2_0, iterator.next()); + } else { + fail(); + } + assertFalse(iterator.hasNext()); + } + + @Test + public void testToArray_NoArg() { + assertArrayEquals(new Object[0], opNull.toArray()); + assertArrayEquals(new Object[0], opEmpty.toArray()); + assertArrayEquals(new Object[] {data1_0}, op1.toArray()); + final Object[] array = op2.toArray(); + assertEquals(2, array.length); + if (data2_0.equals(array[0])) { + assertEquals(data2_1, array[1]); + } else if (data2_1.equals(array[0])) { + assertEquals(data2_0, array[1]); + } else { + fail(); + } + } + + @Test + public void testToArray_WithArg() { + Integer[] arrayIn = new Integer[] {datax}; + Integer[] arrayOut = opNull.toArray(arrayIn); + assertArrayEquals(new Integer[] {null}, arrayIn); + assertArrayEquals(new Integer[] {null}, arrayOut); + + arrayIn = new Integer[] {datax}; + arrayOut = new Integer[] {datax}; + arrayOut = opEmpty.toArray(arrayIn); + assertArrayEquals(new Integer[] {null}, arrayIn); + assertArrayEquals(new Integer[] {null}, arrayOut); + + arrayIn = new Integer[] {datax}; + arrayOut = new Integer[] {datax}; + arrayOut = op1.toArray(arrayIn); + assertArrayEquals(new Integer[] {data1_0}, arrayIn); + assertArrayEquals(new Integer[] {data1_0}, arrayOut); + + arrayIn = new Integer[] {datax}; + arrayOut = new Integer[] {datax}; + arrayOut = op2.toArray(arrayIn); + assertArrayEquals(new Integer[] {datax}, arrayIn); + assertEquals(2, arrayOut.length); + if (data2_0.equals(arrayOut[0])) { + assertEquals(data2_1, arrayOut[1]); + } else if (data2_1.equals(arrayOut[0])) { + assertEquals(data2_0, arrayOut[1]); + } else { + fail(); + } + } +} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/binding/expression/StringExpressionTest.java 2015-08-31 10:24:46.569216584 -0400 @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.binding.expression; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import javafx.beans.binding.BooleanBinding; +import javafx.beans.binding.IntegerBinding; +import javafx.beans.binding.StringBinding; +import javafx.beans.binding.StringExpression; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.beans.value.ObservableIntegerValueStub; +import test.javafx.binding.DependencyUtils; + +import org.junit.Before; +import org.junit.Test; + +public class StringExpressionTest { + + private String data1; + private String data1_ic; + private String data2; + private StringProperty op1; + private StringProperty op2; + + @Before + public void setUp() { + data1 = "Hello"; + data1_ic = "HeLlO"; + data2 = "Goodbye"; + op1 = new SimpleStringProperty(data1); + op2 = new SimpleStringProperty(data2); + } + + @Test + public void testConcat() { + StringExpression expression = op1.concat(op2); + assertEquals(data1 + data2, expression.get()); + + expression = op1.concat(data1); + assertEquals(data1 + data1, expression.get()); + } + + @Test + public void testEquals() { + BooleanBinding binding = op1.isEqualTo(op1); + assertEquals(true, binding.get()); + + binding = op1.isEqualTo(op2); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(data1); + assertEquals(true, binding.get()); + + binding = op1.isEqualTo(data1_ic); + assertEquals(false, binding.get()); + + binding = op1.isEqualTo(data2); + assertEquals(false, binding.get()); + } + + @Test + public void testEqualsIgnoringCase() { + BooleanBinding binding = op1.isEqualToIgnoreCase(op1); + assertEquals(true, binding.get()); + + binding = op1.isEqualToIgnoreCase(op2); + assertEquals(false, binding.get()); + + binding = op1.isEqualToIgnoreCase(data1); + assertEquals(true, binding.get()); + + binding = op1.isEqualToIgnoreCase(data1_ic); + assertEquals(true, binding.get()); + + binding = op1.isEqualToIgnoreCase(data2); + assertEquals(false, binding.get()); + } + + @Test + public void testNotEquals() { + BooleanBinding binding = op1.isNotEqualTo(op1); + assertEquals(false, binding.get()); + + binding = op1.isNotEqualTo(op2); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(data1); + assertEquals(false, binding.get()); + + binding = op1.isNotEqualTo(data1_ic); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualTo(data2); + assertEquals(true, binding.get()); + } + + @Test + public void testNotEqualsIgnoringCase() { + BooleanBinding binding = op1.isNotEqualToIgnoreCase(op1); + assertEquals(false, binding.get()); + + binding = op1.isNotEqualToIgnoreCase(op2); + assertEquals(true, binding.get()); + + binding = op1.isNotEqualToIgnoreCase(data1); + assertEquals(false, binding.get()); + + binding = op1.isNotEqualToIgnoreCase(data1_ic); + assertEquals(false, binding.get()); + + binding = op1.isNotEqualToIgnoreCase(data2); + assertEquals(true, binding.get()); + } + + @Test + public void testIsNull() { + BooleanBinding binding = op1.isNull(); + assertEquals(false, binding.get()); + + StringProperty op3 = new SimpleStringProperty(null); + binding = op3.isNull(); + assertEquals(true, binding.get()); + } + + @Test + public void testIsNotNull() { + BooleanBinding binding = op1.isNotNull(); + assertEquals(true, binding.get()); + + StringProperty op3 = new SimpleStringProperty(null); + binding = op3.isNotNull(); + assertEquals(false, binding.get()); + } + + @Test + public void testGreater() { + BooleanBinding binding = op1.greaterThan(op1); + assertEquals(data1.compareTo(data1) > 0, binding.get()); + + binding = op1.greaterThan(op2); + assertEquals(data1.compareTo(data2) > 0, binding.get()); + + binding = op1.greaterThan(data1); + assertEquals(data1.compareTo(data1) > 0, binding.get()); + + binding = op1.greaterThan(data1_ic); + assertEquals(data1.compareTo(data1_ic) > 0, binding.get()); + + binding = op1.greaterThan(data2); + assertEquals(data1.compareTo(data2) > 0, binding.get()); + } + + @Test + public void testLesser() { + BooleanBinding binding = op1.lessThan(op1); + assertEquals(data1.compareTo(data1) < 0, binding.get()); + + binding = op1.lessThan(op2); + assertEquals(data1.compareTo(data2) < 0, binding.get()); + + binding = op1.lessThan(data1); + assertEquals(data1.compareTo(data1) < 0, binding.get()); + + binding = op1.lessThan(data1_ic); + assertEquals(data1.compareTo(data1_ic) < 0, binding.get()); + + binding = op1.lessThan(data2); + assertEquals(data1.compareTo(data2) < 0, binding.get()); + } + + @Test + public void testGreaterOrEqual() { + BooleanBinding binding = op1.greaterThanOrEqualTo(op1); + assertEquals(data1.compareTo(data1) >= 0, binding.get()); + + binding = op1.greaterThanOrEqualTo(op2); + assertEquals(data1.compareTo(data2) >= 0, binding.get()); + + binding = op1.greaterThanOrEqualTo(data1); + assertEquals(data1.compareTo(data1) >= 0, binding.get()); + + binding = op1.greaterThanOrEqualTo(data1_ic); + assertEquals(data1.compareTo(data1_ic) >= 0, binding.get()); + + binding = op1.greaterThanOrEqualTo(data2); + assertEquals(data1.compareTo(data2) >= 0, binding.get()); + } + + @Test + public void testLesserOrEqual() { + BooleanBinding binding = op1.lessThanOrEqualTo(op1); + assertEquals(data1.compareTo(data1) <= 0, binding.get()); + + binding = op1.lessThanOrEqualTo(op2); + assertEquals(data1.compareTo(data2) <= 0, binding.get()); + + binding = op1.lessThanOrEqualTo(data1); + assertEquals(data1.compareTo(data1) <= 0, binding.get()); + + binding = op1.lessThanOrEqualTo(data1_ic); + assertEquals(data1.compareTo(data1_ic) <= 0, binding.get()); + + binding = op1.lessThanOrEqualTo(data2); + assertEquals(data1.compareTo(data2) <= 0, binding.get()); + } + + @Test + public void testLength() { + IntegerBinding binding = op1.length(); + assertEquals(data1.length(), binding.get()); + + StringProperty op3 = new SimpleStringProperty(null); + binding = op3.length(); + assertEquals(0, binding.get()); + } + + @Test + public void testIsEmpty() { + BooleanBinding binding = op1.isEmpty(); + assertEquals(data1.isEmpty(), binding.get()); + + StringProperty op3 = new SimpleStringProperty(null); + binding = op3.isEmpty(); + assertEquals(true, binding.get()); + } + + @Test + public void testIsNotEmpty() { + BooleanBinding binding = op1.isNotEmpty(); + assertEquals(!data1.isEmpty(), binding.get()); + + StringProperty op3 = new SimpleStringProperty(null); + binding = op3.isNotEmpty(); + assertEquals(false, binding.get()); + } + + @Test + public void testGetValueSafe() { + assertEquals(data1, op1.get()); + assertEquals(data1, op1.getValueSafe()); + + op1.set(null); + assertNull(op1.get()); + assertEquals("", op1.getValueSafe()); + } + + @Test + public void testFactory() { + final ObservableIntegerValueStub valueModel = new ObservableIntegerValueStub(); + final StringExpression exp = StringExpression.stringExpression(valueModel); + + assertTrue(exp instanceof StringBinding); + DependencyUtils.checkDependencies(((StringBinding)exp).getDependencies(), valueModel); + + assertEquals("0", exp.get()); + valueModel.set(42); + assertEquals("42", exp.get()); + valueModel.set(7); + assertEquals("7", exp.get()); + + // make sure we do not create unnecessary bindings + assertEquals(op1, StringExpression.stringExpression(op1)); + } + + @Test(expected=NullPointerException.class) + public void testFactory_Null() { + StringExpression.stringExpression(null); + } + +} --- old/modules/base/src/test/java/javafx/collections/Callable.java 2015-08-31 10:24:47.445216575 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -public interface Callable { - /** - * Computes a result, or throws an exception if unable to do so. - * - * @return computed result - * @throws Exception if unable to compute a result - */ - V call() throws Exception; -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/Callable.java 2015-08-31 10:24:47.313216576 -0400 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +public interface Callable { + /** + * Computes a result, or throws an exception if unable to do so. + * + * @return computed result + * @throws Exception if unable to compute a result + */ + V call() throws Exception; +} --- old/modules/base/src/test/java/javafx/collections/FXCollectionsTest.java 2015-08-31 10:24:48.041216568 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,796 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import javafx.beans.InvalidationListener; -import org.junit.Test; - -import java.util.*; -import javafx.collections.MockSetObserver.Tuple; - -import static org.junit.Assert.*; - -public class FXCollectionsTest { - - @Test - @SuppressWarnings("unchecked") - public void concatTest() { - ObservableList seq = - FXCollections.concat(FXCollections.observableArrayList("foo", "bar"), - FXCollections.observableArrayList("foobar")); - assertArrayEquals(new String[] {"foo", "bar", "foobar"}, seq.toArray(new String[0])); - seq = FXCollections.concat(); - assertTrue(seq.isEmpty()); - seq = FXCollections.concat(FXCollections.observableArrayList("foo")); - assertArrayEquals(new String[] {"foo"}, seq.toArray(new String[0])); - } - - @Test - public void shuffleTest() { - String[] content = new String[] { "foo", "bar", "ham", "eggs", "spam" }; - ObservableList seq = FXCollections.observableArrayList(content); - for (int i = 0; i < 10; ++i ) { - FXCollections.shuffle(seq); - assertEquals(content.length, seq.size()); - for (String s : content) { - assertTrue(seq.contains(s)); - } - } - } - - @Test - public void copyTest() { - ObservableList dest = FXCollections.observableArrayList("a", "b", "c", "d"); - ObservableList src = FXCollections.observableArrayList("foo", "bar"); - final MockListObserver observer = new MockListObserver(); - - dest.addListener(observer); - - FXCollections.copy(dest, src); - assertArrayEquals(new String[] {"foo", "bar", "c", "d" }, dest.toArray(new String[0])); - observer.check1(); - - } - - @Test - public void fillTest() { - ObservableList seq = FXCollections.observableArrayList("foo", "bar"); - final MockListObserver observer = new MockListObserver(); - - seq.addListener(observer); - FXCollections.fill(seq, "ham"); - assertArrayEquals(new String[] {"ham", "ham" }, seq.toArray(new String[0])); - observer.check1(); - } - - @Test - public void replaceAllTest() { - ObservableList seq = FXCollections.observableArrayList("eggs", "ham", "spam", "spam", "eggs", "spam"); - final MockListObserver observer = new MockListObserver(); - - seq.addListener(observer); - FXCollections.replaceAll(seq, "spam", "viking"); - assertArrayEquals(new String[] {"eggs", "ham", "viking", "viking", "eggs", "viking"}, seq.toArray(new String[0])); - observer.check1(); - } - - @Test - public void reverseTest() { - - ObservableList seq1 = FXCollections.observableArrayList("one", "two", "three", "four"); - final MockListObserver observer1 = new MockListObserver(); - seq1.addListener(observer1); - - ObservableList seq2 = FXCollections.observableArrayList("one", "two", "three", "four", "five"); - final MockListObserver observer2 = new MockListObserver(); - seq2.addListener(observer2); - - FXCollections.reverse(seq1); - FXCollections.reverse(seq2); - - assertArrayEquals(new String[] { "four", "three", "two", "one"} , seq1.toArray(new String[0])); - assertArrayEquals(new String[] { "five", "four", "three", "two", "one"} , seq2.toArray(new String[0])); - - observer1.check1(); - observer2.check1(); - } - - @Test - public void rotateTest() { - ObservableList seq = FXCollections.observableArrayList("one", "two", "three", "four", "five"); - final MockListObserver observer = new MockListObserver(); - seq.addListener(observer); - - FXCollections.rotate(seq, 2); - assertArrayEquals(new String[] { "four", "five", "one", "two", "three"} , seq.toArray(new String[0])); - observer.check1(); - observer.clear(); - - FXCollections.rotate(seq, 3); - assertArrayEquals(new String[] { "one", "two", "three", "four", "five"} , seq.toArray(new String[0])); - observer.check1(); - observer.clear(); - - FXCollections.rotate(seq, 8); - assertArrayEquals(new String[] { "three", "four", "five", "one", "two"} , seq.toArray(new String[0])); - observer.check1(); - observer.clear(); - - FXCollections.rotate(seq, -3); - assertArrayEquals(new String[] { "one", "two", "three", "four", "five" } , seq.toArray(new String[0])); - observer.check1(); - observer.clear(); - - } - - @Test - public void sortTest() { - String[] content = new String[] {"one", "two", "three", "four", "five" }; - ObservableList seq = FXCollections.observableArrayList(content); - doSort(seq, true); - seq = new NonSortableObservableList(); - seq.addAll(content); - doSort(seq, false); - } - - @Test - public void sortTest2() { - //test sort on bigger elements, so that it is sorted with mergesort and not insert sort - String[] content = new String[] { "q", "w", "e", "r", "t", "y", "u", "i", "o", "p" }; - ObservableList seq = FXCollections.observableArrayList(content); - final MockListObserver observer = new MockListObserver(); - seq.addListener(observer); - FXCollections.sort(seq); - observer.check1Permutation(seq, new int[] {4, 8, 0, 5, 6, 9, 7, 1, 2, 3}); - seq.setAll( "q", "w", "e", "r", "t", "y", "u", "i", "o", "p"); - observer.clear(); - FXCollections.sort(seq, (o1, o2) -> o1.charAt(0) - o2.charAt(0)); - observer.check1Permutation(seq, new int[] {4, 8, 0, 5, 6, 9, 7, 1, 2, 3}); - } - - @Test - public void sortTest_empty() { - ObservableList seq = FXCollections.observableArrayList(); - final MockListObserver observer = new MockListObserver(); - seq.addListener(observer); - FXCollections.sort(seq); - observer.check0(); - } - - private void doSort(ObservableList seq, boolean permutation) { - final MockListObserver observer = new MockListObserver(); - seq.addListener(observer); - FXCollections.sort(seq); - assertArrayEquals(new String[]{"five", "four", "one", "three", "two"}, seq.toArray(new String[0])); - if (permutation) { - observer.check1Permutation(seq, new int[] {2, 4, 3, 1, 0}); - } else { - observer.check1(); - } - observer.clear(); - FXCollections.sort(seq, (o1, o2) -> -o1.compareTo(o2)); - assertArrayEquals(new String[]{"two", "three", "one", "four", "five"}, seq.toArray(new String[0])); - if (permutation) { - observer.check1Permutation(seq, new int[] {4, 3, 2, 1, 0}); - } else { - observer.check1(); - } - } - - @Test(expected=ClassCastException.class) - @SuppressWarnings("unchecked") - public void sortNotComparableTest() { - ObservableList seq = FXCollections.observableArrayList(new Object(), new Object(), new Object()); - FXCollections.sort(seq); - } - - @Test - public void emptyObservableListTest() { - ObservableList seq = FXCollections.emptyObservableList(); - assertEquals(0, seq.size()); - try { - seq.get(0); - fail("Expected IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException e) { - } - testIfUnmodifiable(seq); - } - - @Test - public void singletonObservableListTest() { - ObservableList seq = FXCollections.singletonObservableList("foo"); - assertEquals(1, seq.size()); - assertEquals("foo", seq.get(0)); - assertEquals("foo", seq.iterator().next()); - assertTrue(seq.contains("foo")); - testIfUnmodifiable(seq); - } - - @Test - public void unmodifiableObservableListTest() { - ObservableList seq = FXCollections.unmodifiableObservableList(FXCollections.observableArrayList("foo")); - testIfUnmodifiable(seq); - } - - @Test - public void unmodifiableObservableMapTest() { - final ObservableMap map = FXCollections.observableMap(new HashMap()); - ObservableMap om = FXCollections.unmodifiableObservableMap(map); - map.put("foo", "bar"); - testIfUnmodifiable(om); - } - - @Test - public void unmodifiableObservableMapTest_KeepsOrder() { - final ObservableMap map = FXCollections.observableMap(new TreeMap<>()); - ObservableMap om = FXCollections.unmodifiableObservableMap(map); - map.put(0, 0); - map.put(1, 1); - map.put(2, 2); - map.put(3, 3); - map.put(4, 4); - map.put(5, 5); - map.put(6, 6); - - map.put(-1, -1); - map.put(-2, -2); - map.put(-3, -3); - map.put(-4, -4); - map.put(-5, -5); - map.put(-6, -6); - - final Iterator v = om.values().iterator(); - final Iterator k = om.keySet().iterator(); - final Iterator> e = om.entrySet().iterator(); - for (int c = -6; c < 7; ++c) { - assertEquals(c, v.next().intValue()); - assertEquals(c, k.next().intValue()); - assertEquals(c, e.next().getKey().intValue()); - } - } - - @Test - public void emptyObservableSetTest() { - ObservableSet set = FXCollections.emptyObservableSet(); - assertEquals(0, set.size()); - assertTrue(set.isEmpty()); - assertFalse(set.contains("foo")); - assertFalse(set.containsAll(Arrays.asList("foo", "foo2"))); - assertTrue(set.containsAll(new LinkedList())); - } - - @Test - public void unmodifiableObservableSetTest() { - ObservableSet set = FXCollections.unmodifiableObservableSet(FXCollections.observableSet("foo", "foo2")); - try { - set.add("foo3"); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - set.addAll(Arrays.asList("foo3", "foo4")); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - set.remove("foo"); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - set.removeAll(Arrays.asList("foo", "foo2")); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - set.retainAll(Arrays.asList("foo")); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - set.clear(); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - final Iterator setIterator = set.iterator(); - if (setIterator.hasNext()) { - setIterator.next(); - setIterator.remove(); - fail("Expected UnsupportedOperationException"); - } - } catch (UnsupportedOperationException e) { - } - } - - @Test - public void checkedListenerObservableSetTest() { - ObservableSet set = FXCollections.checkedObservableSet(FXCollections.observableSet("foo", "foo2"), String.class); - final MockSetObserver observer = new MockSetObserver(); - set.addListener(observer); - try { - set.add("foo3"); - observer.assertAdded(Tuple.tup("foo3")); - set.add("foo4"); - observer.assertAdded(1, Tuple.tup("foo4")); - set.addAll(Arrays.asList("foo5", "foo6")); - observer.assertAdded(2, Tuple.tup("foo5")); - observer.assertAdded(3, Tuple.tup("foo6")); - assertEquals(4, observer.getCallsNumber()); - set.remove("foo2"); - observer.assertRemoved(4, Tuple.tup("foo2")); - assertEquals(5, observer.getCallsNumber()); - } catch (UnsupportedOperationException e) { - } - } - - private void testIfUnmodifiable(Map map) { - try { - map.put("foo", "bar"); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - map.put("fooo", "bar"); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - map.remove("foo"); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - map.clear(); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - Map putMap = new HashMap(); - putMap.put("bar", "bar"); - map.putAll(putMap); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - testIfUnmodifiable(map.values()); - testIfUnmodifiable(map.keySet()); - } - - /** - * Note that observableArrayList should contain "foo" on the first position to be fully tested - * @param seq - */ - private void testIfUnmodifiable(ObservableList seq) { - testIfUnmodifiable((List)seq); - try { - seq.addAll("foo"); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - seq.setAll("foo"); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - if (seq.isEmpty() ) { - testIfUnmodifiable(seq.subList(0, 0)); - } else { - testIfUnmodifiable(seq.subList(0, 1)); - } - } - - private void testIfUnmodifiable(List list) { - testIfUnmodifiable((Collection)list); - try { - list.add(0, "foo"); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - list.addAll(0, Arrays.asList("foo")); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - final ListIterator listIterator = list.listIterator(); - if (listIterator.hasNext()) { - listIterator.next(); - listIterator.remove(); - fail("Expected UnsupportedOperationException"); - } - } catch (UnsupportedOperationException e) { - } - try { - final ListIterator listIterator = list.listIterator(); - if (listIterator.hasNext()) { - listIterator.next(); - listIterator.set("foo"); - fail("Expected UnsupportedOperationException"); - } - } catch (UnsupportedOperationException e) { - } - try { - list.listIterator().add("foo"); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - } - - private void testIfUnmodifiable(Collection col) { - try { - col.add("foo"); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - col.addAll(Arrays.asList("foo")); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - } - try { - if (!col.isEmpty()) { - col.clear(); - fail("Expected UnsupportedOperationException"); - } - } catch (UnsupportedOperationException e) { - } - try { - if (!col.isEmpty()) { - col.remove("foo"); - fail("Expected UnsupportedOperationException"); - } - } catch (UnsupportedOperationException e) { - } - try { - if (!col.isEmpty()) { - col.removeAll(Arrays.asList("foo")); - fail("Expected UnsupportedOperationException"); - } - } catch (UnsupportedOperationException e) { - } - try { - if (!col.isEmpty()) { - col.retainAll(Arrays.asList("bar")); - fail("Expected UnsupportedOperationException"); - } - } catch (UnsupportedOperationException e) { - } - try { - final Iterator it = col.iterator(); - if (it.hasNext()) { - it.next(); - it.remove(); - fail("Expected UnsupportedOperationException"); - } - } catch (UnsupportedOperationException e) { - } - } - - @Test - public void emptyObservableMapTest() { - ObservableMap map = FXCollections.emptyObservableMap(); - assertEquals(0, map.size()); - assertTrue(map.isEmpty()); - assertFalse(map.containsKey("fooKey")); - assertFalse(map.containsValue("fooValue")); - assertEquals(null, map.get("fooKey")); - assertEquals(FXCollections.emptyObservableSet(), map.values()); - assertEquals(FXCollections.emptyObservableSet(), map.keySet()); - assertEquals(FXCollections.emptyObservableSet(), map.entrySet()); - } - - @Test - public void checkedObservableListTest() { - ObservableList list = FXCollections.checkedObservableList(FXCollections.observableArrayList("foo", "foo2"), String.class); - - try { - list.add(Boolean.TRUE); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - try { - list.add(Integer.valueOf(10)); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - list.add("foo3"); - assertArrayEquals(new String[] {"foo", "foo2", "foo3"}, list.toArray(new String[0])); - - try { - list.add(0, Boolean.TRUE); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - list.add(0, "foo0"); - assertArrayEquals(new String[] {"foo0", "foo", "foo2", "foo3"}, list.toArray(new String[0])); - - try { - list.addAll(Boolean.TRUE, Integer.valueOf(15)); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - list.addAll("foo4", "foo5"); - assertArrayEquals(new String[] {"foo0", "foo", "foo2", "foo3", "foo4", "foo5"}, - list.toArray(new String[0])); - - try { - list.addAll(Arrays.asList(Boolean.TRUE, Boolean.FALSE)); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - list.addAll(Arrays.asList("foo6", "foo7")); - assertArrayEquals(new String[] {"foo0", "foo", "foo2", "foo3", "foo4", "foo5", "foo6", "foo7"}, - list.toArray(new String[0])); - - try { - list.addAll(3, Arrays.asList(Boolean.TRUE, Boolean.FALSE)); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - list.addAll(3, Arrays.asList("foo2_1", "foo2_2")); - assertArrayEquals(new String[] {"foo0", "foo", "foo2", "foo2_1", "foo2_2", "foo3", "foo4", "foo5", "foo6", "foo7"}, - list.toArray(new String[0])); - - try { - list.set(2, Boolean.TRUE); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - list.set(2, "fooNew2"); - assertArrayEquals(new String[] {"foo0", "foo", "fooNew2", "foo2_1", "foo2_2", "foo3", "foo4", "foo5", "foo6", "foo7"}, - list.toArray(new String[0])); - - try { - list.setAll(Boolean.TRUE, Boolean.FALSE); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - list.setAll("a", "b", "c"); - assertArrayEquals(new String[] {"a", "b", "c"}, list.toArray(new String[0])); - - try { - list.setAll(Arrays.asList(Boolean.TRUE, Boolean.FALSE)); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - list.setAll(Arrays.asList("1", "2", "3")); - assertArrayEquals(new String[] {"1", "2", "3"}, list.toArray(new String[0])); - } - - @Test - public void checkedObservableMapTest() { - final ObservableMap map = FXCollections.observableMap(new HashMap()); - ObservableMap om = FXCollections.checkedObservableMap(map, String.class, Boolean.class); - - try { - om.put(Integer.valueOf(1), Integer.valueOf(10)); - fail("Expected ClassCastException"); - } catch (Exception ex) { - } - try { - om.put("1", Integer.valueOf(10)); - fail("Expected ClassCastException"); - } catch (Exception ex) { - } - try { - om.put(Integer.valueOf(1), Boolean.TRUE); - fail("Expected ClassCastException"); - } catch (Exception ex) { - } - om.put("1", Boolean.TRUE); - assertEquals(Boolean.TRUE, om.get("1")); - assertEquals(1, map.size()); - - Map putMap = new HashMap(); - putMap.put(Integer.valueOf(1), "10"); - putMap.put(Integer.valueOf(2), "20"); - try { - om.putAll(putMap); - fail("Expected ClassCastException"); - } catch (Exception ex) { - } - putMap.clear(); - putMap.put("1", "10"); - putMap.put("2", "20"); - try { - om.putAll(putMap); - fail("Expected ClassCastException"); - } catch (Exception ex) { - } - putMap.clear(); - putMap.put(Integer.valueOf(1), Boolean.TRUE); - putMap.put(Integer.valueOf(2), Boolean.FALSE); - try { - om.putAll(putMap); - fail("Expected ClassCastException"); - } catch (Exception ex) { - } - putMap.clear(); - putMap.put("1", Boolean.TRUE); - putMap.put("2", Boolean.FALSE); - om.putAll(putMap); - assertEquals(Boolean.TRUE, om.get("1")); - assertEquals(Boolean.FALSE, om.get("2")); - assertEquals(2, om.size()); - } - - @Test - public void checkedObservableSetTest() { - ObservableSet set = FXCollections.checkedObservableSet(FXCollections.observableSet("foo", "foo2"), String.class); - - try { - set.add(Boolean.TRUE); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - try { - set.add(Integer.valueOf(10)); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - set.add("foo3"); - assertTrue(set.containsAll(Arrays.asList("foo", "foo2", "foo3"))); - assertEquals(3, set.size()); - - try { - set.addAll(Arrays.asList(Boolean.TRUE, Boolean.FALSE)); - fail("Expected ClassCastException"); - } catch (ClassCastException ex) { - } - set.addAll(Arrays.asList("foo6", "foo7")); - assertTrue(set.containsAll(Arrays.asList("foo", "foo2", "foo3", "foo6", "foo7"))); - assertEquals(5, set.size()); - } - - private static class NonSortableObservableList extends AbstractList implements ObservableList { - - private List backingList = new ArrayList(); - private Set> listeners = new HashSet>(); - private Set invalidationListeners = new HashSet(); - - @Override - public boolean addAll(String... ts) { - return addAll(Arrays.asList(ts)); - } - - @Override - public boolean setAll(String... ts) { - return setAll(Arrays.asList(ts)); - } - - @Override - public boolean setAll(Collection clctn) { - final List copy = new ArrayList(this); - clear(); - boolean ret = addAll(clctn); - for (ListChangeListener l : listeners) { - l.onChanged(new ListChangeListener.Change(this) { - - boolean valid = true; - - @Override - public int getFrom() { - return 0; - } - - @Override - public int getTo() { - return size(); - } - - @Override - public List getRemoved() { - return copy; - } - - @Override - public boolean wasPermutated() { - return false; - } - - @Override - public boolean next() { - if (valid) { - valid = false; - return true; - } - return false; - } - - @Override - public void reset() { - } - - @Override - public int[] getPermutation() { - return new int[0]; - } - - }); - } - for (InvalidationListener listener : invalidationListeners) { - listener.invalidated(this); - } - return ret; - } - - @Override - public boolean addAll(Collection c) { - return backingList.addAll(c); - } - - @Override - public void clear() { - backingList.clear(); - } - - @Override - public String get(int index) { - return backingList.get(index); - } - - @Override - public int size() { - return backingList.size(); - } - - @Override - public void addListener(InvalidationListener listener) { - invalidationListeners.add(listener); - } - - @Override - public void removeListener(InvalidationListener listener) { - invalidationListeners.remove(listener); - } - - @Override - public void addListener(ListChangeListener ll) { - listeners.add(ll); - } - - @Override - public void removeListener(ListChangeListener ll) { - listeners.remove(ll); - } - - @Override - public boolean removeAll(String... es) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean retainAll(String... es) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void remove(int i, int i1) { - throw new UnsupportedOperationException("Not supported yet."); - } - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/FXCollectionsTest.java 2015-08-31 10:24:47.909216569 -0400 @@ -0,0 +1,801 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import javafx.beans.InvalidationListener; +import org.junit.Test; + +import java.util.*; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; +import test.javafx.collections.MockSetObserver.Tuple; +import javafx.collections.ObservableList; +import javafx.collections.ObservableMap; +import javafx.collections.ObservableSet; + +import static org.junit.Assert.*; + +public class FXCollectionsTest { + + @Test + @SuppressWarnings("unchecked") + public void concatTest() { + ObservableList seq = + FXCollections.concat(FXCollections.observableArrayList("foo", "bar"), + FXCollections.observableArrayList("foobar")); + assertArrayEquals(new String[] {"foo", "bar", "foobar"}, seq.toArray(new String[0])); + seq = FXCollections.concat(); + assertTrue(seq.isEmpty()); + seq = FXCollections.concat(FXCollections.observableArrayList("foo")); + assertArrayEquals(new String[] {"foo"}, seq.toArray(new String[0])); + } + + @Test + public void shuffleTest() { + String[] content = new String[] { "foo", "bar", "ham", "eggs", "spam" }; + ObservableList seq = FXCollections.observableArrayList(content); + for (int i = 0; i < 10; ++i ) { + FXCollections.shuffle(seq); + assertEquals(content.length, seq.size()); + for (String s : content) { + assertTrue(seq.contains(s)); + } + } + } + + @Test + public void copyTest() { + ObservableList dest = FXCollections.observableArrayList("a", "b", "c", "d"); + ObservableList src = FXCollections.observableArrayList("foo", "bar"); + final MockListObserver observer = new MockListObserver(); + + dest.addListener(observer); + + FXCollections.copy(dest, src); + assertArrayEquals(new String[] {"foo", "bar", "c", "d" }, dest.toArray(new String[0])); + observer.check1(); + + } + + @Test + public void fillTest() { + ObservableList seq = FXCollections.observableArrayList("foo", "bar"); + final MockListObserver observer = new MockListObserver(); + + seq.addListener(observer); + FXCollections.fill(seq, "ham"); + assertArrayEquals(new String[] {"ham", "ham" }, seq.toArray(new String[0])); + observer.check1(); + } + + @Test + public void replaceAllTest() { + ObservableList seq = FXCollections.observableArrayList("eggs", "ham", "spam", "spam", "eggs", "spam"); + final MockListObserver observer = new MockListObserver(); + + seq.addListener(observer); + FXCollections.replaceAll(seq, "spam", "viking"); + assertArrayEquals(new String[] {"eggs", "ham", "viking", "viking", "eggs", "viking"}, seq.toArray(new String[0])); + observer.check1(); + } + + @Test + public void reverseTest() { + + ObservableList seq1 = FXCollections.observableArrayList("one", "two", "three", "four"); + final MockListObserver observer1 = new MockListObserver(); + seq1.addListener(observer1); + + ObservableList seq2 = FXCollections.observableArrayList("one", "two", "three", "four", "five"); + final MockListObserver observer2 = new MockListObserver(); + seq2.addListener(observer2); + + FXCollections.reverse(seq1); + FXCollections.reverse(seq2); + + assertArrayEquals(new String[] { "four", "three", "two", "one"} , seq1.toArray(new String[0])); + assertArrayEquals(new String[] { "five", "four", "three", "two", "one"} , seq2.toArray(new String[0])); + + observer1.check1(); + observer2.check1(); + } + + @Test + public void rotateTest() { + ObservableList seq = FXCollections.observableArrayList("one", "two", "three", "four", "five"); + final MockListObserver observer = new MockListObserver(); + seq.addListener(observer); + + FXCollections.rotate(seq, 2); + assertArrayEquals(new String[] { "four", "five", "one", "two", "three"} , seq.toArray(new String[0])); + observer.check1(); + observer.clear(); + + FXCollections.rotate(seq, 3); + assertArrayEquals(new String[] { "one", "two", "three", "four", "five"} , seq.toArray(new String[0])); + observer.check1(); + observer.clear(); + + FXCollections.rotate(seq, 8); + assertArrayEquals(new String[] { "three", "four", "five", "one", "two"} , seq.toArray(new String[0])); + observer.check1(); + observer.clear(); + + FXCollections.rotate(seq, -3); + assertArrayEquals(new String[] { "one", "two", "three", "four", "five" } , seq.toArray(new String[0])); + observer.check1(); + observer.clear(); + + } + + @Test + public void sortTest() { + String[] content = new String[] {"one", "two", "three", "four", "five" }; + ObservableList seq = FXCollections.observableArrayList(content); + doSort(seq, true); + seq = new NonSortableObservableList(); + seq.addAll(content); + doSort(seq, false); + } + + @Test + public void sortTest2() { + //test sort on bigger elements, so that it is sorted with mergesort and not insert sort + String[] content = new String[] { "q", "w", "e", "r", "t", "y", "u", "i", "o", "p" }; + ObservableList seq = FXCollections.observableArrayList(content); + final MockListObserver observer = new MockListObserver(); + seq.addListener(observer); + FXCollections.sort(seq); + observer.check1Permutation(seq, new int[] {4, 8, 0, 5, 6, 9, 7, 1, 2, 3}); + seq.setAll( "q", "w", "e", "r", "t", "y", "u", "i", "o", "p"); + observer.clear(); + FXCollections.sort(seq, (o1, o2) -> o1.charAt(0) - o2.charAt(0)); + observer.check1Permutation(seq, new int[] {4, 8, 0, 5, 6, 9, 7, 1, 2, 3}); + } + + @Test + public void sortTest_empty() { + ObservableList seq = FXCollections.observableArrayList(); + final MockListObserver observer = new MockListObserver(); + seq.addListener(observer); + FXCollections.sort(seq); + observer.check0(); + } + + private void doSort(ObservableList seq, boolean permutation) { + final MockListObserver observer = new MockListObserver(); + seq.addListener(observer); + FXCollections.sort(seq); + assertArrayEquals(new String[]{"five", "four", "one", "three", "two"}, seq.toArray(new String[0])); + if (permutation) { + observer.check1Permutation(seq, new int[] {2, 4, 3, 1, 0}); + } else { + observer.check1(); + } + observer.clear(); + FXCollections.sort(seq, (o1, o2) -> -o1.compareTo(o2)); + assertArrayEquals(new String[]{"two", "three", "one", "four", "five"}, seq.toArray(new String[0])); + if (permutation) { + observer.check1Permutation(seq, new int[] {4, 3, 2, 1, 0}); + } else { + observer.check1(); + } + } + + @Test(expected=ClassCastException.class) + @SuppressWarnings("unchecked") + public void sortNotComparableTest() { + ObservableList seq = FXCollections.observableArrayList(new Object(), new Object(), new Object()); + FXCollections.sort(seq); + } + + @Test + public void emptyObservableListTest() { + ObservableList seq = FXCollections.emptyObservableList(); + assertEquals(0, seq.size()); + try { + seq.get(0); + fail("Expected IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + } + testIfUnmodifiable(seq); + } + + @Test + public void singletonObservableListTest() { + ObservableList seq = FXCollections.singletonObservableList("foo"); + assertEquals(1, seq.size()); + assertEquals("foo", seq.get(0)); + assertEquals("foo", seq.iterator().next()); + assertTrue(seq.contains("foo")); + testIfUnmodifiable(seq); + } + + @Test + public void unmodifiableObservableListTest() { + ObservableList seq = FXCollections.unmodifiableObservableList(FXCollections.observableArrayList("foo")); + testIfUnmodifiable(seq); + } + + @Test + public void unmodifiableObservableMapTest() { + final ObservableMap map = FXCollections.observableMap(new HashMap()); + ObservableMap om = FXCollections.unmodifiableObservableMap(map); + map.put("foo", "bar"); + testIfUnmodifiable(om); + } + + @Test + public void unmodifiableObservableMapTest_KeepsOrder() { + final ObservableMap map = FXCollections.observableMap(new TreeMap<>()); + ObservableMap om = FXCollections.unmodifiableObservableMap(map); + map.put(0, 0); + map.put(1, 1); + map.put(2, 2); + map.put(3, 3); + map.put(4, 4); + map.put(5, 5); + map.put(6, 6); + + map.put(-1, -1); + map.put(-2, -2); + map.put(-3, -3); + map.put(-4, -4); + map.put(-5, -5); + map.put(-6, -6); + + final Iterator v = om.values().iterator(); + final Iterator k = om.keySet().iterator(); + final Iterator> e = om.entrySet().iterator(); + for (int c = -6; c < 7; ++c) { + assertEquals(c, v.next().intValue()); + assertEquals(c, k.next().intValue()); + assertEquals(c, e.next().getKey().intValue()); + } + } + + @Test + public void emptyObservableSetTest() { + ObservableSet set = FXCollections.emptyObservableSet(); + assertEquals(0, set.size()); + assertTrue(set.isEmpty()); + assertFalse(set.contains("foo")); + assertFalse(set.containsAll(Arrays.asList("foo", "foo2"))); + assertTrue(set.containsAll(new LinkedList())); + } + + @Test + public void unmodifiableObservableSetTest() { + ObservableSet set = FXCollections.unmodifiableObservableSet(FXCollections.observableSet("foo", "foo2")); + try { + set.add("foo3"); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + set.addAll(Arrays.asList("foo3", "foo4")); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + set.remove("foo"); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + set.removeAll(Arrays.asList("foo", "foo2")); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + set.retainAll(Arrays.asList("foo")); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + set.clear(); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + final Iterator setIterator = set.iterator(); + if (setIterator.hasNext()) { + setIterator.next(); + setIterator.remove(); + fail("Expected UnsupportedOperationException"); + } + } catch (UnsupportedOperationException e) { + } + } + + @Test + public void checkedListenerObservableSetTest() { + ObservableSet set = FXCollections.checkedObservableSet(FXCollections.observableSet("foo", "foo2"), String.class); + final MockSetObserver observer = new MockSetObserver(); + set.addListener(observer); + try { + set.add("foo3"); + observer.assertAdded(Tuple.tup("foo3")); + set.add("foo4"); + observer.assertAdded(1, Tuple.tup("foo4")); + set.addAll(Arrays.asList("foo5", "foo6")); + observer.assertAdded(2, Tuple.tup("foo5")); + observer.assertAdded(3, Tuple.tup("foo6")); + assertEquals(4, observer.getCallsNumber()); + set.remove("foo2"); + observer.assertRemoved(4, Tuple.tup("foo2")); + assertEquals(5, observer.getCallsNumber()); + } catch (UnsupportedOperationException e) { + } + } + + private void testIfUnmodifiable(Map map) { + try { + map.put("foo", "bar"); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + map.put("fooo", "bar"); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + map.remove("foo"); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + map.clear(); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + Map putMap = new HashMap(); + putMap.put("bar", "bar"); + map.putAll(putMap); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + testIfUnmodifiable(map.values()); + testIfUnmodifiable(map.keySet()); + } + + /** + * Note that observableArrayList should contain "foo" on the first position to be fully tested + * @param seq + */ + private void testIfUnmodifiable(ObservableList seq) { + testIfUnmodifiable((List)seq); + try { + seq.addAll("foo"); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + seq.setAll("foo"); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + if (seq.isEmpty() ) { + testIfUnmodifiable(seq.subList(0, 0)); + } else { + testIfUnmodifiable(seq.subList(0, 1)); + } + } + + private void testIfUnmodifiable(List list) { + testIfUnmodifiable((Collection)list); + try { + list.add(0, "foo"); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + list.addAll(0, Arrays.asList("foo")); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + final ListIterator listIterator = list.listIterator(); + if (listIterator.hasNext()) { + listIterator.next(); + listIterator.remove(); + fail("Expected UnsupportedOperationException"); + } + } catch (UnsupportedOperationException e) { + } + try { + final ListIterator listIterator = list.listIterator(); + if (listIterator.hasNext()) { + listIterator.next(); + listIterator.set("foo"); + fail("Expected UnsupportedOperationException"); + } + } catch (UnsupportedOperationException e) { + } + try { + list.listIterator().add("foo"); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + } + + private void testIfUnmodifiable(Collection col) { + try { + col.add("foo"); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + col.addAll(Arrays.asList("foo")); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + try { + if (!col.isEmpty()) { + col.clear(); + fail("Expected UnsupportedOperationException"); + } + } catch (UnsupportedOperationException e) { + } + try { + if (!col.isEmpty()) { + col.remove("foo"); + fail("Expected UnsupportedOperationException"); + } + } catch (UnsupportedOperationException e) { + } + try { + if (!col.isEmpty()) { + col.removeAll(Arrays.asList("foo")); + fail("Expected UnsupportedOperationException"); + } + } catch (UnsupportedOperationException e) { + } + try { + if (!col.isEmpty()) { + col.retainAll(Arrays.asList("bar")); + fail("Expected UnsupportedOperationException"); + } + } catch (UnsupportedOperationException e) { + } + try { + final Iterator it = col.iterator(); + if (it.hasNext()) { + it.next(); + it.remove(); + fail("Expected UnsupportedOperationException"); + } + } catch (UnsupportedOperationException e) { + } + } + + @Test + public void emptyObservableMapTest() { + ObservableMap map = FXCollections.emptyObservableMap(); + assertEquals(0, map.size()); + assertTrue(map.isEmpty()); + assertFalse(map.containsKey("fooKey")); + assertFalse(map.containsValue("fooValue")); + assertEquals(null, map.get("fooKey")); + assertEquals(FXCollections.emptyObservableSet(), map.values()); + assertEquals(FXCollections.emptyObservableSet(), map.keySet()); + assertEquals(FXCollections.emptyObservableSet(), map.entrySet()); + } + + @Test + public void checkedObservableListTest() { + ObservableList list = FXCollections.checkedObservableList(FXCollections.observableArrayList("foo", "foo2"), String.class); + + try { + list.add(Boolean.TRUE); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + try { + list.add(Integer.valueOf(10)); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + list.add("foo3"); + assertArrayEquals(new String[] {"foo", "foo2", "foo3"}, list.toArray(new String[0])); + + try { + list.add(0, Boolean.TRUE); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + list.add(0, "foo0"); + assertArrayEquals(new String[] {"foo0", "foo", "foo2", "foo3"}, list.toArray(new String[0])); + + try { + list.addAll(Boolean.TRUE, Integer.valueOf(15)); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + list.addAll("foo4", "foo5"); + assertArrayEquals(new String[] {"foo0", "foo", "foo2", "foo3", "foo4", "foo5"}, + list.toArray(new String[0])); + + try { + list.addAll(Arrays.asList(Boolean.TRUE, Boolean.FALSE)); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + list.addAll(Arrays.asList("foo6", "foo7")); + assertArrayEquals(new String[] {"foo0", "foo", "foo2", "foo3", "foo4", "foo5", "foo6", "foo7"}, + list.toArray(new String[0])); + + try { + list.addAll(3, Arrays.asList(Boolean.TRUE, Boolean.FALSE)); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + list.addAll(3, Arrays.asList("foo2_1", "foo2_2")); + assertArrayEquals(new String[] {"foo0", "foo", "foo2", "foo2_1", "foo2_2", "foo3", "foo4", "foo5", "foo6", "foo7"}, + list.toArray(new String[0])); + + try { + list.set(2, Boolean.TRUE); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + list.set(2, "fooNew2"); + assertArrayEquals(new String[] {"foo0", "foo", "fooNew2", "foo2_1", "foo2_2", "foo3", "foo4", "foo5", "foo6", "foo7"}, + list.toArray(new String[0])); + + try { + list.setAll(Boolean.TRUE, Boolean.FALSE); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + list.setAll("a", "b", "c"); + assertArrayEquals(new String[] {"a", "b", "c"}, list.toArray(new String[0])); + + try { + list.setAll(Arrays.asList(Boolean.TRUE, Boolean.FALSE)); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + list.setAll(Arrays.asList("1", "2", "3")); + assertArrayEquals(new String[] {"1", "2", "3"}, list.toArray(new String[0])); + } + + @Test + public void checkedObservableMapTest() { + final ObservableMap map = FXCollections.observableMap(new HashMap()); + ObservableMap om = FXCollections.checkedObservableMap(map, String.class, Boolean.class); + + try { + om.put(Integer.valueOf(1), Integer.valueOf(10)); + fail("Expected ClassCastException"); + } catch (Exception ex) { + } + try { + om.put("1", Integer.valueOf(10)); + fail("Expected ClassCastException"); + } catch (Exception ex) { + } + try { + om.put(Integer.valueOf(1), Boolean.TRUE); + fail("Expected ClassCastException"); + } catch (Exception ex) { + } + om.put("1", Boolean.TRUE); + assertEquals(Boolean.TRUE, om.get("1")); + assertEquals(1, map.size()); + + Map putMap = new HashMap(); + putMap.put(Integer.valueOf(1), "10"); + putMap.put(Integer.valueOf(2), "20"); + try { + om.putAll(putMap); + fail("Expected ClassCastException"); + } catch (Exception ex) { + } + putMap.clear(); + putMap.put("1", "10"); + putMap.put("2", "20"); + try { + om.putAll(putMap); + fail("Expected ClassCastException"); + } catch (Exception ex) { + } + putMap.clear(); + putMap.put(Integer.valueOf(1), Boolean.TRUE); + putMap.put(Integer.valueOf(2), Boolean.FALSE); + try { + om.putAll(putMap); + fail("Expected ClassCastException"); + } catch (Exception ex) { + } + putMap.clear(); + putMap.put("1", Boolean.TRUE); + putMap.put("2", Boolean.FALSE); + om.putAll(putMap); + assertEquals(Boolean.TRUE, om.get("1")); + assertEquals(Boolean.FALSE, om.get("2")); + assertEquals(2, om.size()); + } + + @Test + public void checkedObservableSetTest() { + ObservableSet set = FXCollections.checkedObservableSet(FXCollections.observableSet("foo", "foo2"), String.class); + + try { + set.add(Boolean.TRUE); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + try { + set.add(Integer.valueOf(10)); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + set.add("foo3"); + assertTrue(set.containsAll(Arrays.asList("foo", "foo2", "foo3"))); + assertEquals(3, set.size()); + + try { + set.addAll(Arrays.asList(Boolean.TRUE, Boolean.FALSE)); + fail("Expected ClassCastException"); + } catch (ClassCastException ex) { + } + set.addAll(Arrays.asList("foo6", "foo7")); + assertTrue(set.containsAll(Arrays.asList("foo", "foo2", "foo3", "foo6", "foo7"))); + assertEquals(5, set.size()); + } + + private static class NonSortableObservableList extends AbstractList implements ObservableList { + + private List backingList = new ArrayList(); + private Set> listeners = new HashSet>(); + private Set invalidationListeners = new HashSet(); + + @Override + public boolean addAll(String... ts) { + return addAll(Arrays.asList(ts)); + } + + @Override + public boolean setAll(String... ts) { + return setAll(Arrays.asList(ts)); + } + + @Override + public boolean setAll(Collection clctn) { + final List copy = new ArrayList(this); + clear(); + boolean ret = addAll(clctn); + for (ListChangeListener l : listeners) { + l.onChanged(new ListChangeListener.Change(this) { + + boolean valid = true; + + @Override + public int getFrom() { + return 0; + } + + @Override + public int getTo() { + return size(); + } + + @Override + public List getRemoved() { + return copy; + } + + @Override + public boolean wasPermutated() { + return false; + } + + @Override + public boolean next() { + if (valid) { + valid = false; + return true; + } + return false; + } + + @Override + public void reset() { + } + + @Override + public int[] getPermutation() { + return new int[0]; + } + + }); + } + for (InvalidationListener listener : invalidationListeners) { + listener.invalidated(this); + } + return ret; + } + + @Override + public boolean addAll(Collection c) { + return backingList.addAll(c); + } + + @Override + public void clear() { + backingList.clear(); + } + + @Override + public String get(int index) { + return backingList.get(index); + } + + @Override + public int size() { + return backingList.size(); + } + + @Override + public void addListener(InvalidationListener listener) { + invalidationListeners.add(listener); + } + + @Override + public void removeListener(InvalidationListener listener) { + invalidationListeners.remove(listener); + } + + @Override + public void addListener(ListChangeListener ll) { + listeners.add(ll); + } + + @Override + public void removeListener(ListChangeListener ll) { + listeners.remove(ll); + } + + @Override + public boolean removeAll(String... es) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean retainAll(String... es) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void remove(int i, int i1) { + throw new UnsupportedOperationException("Not supported yet."); + } + + } +} --- old/modules/base/src/test/java/javafx/collections/FilteredListTest.java 2015-08-31 10:24:48.793216559 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,246 +0,0 @@ -/* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import com.sun.javafx.collections.ObservableListWrapper; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.function.Predicate; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.collections.transformation.FilteredList; -import static org.junit.Assert.*; -import org.junit.Before; -import org.junit.Test; - -public class FilteredListTest { - - private ObservableList list; - private MockListObserver mlo; - private FilteredList filteredList; - - @Before - public void setUp() { - list = FXCollections.observableArrayList(); - list.addAll("a", "c", "d", "c"); - Predicate predicate = (String e) -> !e.equals("c"); - mlo = new MockListObserver(); - filteredList = new FilteredList<>(list, predicate); - filteredList.addListener(mlo); - } - - - @Test - public void testLiveMode() { - assertEquals(Arrays.asList("a", "d"), filteredList); - mlo.check0(); - } - - @Test - public void testLiveMode_Add() { - list.clear(); - mlo.clear(); - assertEquals(Collections.emptyList(), filteredList); - list.addAll("a", "c", "d", "c"); - assertEquals(Arrays.asList("a", "d"), filteredList); - mlo.check1AddRemove(filteredList, Collections.emptyList(), 0, 2); - mlo.clear(); - list.add("c"); - mlo.check0(); - list.add(1, "b"); - assertEquals(Arrays.asList("a", "b", "d"), filteredList); - mlo.check1AddRemove(filteredList, Collections.emptyList(), 1, 2); - } - - @Test - public void testLiveMode_Remove() { - list.removeAll(Arrays.asList("c")); - assertEquals(Arrays.asList("a", "d"), filteredList); - mlo.check0(); - mlo.clear(); - list.remove("a"); - assertEquals(Arrays.asList("d"), filteredList); - mlo.check1AddRemove(filteredList, Arrays.asList("a"), 0, 0); - } - - @Test - public void testLiveMode_Permutation() { - FXCollections.sort(list, (o1, o2) -> -o1.compareTo(o2)); - mlo.check1Permutation(filteredList, new int[] {1, 0}); - assertEquals(Arrays.asList("d", "a"), filteredList); - } - - @Test - public void testLiveMode_changeMatcher() { - ObjectProperty> pProperty = new SimpleObjectProperty<>(); - pProperty.set((String e) -> !e.equals("c")); - filteredList = new FilteredList<>(list); - filteredList.predicateProperty().bind(pProperty); - filteredList.addListener(mlo); - assertEquals(Arrays.asList("a", "d"), filteredList); - mlo.check0(); - pProperty.set((String s) -> !s.equals("d")); - mlo.check1AddRemove(filteredList, Arrays.asList("a", "d"), 0, 3); - } - - @Test - public void testLiveMode_mutableElement() { - ObservableList list = Person.createPersonsList("A", "BB", "C"); - - FilteredList filtered = new FilteredList<>(list, - (Person p) -> p.name.get().length() > 1); - MockListObserver lo = new MockListObserver<>(); - filtered.addListener(lo); - - assertEquals(Arrays.asList(new Person("BB")), filtered); - - list.get(0).name.set("AA"); - lo.check1AddRemove(filtered, Collections.EMPTY_LIST, 0, 1); - assertEquals(Person.createPersonsList("AA", "BB"), filtered); - - lo.clear(); - list.get(1).name.set("BBB"); - lo.check1Update(filtered, 1, 2); - assertEquals(Person.createPersonsList("AA", "BBB"), filtered); - - lo.clear(); - list.get(1).name.set("B"); - lo.check1AddRemove(filtered, Person.createPersonsList("B"), 1, 1); - assertEquals(Person.createPersonsList("AA"), filtered); - } - - @Test - public void testLiveMode_mutableElementEmptyList() { - ObservableList list = Person.createPersonsList("A", "B", "C"); - - FilteredList filtered = new FilteredList<>(list, - (Person p) -> p.name.get().length() > 1); - MockListObserver lo = new MockListObserver<>(); - filtered.addListener(lo); - - assertEquals(Collections.EMPTY_LIST, filtered); - - list.get(0).name.set("AA"); - lo.check1AddRemove(filtered, Collections.EMPTY_LIST, 0, 1); - assertEquals(Person.createPersonsList("AA"), filtered); - } - - @Test - public void testLiveMode_mutableElements() { - Person p1 = new Person("A"); - ObservableList list = Person.createPersonsList( - p1, p1, new Person("BB"), new Person("B"), p1, p1, new Person("BC"), p1, new Person("C")); - - FilteredList filtered = new FilteredList<>(list, - (Person p) -> p.name.get().length() > 1); - MockListObserver lo = new MockListObserver<>(); - filtered.addListener(lo); - - assertEquals(Person.createPersonsList("BB", "BC"), filtered); - - p1.name.set("AA"); - lo.checkAddRemove(0, filtered, Collections.EMPTY_LIST, 0, 2); - lo.checkAddRemove(1, filtered, Collections.EMPTY_LIST, 3, 5); - lo.checkAddRemove(2, filtered, Collections.EMPTY_LIST, 6, 7); - assertEquals(Person.createPersonsList("AA", "AA", "BB", "AA", "AA", "BC", "AA"), filtered); - - lo.clear(); - p1.name.set("AAA"); - lo.checkUpdate(0, filtered, 0, 2); - lo.checkUpdate(1, filtered, 3, 5); - lo.checkUpdate(2, filtered, 6, 7); - assertEquals(Person.createPersonsList("AAA", "AAA", "BB", "AAA", "AAA", "BC", "AAA"), filtered); - - lo.clear(); - p1.name.set("A"); - lo.checkAddRemove(0, filtered, Person.createPersonsList("A", "A"), 0, 0); - lo.checkAddRemove(1, filtered, Person.createPersonsList("A", "A"), 1, 1); - lo.checkAddRemove(2, filtered, Person.createPersonsList("A"), 2, 2); - assertEquals(Person.createPersonsList( "BB", "BC"), filtered); - } - - private static class Updater extends ObservableListWrapper { - public Updater(List list) { - super(list); - } - - public void update(int from, int to) { - beginChange(); - for (int i = from; i < to; ++i) { - nextUpdate(i); - } - endChange(); - } - - public void updateAll() { - update(0, size()); - } - } - - @Test - public void testCustomMutableElements() { - Updater list = new Updater<>(Person.createPersonsFromNames( - "A0", "A1", "BB2", "B3", "A4", "A5", "BC6", "A7", "C8")); - - FilteredList filtered = new FilteredList<>(list, - (Person p) -> p.name.get().length() > 2); - MockListObserver lo = new MockListObserver<>(); - filtered.addListener(lo); - - assertEquals(Person.createPersonsList("BB2", "BC6"), filtered); - - list.updateAll(); - lo.checkUpdate(0, filtered, 0, filtered.size()); - - lo.clear(); - list.get(0).name.set("AA0"); - list.get(3).name.set("BB3"); - list.get(5).name.set("AA5"); - list.get(6).name.set("B6"); - list.get(7).name.set("AA7"); - list.updateAll(); - assertEquals(Person.createPersonsList("AA0", "BB2", "BB3", "AA5", "AA7"), filtered); - lo.checkAddRemove(0, filtered, Collections.EMPTY_LIST, 0, 1); - lo.checkAddRemove(1, filtered, Person.createPersonsList("B6"), 2, 5); - lo.checkUpdate(2, filtered, 1, 2); - } - - @Test - public void testNullPredicate() { - filteredList.setPredicate(null); - assertEquals(list.size(), filteredList.size()); - assertEquals(list, filteredList); - mlo.check1AddRemove(filteredList, Arrays.asList("a", "d"), 0, 4); - } - - @Test - public void testSingleArgConstructor() { - filteredList = new FilteredList<>(list); - assertEquals(list.size(), filteredList.size()); - assertEquals(list, filteredList); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/FilteredListTest.java 2015-08-31 10:24:48.593216562 -0400 @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import test.javafx.collections.Person; +import test.javafx.collections.MockListObserver; +import com.sun.javafx.collections.ObservableListWrapper; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.function.Predicate; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.collections.ObservableListWrapperShim; +import javafx.collections.transformation.FilteredList; +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; + +public class FilteredListTest { + + private ObservableList list; + private MockListObserver mlo; + private FilteredList filteredList; + + @Before + public void setUp() { + list = FXCollections.observableArrayList(); + list.addAll("a", "c", "d", "c"); + Predicate predicate = (String e) -> !e.equals("c"); + mlo = new MockListObserver(); + filteredList = new FilteredList<>(list, predicate); + filteredList.addListener(mlo); + } + + + @Test + public void testLiveMode() { + assertEquals(Arrays.asList("a", "d"), filteredList); + mlo.check0(); + } + + @Test + public void testLiveMode_Add() { + list.clear(); + mlo.clear(); + assertEquals(Collections.emptyList(), filteredList); + list.addAll("a", "c", "d", "c"); + assertEquals(Arrays.asList("a", "d"), filteredList); + mlo.check1AddRemove(filteredList, Collections.emptyList(), 0, 2); + mlo.clear(); + list.add("c"); + mlo.check0(); + list.add(1, "b"); + assertEquals(Arrays.asList("a", "b", "d"), filteredList); + mlo.check1AddRemove(filteredList, Collections.emptyList(), 1, 2); + } + + @Test + public void testLiveMode_Remove() { + list.removeAll(Arrays.asList("c")); + assertEquals(Arrays.asList("a", "d"), filteredList); + mlo.check0(); + mlo.clear(); + list.remove("a"); + assertEquals(Arrays.asList("d"), filteredList); + mlo.check1AddRemove(filteredList, Arrays.asList("a"), 0, 0); + } + + @Test + public void testLiveMode_Permutation() { + FXCollections.sort(list, (o1, o2) -> -o1.compareTo(o2)); + mlo.check1Permutation(filteredList, new int[] {1, 0}); + assertEquals(Arrays.asList("d", "a"), filteredList); + } + + @Test + public void testLiveMode_changeMatcher() { + ObjectProperty> pProperty = new SimpleObjectProperty<>(); + pProperty.set((String e) -> !e.equals("c")); + filteredList = new FilteredList<>(list); + filteredList.predicateProperty().bind(pProperty); + filteredList.addListener(mlo); + assertEquals(Arrays.asList("a", "d"), filteredList); + mlo.check0(); + pProperty.set((String s) -> !s.equals("d")); + mlo.check1AddRemove(filteredList, Arrays.asList("a", "d"), 0, 3); + } + + @Test + public void testLiveMode_mutableElement() { + ObservableList list = Person.createPersonsList("A", "BB", "C"); + + FilteredList filtered = new FilteredList<>(list, + (Person p) -> p.name.get().length() > 1); + MockListObserver lo = new MockListObserver<>(); + filtered.addListener(lo); + + assertEquals(Arrays.asList(new Person("BB")), filtered); + + list.get(0).name.set("AA"); + lo.check1AddRemove(filtered, Collections.EMPTY_LIST, 0, 1); + assertEquals(Person.createPersonsList("AA", "BB"), filtered); + + lo.clear(); + list.get(1).name.set("BBB"); + lo.check1Update(filtered, 1, 2); + assertEquals(Person.createPersonsList("AA", "BBB"), filtered); + + lo.clear(); + list.get(1).name.set("B"); + lo.check1AddRemove(filtered, Person.createPersonsList("B"), 1, 1); + assertEquals(Person.createPersonsList("AA"), filtered); + } + + @Test + public void testLiveMode_mutableElementEmptyList() { + ObservableList list = Person.createPersonsList("A", "B", "C"); + + FilteredList filtered = new FilteredList<>(list, + (Person p) -> p.name.get().length() > 1); + MockListObserver lo = new MockListObserver<>(); + filtered.addListener(lo); + + assertEquals(Collections.EMPTY_LIST, filtered); + + list.get(0).name.set("AA"); + lo.check1AddRemove(filtered, Collections.EMPTY_LIST, 0, 1); + assertEquals(Person.createPersonsList("AA"), filtered); + } + + @Test + public void testLiveMode_mutableElements() { + Person p1 = new Person("A"); + ObservableList list = Person.createPersonsList( + p1, p1, new Person("BB"), new Person("B"), p1, p1, new Person("BC"), p1, new Person("C")); + + FilteredList filtered = new FilteredList<>(list, + (Person p) -> p.name.get().length() > 1); + MockListObserver lo = new MockListObserver<>(); + filtered.addListener(lo); + + assertEquals(Person.createPersonsList("BB", "BC"), filtered); + + p1.name.set("AA"); + lo.checkAddRemove(0, filtered, Collections.EMPTY_LIST, 0, 2); + lo.checkAddRemove(1, filtered, Collections.EMPTY_LIST, 3, 5); + lo.checkAddRemove(2, filtered, Collections.EMPTY_LIST, 6, 7); + assertEquals(Person.createPersonsList("AA", "AA", "BB", "AA", "AA", "BC", "AA"), filtered); + + lo.clear(); + p1.name.set("AAA"); + lo.checkUpdate(0, filtered, 0, 2); + lo.checkUpdate(1, filtered, 3, 5); + lo.checkUpdate(2, filtered, 6, 7); + assertEquals(Person.createPersonsList("AAA", "AAA", "BB", "AAA", "AAA", "BC", "AAA"), filtered); + + lo.clear(); + p1.name.set("A"); + lo.checkAddRemove(0, filtered, Person.createPersonsList("A", "A"), 0, 0); + lo.checkAddRemove(1, filtered, Person.createPersonsList("A", "A"), 1, 1); + lo.checkAddRemove(2, filtered, Person.createPersonsList("A"), 2, 2); + assertEquals(Person.createPersonsList( "BB", "BC"), filtered); + } + + private static class Updater extends ObservableListWrapper { + public Updater(List list) { + super(list); + } + + public void update(int from, int to) { + ObservableListWrapperShim.beginChange(this); + for (int i = from; i < to; ++i) { + ObservableListWrapperShim.nextUpdate(this, i); + } + ObservableListWrapperShim.endChange(this); + } + + public void updateAll() { + update(0, size()); + } + } + + @Test + public void testCustomMutableElements() { + Updater list = new Updater<>(Person.createPersonsFromNames( + "A0", "A1", "BB2", "B3", "A4", "A5", "BC6", "A7", "C8")); + + FilteredList filtered = new FilteredList<>(list, + (Person p) -> p.name.get().length() > 2); + MockListObserver lo = new MockListObserver<>(); + filtered.addListener(lo); + + assertEquals(Person.createPersonsList("BB2", "BC6"), filtered); + + list.updateAll(); + lo.checkUpdate(0, filtered, 0, filtered.size()); + + lo.clear(); + list.get(0).name.set("AA0"); + list.get(3).name.set("BB3"); + list.get(5).name.set("AA5"); + list.get(6).name.set("B6"); + list.get(7).name.set("AA7"); + list.updateAll(); + assertEquals(Person.createPersonsList("AA0", "BB2", "BB3", "AA5", "AA7"), filtered); + lo.checkAddRemove(0, filtered, Collections.EMPTY_LIST, 0, 1); + lo.checkAddRemove(1, filtered, Person.createPersonsList("B6"), 2, 5); + lo.checkUpdate(2, filtered, 1, 2); + } + + @Test + public void testNullPredicate() { + filteredList.setPredicate(null); + assertEquals(list.size(), filteredList.size()); + assertEquals(list, filteredList); + mlo.check1AddRemove(filteredList, Arrays.asList("a", "d"), 0, 4); + } + + @Test + public void testSingleArgConstructor() { + filteredList = new FilteredList<>(list); + assertEquals(list.size(), filteredList.size()); + assertEquals(list, filteredList); + } +} --- old/modules/base/src/test/java/javafx/collections/ListChangeBuilderTest.java 2015-08-31 10:24:49.561216551 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,535 +0,0 @@ -/* - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import com.sun.javafx.collections.ObservableListWrapper; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -public class ListChangeBuilderTest { - - private ListChangeBuilder builder; - private ObservableListWrapper observableList; - private ArrayList list; - private MockListObserver observer; - - @Before - public void setUp() { - observer = new MockListObserver(); - list = new ArrayList(Arrays.asList("a", "b", "c", "d")); - observableList = new ObservableListWrapper(list); - observableList.addListener(observer); - builder = new ListChangeBuilder(observableList); - } - - @Test - public void testAddRemove() { - builder.beginChange(); - list.remove(2); - builder.nextRemove(2, "c"); - list.add(2, "cc"); - list.add(3, "ccc"); - builder.nextAdd(2, 4); - list.remove(2); - builder.nextRemove(2, "cc"); - list.remove(3); - builder.nextRemove(3, "d"); - list.add(0, "aa"); - builder.nextAdd(0, 1); - builder.endChange(); - - assertEquals(list, Arrays.asList("aa", "a", "b", "ccc")); - - observer.checkAddRemove(0, observableList, Collections.EMPTY_LIST, 0, 1); - observer.checkAddRemove(1, observableList, Arrays.asList("c", "d"), 3, 4); - } - - @Test - public void testAddRemove_2() { - builder.beginChange(); - list.add("e"); - builder.nextAdd(4, 5); - list.add(3, "dd"); - builder.nextAdd(3, 4); - list.remove(4); - builder.nextRemove(4, "d"); - - list.remove(0); - builder.nextRemove(0, "a"); - builder.endChange(); - - assertEquals(list, Arrays.asList("b", "c", "dd", "e")); - - observer.checkAddRemove(0, observableList, Arrays.asList("a"), 0, 0); - observer.checkAddRemove(1, observableList, Arrays.asList("d"), 2, 4); - } - - @Test - public void testAddRemove_3() { - builder.beginChange(); - list.add("e"); - builder.nextAdd(4, 5); - - list.set(0, "aa"); - builder.nextReplace(0, 1, Arrays.asList("a")); - - list.remove(4); - builder.nextRemove(4, "e"); - - list.remove(0); - builder.nextRemove(0, "aa"); - builder.endChange(); - - assertEquals(list, Arrays.asList("b", "c", "d")); - - observer.check1AddRemove(observableList, Arrays.asList("a"), 0, 0); - - } - - @Test - public void testAddRemove_4() { - builder.beginChange(); - - list.add("e"); - builder.nextAdd(4, 5); - - list.remove(1); - builder.nextRemove(1, "b"); - - list.add(1, "bb"); - builder.nextAdd(1, 2); - - builder.endChange(); - - assertEquals(list, Arrays.asList("a", "bb", "c", "d", "e")); - - observer.checkAddRemove(0, observableList, Arrays.asList("b"), 1, 2); - observer.checkAddRemove(1, observableList, Collections.EMPTY_LIST, 4, 5); - } - - //RT-37089 - @Test - public void testAddRemove_5() { - builder.beginChange(); - - list.addAll(1, Arrays.asList("x", "y")); - builder.nextAdd(1, 3); - - list.remove(2); - builder.nextRemove(2, "y"); - - builder.endChange(); - - observer.check1AddRemove(observableList, Collections.EMPTY_LIST, 1, 2); - - } - - @Test - public void testAdd() { - builder.beginChange(); - - list.add(1, "aa"); - builder.nextAdd(1, 2); - list.add(5, "e"); - builder.nextAdd(5, 6); - list.add(1, "aa"); - builder.nextAdd(1, 2); - list.add(2, "aa"); - builder.nextAdd(2, 3); - list.add(4, "aa"); - builder.nextAdd(4, 5); - - builder.endChange(); - - assertEquals(list, Arrays.asList("a", "aa","aa","aa","aa", "b", "c", "d", "e")); - - observer.checkAddRemove(0, observableList, Collections.EMPTY_LIST, 1, 5); - observer.checkAddRemove(1, observableList, Collections.EMPTY_LIST, 8, 9); - - } - - @Test - public void testRemove() { - builder.beginChange(); - list.remove(0); - builder.nextRemove(0, "a"); - list.remove(2); - builder.nextRemove(2, "d"); - list.remove(0); - builder.nextRemove(0, "b"); - builder.endChange(); - - assertEquals(list, Arrays.asList("c")); - - observer.checkAddRemove(0, observableList, Arrays.asList("a", "b"), 0, 0); - observer.checkAddRemove(1, observableList, Arrays.asList("d"), 1, 1); - - } - - @Test - public void testRemove_2() { - builder.beginChange(); - list.remove(1); - builder.nextRemove(1, "b"); - list.remove(2); - builder.nextRemove(2, "d"); - list.remove(0); - builder.nextRemove(0, "a"); - builder.endChange(); - - assertEquals(list, Arrays.asList("c")); - - observer.checkAddRemove(0, observableList, Arrays.asList("a", "b"), 0, 0); - observer.checkAddRemove(1, observableList, Arrays.asList("d"), 1, 1); - - } - - @Test - public void testUpdate() { - builder.beginChange(); - builder.nextUpdate(1); - builder.nextUpdate(0); - builder.nextUpdate(3); - builder.endChange(); - - observer.checkUpdate(0, observableList, 0, 2); - observer.checkUpdate(1, observableList, 3, 4); - } - - @Test - public void testUpdate_2() { - builder.beginChange(); - builder.nextUpdate(3); - builder.nextUpdate(1); - builder.nextUpdate(0); - builder.nextUpdate(0); - builder.nextUpdate(2); - builder.endChange(); - - observer.checkUpdate(0, observableList, 0, 4); - } - - @Test - public void testPermutation() { - builder.beginChange(); - - builder.nextPermutation(0, 4, new int[] {3, 2, 1, 0}); - builder.nextPermutation(1, 4, new int[] {3, 2, 1}); - builder.endChange(); - - observer.check1Permutation(observableList, new int[] {1, 2, 3, 0}); - } - - @Test - public void testUpdateAndAddRemove() { - builder.beginChange(); - builder.nextUpdate(1); - builder.nextUpdate(2); - list.remove(2); - builder.nextRemove(2, "c"); - list.add(2, "cc"); - list.add(3, "ccc"); - builder.nextAdd(2, 4); - builder.nextUpdate(2); - list.remove(2); - builder.nextRemove(2, "cc"); - list.remove(3); - builder.nextRemove(3, "d"); - list.add(0, "aa"); - builder.nextAdd(0, 1); - builder.endChange(); - - assertEquals(list, Arrays.asList("aa", "a", "b", "ccc")); - - observer.checkAddRemove(0, observableList, Collections.EMPTY_LIST, 0, 1); - observer.checkAddRemove(1, observableList, Arrays.asList("c", "d"), 3, 4); - observer.checkUpdate(2, observableList, 2, 3); - } - - @Test - public void testUpdateAndAddRemove_2() { - builder.beginChange(); - builder.nextUpdate(0); - builder.nextUpdate(1); - list.add(1,"aaa"); - list.add(1,"aa"); - builder.nextAdd(1, 3); - builder.endChange(); - - assertEquals(list, Arrays.asList("a", "aa", "aaa", "b", "c", "d")); - - observer.checkAddRemove(0, observableList, Collections.EMPTY_LIST, 1, 3); - observer.checkUpdate(1, observableList, 0, 1); - observer.checkUpdate(2, observableList, 3, 4); - } - - @Test - public void testUpdateAndAddRemove_3() { - builder.beginChange(); - builder.nextUpdate(2); - builder.nextUpdate(3); - list.add(1,"aa"); - builder.nextAdd(1, 2); - list.remove(0); - builder.nextRemove(0, "a"); - builder.endChange(); - - assertEquals(list, Arrays.asList("aa", "b", "c", "d")); - - observer.checkAddRemove(0, observableList, Arrays.asList("a"), 0, 1); - observer.checkUpdate(1, observableList, 2, 4); - } - - @Test - public void testUpdateAndPermutation() { - builder.beginChange(); - - builder.nextUpdate(1); - builder.nextUpdate(2); - builder.nextPermutation(1, 4, new int[] {3, 2, 1}); - builder.endChange(); - - observer.checkPermutation(0, observableList, 1, 4, new int[] {3, 2, 1}); - observer.checkUpdate(1, observableList, 2, 4); - } - - @Test - public void testUpdateAndPermutation_2() { - builder.beginChange(); - - builder.nextUpdate(0); - builder.nextUpdate(2); - builder.nextPermutation(0, 4, new int[] {1, 3, 2, 0}); - builder.endChange(); - - observer.checkPermutation(0, observableList, 0, 4, new int[] {1, 3, 2, 0}); - observer.checkUpdate(1, observableList, 1, 3); - } - - @Test - public void testAddAndPermutation() { - builder.beginChange(); - - builder.nextAdd(1, 2); // as-if "b" was added - builder.nextPermutation(0, 3, new int[] { 2, 0, 1}); // new order is "b", "c", "a", "d" - - builder.endChange(); - // "c", "a", "d" before "b" was added - observer.checkPermutation(0, observableList, 0, 3, new int[] {1, 0, 2}); - - observer.checkAddRemove(1, observableList, Collections.EMPTY_LIST, 0, 1); - } - - @Test - public void testRemoveAndPermutation() { - builder.beginChange(); - - List removed = Arrays.asList("bb", "bbb"); - - builder.nextRemove(2, removed); - builder.nextPermutation(0, 3, new int[] {2, 0, 1}); - - builder.endChange(); - - observer.checkPermutation(0, observableList, 0, 6, new int[] {4, 0, 2, 3, 1, 5}); - observer.checkAddRemove(1, observableList, removed, 1, 1); - - } - - @Test - public void testAddRemoveAndPermutation() { - builder.beginChange(); - - // Expect list to be "b", "c1", "c2", "d" - List removed = Arrays.asList("c1", "c2"); - // After add: "a", "b", "c1", "c2", "d" - builder.nextAdd(0, 1); - // After replace "a", "b", "c", "d" - builder.nextReplace(2, 3, removed); - builder.nextPermutation(1, 4, new int[] {3, 1, 2}); - - builder.endChange(); - - observer.checkPermutation(0, observableList, 0, 4, new int[] {3, 1, 2, 0}); - observer.checkAddRemove(1, observableList, removed, 0, 2); - } - - @Test - public void testPermutationAndAddRemove() { - builder.beginChange(); - - // Expect list to be "b", "c1", "c2", "d" - // After perm "b", "c2", "d", "c1" - builder.nextPermutation(1, 4, new int[] {3, 1, 2}); - // After add: "a", "b", "c2", "d", "c1" - builder.nextAdd(0, 1); - builder.nextReplace(2, 3, Arrays.asList("c2")); - builder.nextRemove(4, Arrays.asList("c1")); - - builder.endChange(); - - observer.checkPermutation(0, observableList, 1, 4, new int[] {3, 1, 2}); - observer.checkAddRemove(1, observableList, Collections.EMPTY_LIST, 0, 1); - observer.checkAddRemove(2, observableList, Arrays.asList("c2"), 2, 3); - observer.checkAddRemove(3, observableList, Arrays.asList("c1"), 4, 4); - } - - @Test - public void testPermutationAddRemoveAndPermutation() { - - builder.beginChange(); - // Expect list to be "b", "c1", "d" - List removed = Arrays.asList("c1"); - // After perm: "c1", "b", "d" - builder.nextPermutation(0, 2, new int[] { 1, 0 }); - // After add: "a", "c1", "b", "d" - builder.nextAdd(0, 1); - // After remove/add "a", "b", "c", "d" - builder.nextRemove(1, removed); - builder.nextAdd(2, 3); - // After permutation "a", "c", "d", "b" - builder.nextPermutation(1, 4, new int[] {3, 1, 2}); - - builder.endChange(); - - // When combined, it's from the expected list: - // permutation to "c1", "d", "b" - observer.checkPermutation(0, observableList, 0, 3, new int[] {2, 0, 1}); - // add remove to "a", "c", "d", "b" - observer.checkAddRemove(1, observableList, removed, 0, 2); - } - - @Test(expected=IllegalStateException.class) - public void testNextAddWithoutBegin() { - builder.nextAdd(0, 1); - } - - @Test(expected=IllegalStateException.class) - public void testNextRemoveWithoutBegin() { - builder.nextRemove(0, (String)null); - } - - @Test(expected=IllegalStateException.class) - public void testNextRemove2WithoutBegin() { - builder.nextRemove(0, Collections.EMPTY_LIST); - } - - @Test(expected=IllegalStateException.class) - public void testNextUpdateWithoutBegin() { - builder.nextUpdate(0); - } - - @Test(expected=IllegalStateException.class) - public void testNextSetWithoutBegin() { - builder.nextSet(0, null); - } - - @Test(expected=IllegalStateException.class) - public void testNextReplaceWithoutBegin() { - builder.nextReplace(0, 1, Collections.EMPTY_LIST); - } - - @Test - public void testEmpty() { - builder.beginChange(); - builder.endChange(); - - observer.check0(); - } - - @Test - public void testToString_Update() { - observableList.removeListener(observer); - observableList.addListener((ListChangeListener.Change change) -> { - assertNotNull(change.toString()); - }); - builder.beginChange(); - - builder.nextUpdate(0); - - builder.endChange(); - } - - @Test - public void testToString_Add() { - observableList.removeListener(observer); - observableList.addListener((ListChangeListener.Change change) -> { - assertNotNull(change.toString()); - }); - builder.beginChange(); - - builder.nextAdd(0, 1); - - builder.endChange(); - } - - @Test - public void testToString_Remove() { - observableList.removeListener(observer); - observableList.addListener((ListChangeListener.Change change) -> { - assertNotNull(change.toString()); - }); - builder.beginChange(); - - builder.nextRemove(0, ""); - - builder.endChange(); - } - - @Test - public void testToString_Composed() { - observableList.removeListener(observer); - observableList.addListener((ListChangeListener.Change change) -> { - assertNotNull(change.toString()); - }); - builder.beginChange(); - - builder.nextUpdate(0); - - builder.nextAdd(0, 3); - - builder.endChange(); - } - - @Test - public void testToString_Permutation() { - observableList.removeListener(observer); - observableList.addListener((ListChangeListener.Change change) -> { - assertNotNull(change.toString()); - }); - builder.beginChange(); - - builder.nextPermutation(0, 2, new int[] {1, 0}); - - builder.endChange(); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/ListChangeBuilderTest.java 2015-08-31 10:24:49.421216552 -0400 @@ -0,0 +1,539 @@ +/* + * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import test.javafx.collections.MockListObserver; +import com.sun.javafx.collections.ObservableListWrapper; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import javafx.collections.ListChangeBuilderShim; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableListWrapperShim; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +public class ListChangeBuilderTest { + + private ListChangeBuilderShim builder; + private ObservableListWrapperShim observableList; + private ArrayList list; + private MockListObserver observer; + + @Before + public void setUp() { + observer = new MockListObserver(); + list = new ArrayList(Arrays.asList("a", "b", "c", "d")); + observableList = new ObservableListWrapperShim(list); + observableList.addListener(observer); + builder = new ListChangeBuilderShim(observableList); + } + + @Test + public void testAddRemove() { + builder.beginChange(); + list.remove(2); + builder.nextRemove(2, "c"); + list.add(2, "cc"); + list.add(3, "ccc"); + builder.nextAdd(2, 4); + list.remove(2); + builder.nextRemove(2, "cc"); + list.remove(3); + builder.nextRemove(3, "d"); + list.add(0, "aa"); + builder.nextAdd(0, 1); + builder.endChange(); + + assertEquals(list, Arrays.asList("aa", "a", "b", "ccc")); + + observer.checkAddRemove(0, observableList, Collections.EMPTY_LIST, 0, 1); + observer.checkAddRemove(1, observableList, Arrays.asList("c", "d"), 3, 4); + } + + @Test + public void testAddRemove_2() { + builder.beginChange(); + list.add("e"); + builder.nextAdd(4, 5); + list.add(3, "dd"); + builder.nextAdd(3, 4); + list.remove(4); + builder.nextRemove(4, "d"); + + list.remove(0); + builder.nextRemove(0, "a"); + builder.endChange(); + + assertEquals(list, Arrays.asList("b", "c", "dd", "e")); + + observer.checkAddRemove(0, observableList, Arrays.asList("a"), 0, 0); + observer.checkAddRemove(1, observableList, Arrays.asList("d"), 2, 4); + } + + @Test + public void testAddRemove_3() { + builder.beginChange(); + list.add("e"); + builder.nextAdd(4, 5); + + list.set(0, "aa"); + builder.nextReplace(0, 1, Arrays.asList("a")); + + list.remove(4); + builder.nextRemove(4, "e"); + + list.remove(0); + builder.nextRemove(0, "aa"); + builder.endChange(); + + assertEquals(list, Arrays.asList("b", "c", "d")); + + observer.check1AddRemove(observableList, Arrays.asList("a"), 0, 0); + + } + + @Test + public void testAddRemove_4() { + builder.beginChange(); + + list.add("e"); + builder.nextAdd(4, 5); + + list.remove(1); + builder.nextRemove(1, "b"); + + list.add(1, "bb"); + builder.nextAdd(1, 2); + + builder.endChange(); + + assertEquals(list, Arrays.asList("a", "bb", "c", "d", "e")); + + observer.checkAddRemove(0, observableList, Arrays.asList("b"), 1, 2); + observer.checkAddRemove(1, observableList, Collections.EMPTY_LIST, 4, 5); + } + + //RT-37089 + @Test + public void testAddRemove_5() { + builder.beginChange(); + + list.addAll(1, Arrays.asList("x", "y")); + builder.nextAdd(1, 3); + + list.remove(2); + builder.nextRemove(2, "y"); + + builder.endChange(); + + observer.check1AddRemove(observableList, Collections.EMPTY_LIST, 1, 2); + + } + + @Test + public void testAdd() { + builder.beginChange(); + + list.add(1, "aa"); + builder.nextAdd(1, 2); + list.add(5, "e"); + builder.nextAdd(5, 6); + list.add(1, "aa"); + builder.nextAdd(1, 2); + list.add(2, "aa"); + builder.nextAdd(2, 3); + list.add(4, "aa"); + builder.nextAdd(4, 5); + + builder.endChange(); + + assertEquals(list, Arrays.asList("a", "aa","aa","aa","aa", "b", "c", "d", "e")); + + observer.checkAddRemove(0, observableList, Collections.EMPTY_LIST, 1, 5); + observer.checkAddRemove(1, observableList, Collections.EMPTY_LIST, 8, 9); + + } + + @Test + public void testRemove() { + builder.beginChange(); + list.remove(0); + builder.nextRemove(0, "a"); + list.remove(2); + builder.nextRemove(2, "d"); + list.remove(0); + builder.nextRemove(0, "b"); + builder.endChange(); + + assertEquals(list, Arrays.asList("c")); + + observer.checkAddRemove(0, observableList, Arrays.asList("a", "b"), 0, 0); + observer.checkAddRemove(1, observableList, Arrays.asList("d"), 1, 1); + + } + + @Test + public void testRemove_2() { + builder.beginChange(); + list.remove(1); + builder.nextRemove(1, "b"); + list.remove(2); + builder.nextRemove(2, "d"); + list.remove(0); + builder.nextRemove(0, "a"); + builder.endChange(); + + assertEquals(list, Arrays.asList("c")); + + observer.checkAddRemove(0, observableList, Arrays.asList("a", "b"), 0, 0); + observer.checkAddRemove(1, observableList, Arrays.asList("d"), 1, 1); + + } + + @Test + public void testUpdate() { + builder.beginChange(); + builder.nextUpdate(1); + builder.nextUpdate(0); + builder.nextUpdate(3); + builder.endChange(); + + observer.checkUpdate(0, observableList, 0, 2); + observer.checkUpdate(1, observableList, 3, 4); + } + + @Test + public void testUpdate_2() { + builder.beginChange(); + builder.nextUpdate(3); + builder.nextUpdate(1); + builder.nextUpdate(0); + builder.nextUpdate(0); + builder.nextUpdate(2); + builder.endChange(); + + observer.checkUpdate(0, observableList, 0, 4); + } + + @Test + public void testPermutation() { + builder.beginChange(); + + builder.nextPermutation(0, 4, new int[] {3, 2, 1, 0}); + builder.nextPermutation(1, 4, new int[] {3, 2, 1}); + builder.endChange(); + + observer.check1Permutation(observableList, new int[] {1, 2, 3, 0}); + } + + @Test + public void testUpdateAndAddRemove() { + builder.beginChange(); + builder.nextUpdate(1); + builder.nextUpdate(2); + list.remove(2); + builder.nextRemove(2, "c"); + list.add(2, "cc"); + list.add(3, "ccc"); + builder.nextAdd(2, 4); + builder.nextUpdate(2); + list.remove(2); + builder.nextRemove(2, "cc"); + list.remove(3); + builder.nextRemove(3, "d"); + list.add(0, "aa"); + builder.nextAdd(0, 1); + builder.endChange(); + + assertEquals(list, Arrays.asList("aa", "a", "b", "ccc")); + + observer.checkAddRemove(0, observableList, Collections.EMPTY_LIST, 0, 1); + observer.checkAddRemove(1, observableList, Arrays.asList("c", "d"), 3, 4); + observer.checkUpdate(2, observableList, 2, 3); + } + + @Test + public void testUpdateAndAddRemove_2() { + builder.beginChange(); + builder.nextUpdate(0); + builder.nextUpdate(1); + list.add(1,"aaa"); + list.add(1,"aa"); + builder.nextAdd(1, 3); + builder.endChange(); + + assertEquals(list, Arrays.asList("a", "aa", "aaa", "b", "c", "d")); + + observer.checkAddRemove(0, observableList, Collections.EMPTY_LIST, 1, 3); + observer.checkUpdate(1, observableList, 0, 1); + observer.checkUpdate(2, observableList, 3, 4); + } + + @Test + public void testUpdateAndAddRemove_3() { + builder.beginChange(); + builder.nextUpdate(2); + builder.nextUpdate(3); + list.add(1,"aa"); + builder.nextAdd(1, 2); + list.remove(0); + builder.nextRemove(0, "a"); + builder.endChange(); + + assertEquals(list, Arrays.asList("aa", "b", "c", "d")); + + observer.checkAddRemove(0, observableList, Arrays.asList("a"), 0, 1); + observer.checkUpdate(1, observableList, 2, 4); + } + + @Test + public void testUpdateAndPermutation() { + builder.beginChange(); + + builder.nextUpdate(1); + builder.nextUpdate(2); + builder.nextPermutation(1, 4, new int[] {3, 2, 1}); + builder.endChange(); + + observer.checkPermutation(0, observableList, 1, 4, new int[] {3, 2, 1}); + observer.checkUpdate(1, observableList, 2, 4); + } + + @Test + public void testUpdateAndPermutation_2() { + builder.beginChange(); + + builder.nextUpdate(0); + builder.nextUpdate(2); + builder.nextPermutation(0, 4, new int[] {1, 3, 2, 0}); + builder.endChange(); + + observer.checkPermutation(0, observableList, 0, 4, new int[] {1, 3, 2, 0}); + observer.checkUpdate(1, observableList, 1, 3); + } + + @Test + public void testAddAndPermutation() { + builder.beginChange(); + + builder.nextAdd(1, 2); // as-if "b" was added + builder.nextPermutation(0, 3, new int[] { 2, 0, 1}); // new order is "b", "c", "a", "d" + + builder.endChange(); + // "c", "a", "d" before "b" was added + observer.checkPermutation(0, observableList, 0, 3, new int[] {1, 0, 2}); + + observer.checkAddRemove(1, observableList, Collections.EMPTY_LIST, 0, 1); + } + + @Test + public void testRemoveAndPermutation() { + builder.beginChange(); + + List removed = Arrays.asList("bb", "bbb"); + + builder.nextRemove(2, removed); + builder.nextPermutation(0, 3, new int[] {2, 0, 1}); + + builder.endChange(); + + observer.checkPermutation(0, observableList, 0, 6, new int[] {4, 0, 2, 3, 1, 5}); + observer.checkAddRemove(1, observableList, removed, 1, 1); + + } + + @Test + public void testAddRemoveAndPermutation() { + builder.beginChange(); + + // Expect list to be "b", "c1", "c2", "d" + List removed = Arrays.asList("c1", "c2"); + // After add: "a", "b", "c1", "c2", "d" + builder.nextAdd(0, 1); + // After replace "a", "b", "c", "d" + builder.nextReplace(2, 3, removed); + builder.nextPermutation(1, 4, new int[] {3, 1, 2}); + + builder.endChange(); + + observer.checkPermutation(0, observableList, 0, 4, new int[] {3, 1, 2, 0}); + observer.checkAddRemove(1, observableList, removed, 0, 2); + } + + @Test + public void testPermutationAndAddRemove() { + builder.beginChange(); + + // Expect list to be "b", "c1", "c2", "d" + // After perm "b", "c2", "d", "c1" + builder.nextPermutation(1, 4, new int[] {3, 1, 2}); + // After add: "a", "b", "c2", "d", "c1" + builder.nextAdd(0, 1); + builder.nextReplace(2, 3, Arrays.asList("c2")); + builder.nextRemove(4, Arrays.asList("c1")); + + builder.endChange(); + + observer.checkPermutation(0, observableList, 1, 4, new int[] {3, 1, 2}); + observer.checkAddRemove(1, observableList, Collections.EMPTY_LIST, 0, 1); + observer.checkAddRemove(2, observableList, Arrays.asList("c2"), 2, 3); + observer.checkAddRemove(3, observableList, Arrays.asList("c1"), 4, 4); + } + + @Test + public void testPermutationAddRemoveAndPermutation() { + + builder.beginChange(); + // Expect list to be "b", "c1", "d" + List removed = Arrays.asList("c1"); + // After perm: "c1", "b", "d" + builder.nextPermutation(0, 2, new int[] { 1, 0 }); + // After add: "a", "c1", "b", "d" + builder.nextAdd(0, 1); + // After remove/add "a", "b", "c", "d" + builder.nextRemove(1, removed); + builder.nextAdd(2, 3); + // After permutation "a", "c", "d", "b" + builder.nextPermutation(1, 4, new int[] {3, 1, 2}); + + builder.endChange(); + + // When combined, it's from the expected list: + // permutation to "c1", "d", "b" + observer.checkPermutation(0, observableList, 0, 3, new int[] {2, 0, 1}); + // add remove to "a", "c", "d", "b" + observer.checkAddRemove(1, observableList, removed, 0, 2); + } + + @Test(expected=IllegalStateException.class) + public void testNextAddWithoutBegin() { + builder.nextAdd(0, 1); + } + + @Test(expected=IllegalStateException.class) + public void testNextRemoveWithoutBegin() { + builder.nextRemove(0, (String)null); + } + + @Test(expected=IllegalStateException.class) + public void testNextRemove2WithoutBegin() { + builder.nextRemove(0, Collections.EMPTY_LIST); + } + + @Test(expected=IllegalStateException.class) + public void testNextUpdateWithoutBegin() { + builder.nextUpdate(0); + } + + @Test(expected=IllegalStateException.class) + public void testNextSetWithoutBegin() { + builder.nextSet(0, null); + } + + @Test(expected=IllegalStateException.class) + public void testNextReplaceWithoutBegin() { + builder.nextReplace(0, 1, Collections.EMPTY_LIST); + } + + @Test + public void testEmpty() { + builder.beginChange(); + builder.endChange(); + + observer.check0(); + } + + @Test + public void testToString_Update() { + observableList.removeListener(observer); + observableList.addListener((ListChangeListener.Change change) -> { + assertNotNull(change.toString()); + }); + builder.beginChange(); + + builder.nextUpdate(0); + + builder.endChange(); + } + + @Test + public void testToString_Add() { + observableList.removeListener(observer); + observableList.addListener((ListChangeListener.Change change) -> { + assertNotNull(change.toString()); + }); + builder.beginChange(); + + builder.nextAdd(0, 1); + + builder.endChange(); + } + + @Test + public void testToString_Remove() { + observableList.removeListener(observer); + observableList.addListener((ListChangeListener.Change change) -> { + assertNotNull(change.toString()); + }); + builder.beginChange(); + + builder.nextRemove(0, ""); + + builder.endChange(); + } + + @Test + public void testToString_Composed() { + observableList.removeListener(observer); + observableList.addListener((ListChangeListener.Change change) -> { + assertNotNull(change.toString()); + }); + builder.beginChange(); + + builder.nextUpdate(0); + + builder.nextAdd(0, 3); + + builder.endChange(); + } + + @Test + public void testToString_Permutation() { + observableList.removeListener(observer); + observableList.addListener((ListChangeListener.Change change) -> { + assertNotNull(change.toString()); + }); + builder.beginChange(); + + builder.nextPermutation(0, 2, new int[] {1, 0}); + + builder.endChange(); + } + +} --- old/modules/base/src/test/java/javafx/collections/MockArrayObserver.java 2015-08-31 10:24:50.169216544 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import static org.junit.Assert.*; - -/** - * A mock observer that tracks calls to its onChanged() method, - * combined with utility methods to make assertions on the calls made. - * - */ -public class MockArrayObserver> implements ArrayChangeListener { - private boolean tooManyCalls; - - static class Call { - T array; - boolean sizeChanged; - int from; - int to; - - @Override - public String toString() { - return "sizeChanged: " + sizeChanged + ", from: " + from + ", to: " + to; - } - } - - Call call; - - @Override - public void onChanged(T observableArray, boolean sizeChanged, int from, int to) { - if (call == null) { - call = new Call(); - call.array = observableArray; - call.sizeChanged = sizeChanged; - call.from = from; - call.to = to; - - // Check generic change assertions - assertFalse("Negative from index", from < 0); - assertFalse("Negative to index", to < 0); - assertFalse("from index is greater then to index", from > to); - assertFalse("No change in both elements and size", from == to && sizeChanged == false); - assertFalse("from index is greater than array size", from < to && from >= observableArray.size()); - assertFalse("to index is greater than array size", from < to && to > observableArray.size()); - } else { - tooManyCalls = true; - } - } - - public void check0() { - assertNull(call); - } - - public void checkOnlySizeChanged(T array) { - assertFalse("Too many array change events", tooManyCalls); - assertSame(array, call.array); - assertEquals(true, call.sizeChanged); - } - - public void checkOnlyElementsChanged(T array, - int from, - int to) { - assertFalse("Too many array change events", tooManyCalls); - assertSame(array, call.array); - assertEquals(false, call.sizeChanged); - assertEquals(from, call.from); - assertEquals(to, call.to); - } - - public void check(T array, - boolean sizeChanged, - int from, - int to) { - assertFalse("Too many array change events", tooManyCalls); - assertSame(array, call.array); - assertEquals(sizeChanged, call.sizeChanged); - assertEquals(from, call.from); - assertEquals(to, call.to); - } - - public void check1() { - assertFalse("Too many array change events", tooManyCalls); - assertNotNull(call); - } - - public void reset() { - call = null; - tooManyCalls = false; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/MockArrayObserver.java 2015-08-31 10:24:50.033216546 -0400 @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import javafx.collections.ArrayChangeListener; +import javafx.collections.ObservableArray; +import static org.junit.Assert.*; + +/** + * A mock observer that tracks calls to its onChanged() method, + * combined with utility methods to make assertions on the calls made. + * + */ +public class MockArrayObserver> implements ArrayChangeListener { + private boolean tooManyCalls; + + static class Call { + T array; + boolean sizeChanged; + int from; + int to; + + @Override + public String toString() { + return "sizeChanged: " + sizeChanged + ", from: " + from + ", to: " + to; + } + } + + Call call; + + @Override + public void onChanged(T observableArray, boolean sizeChanged, int from, int to) { + if (call == null) { + call = new Call(); + call.array = observableArray; + call.sizeChanged = sizeChanged; + call.from = from; + call.to = to; + + // Check generic change assertions + assertFalse("Negative from index", from < 0); + assertFalse("Negative to index", to < 0); + assertFalse("from index is greater then to index", from > to); + assertFalse("No change in both elements and size", from == to && sizeChanged == false); + assertFalse("from index is greater than array size", from < to && from >= observableArray.size()); + assertFalse("to index is greater than array size", from < to && to > observableArray.size()); + } else { + tooManyCalls = true; + } + } + + public void check0() { + assertNull(call); + } + + public void checkOnlySizeChanged(T array) { + assertFalse("Too many array change events", tooManyCalls); + assertSame(array, call.array); + assertEquals(true, call.sizeChanged); + } + + public void checkOnlyElementsChanged(T array, + int from, + int to) { + assertFalse("Too many array change events", tooManyCalls); + assertSame(array, call.array); + assertEquals(false, call.sizeChanged); + assertEquals(from, call.from); + assertEquals(to, call.to); + } + + public void check(T array, + boolean sizeChanged, + int from, + int to) { + assertFalse("Too many array change events", tooManyCalls); + assertSame(array, call.array); + assertEquals(sizeChanged, call.sizeChanged); + assertEquals(from, call.from); + assertEquals(to, call.to); + } + + public void check1() { + assertFalse("Too many array change events", tooManyCalls); + assertNotNull(call); + } + + public void reset() { + call = null; + tooManyCalls = false; + } +} --- old/modules/base/src/test/java/javafx/collections/MockListObserver.java 2015-08-31 10:24:50.845216536 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import static org.junit.Assert.* ; - -/** - * A mock observer that tracks calls to its onChanged() method, - * combined with utility methods to make assertions on the calls made. - * - */ -public class MockListObserver implements ListChangeListener { - private boolean tooManyCalls; - - static class Call { - ObservableList list; - List removed; - int from; - int to; - private int[] permutation; - private boolean update; - @Override - public String toString() { - return "removed: " + removed + ", from: " + from + ", to: " + to + ", permutation: " + Arrays.toString(permutation); - } - } - - List> calls = new LinkedList>(); - - @Override - public void onChanged(Change change) { - if (calls.isEmpty()) { - while (change.next()) { - Call call = new Call(); - call.list = change.getList(); - call.removed = change.getRemoved(); - call.from = change.getFrom(); - call.to = change.getTo(); - if (change.wasPermutated()) { - call.permutation = new int[call.to - call.from]; - for (int i = 0; i < call.permutation.length; ++i) { - call.permutation[i] = change.getPermutation(i + call.from); - } - } else { - call.permutation = new int[0]; - } - call.update = change.wasUpdated(); - calls.add(call); - - // Check generic change assertions - assertFalse(change.wasPermutated() && change.wasUpdated()); - assertFalse((change.wasAdded() || change.wasRemoved()) && change.wasUpdated()); - assertFalse((change.wasAdded() || change.wasRemoved()) && change.wasPermutated()); - } - } else { - tooManyCalls = true; - } - } - - public void check0() { - assertEquals(0, calls.size()); - } - - public void check1AddRemove(ObservableList list, - List removed, - int from, - int to) { - assertFalse(tooManyCalls); - assertEquals(1, calls.size()); - checkAddRemove(0, list, removed, from, to); - } - - public void checkAddRemove(int idx, ObservableList list, - List removed, - int from, - int to) { - if (removed == null) { - removed = Collections.emptyList(); - } - assertFalse(tooManyCalls); - Call call = calls.get(idx); - assertSame(call.list, list); - assertEquals(call.removed, removed); - assertEquals(call.from, from); - assertEquals(call.to, to); - assertEquals(call.permutation.length, 0); - } - - public void check1Permutation(ObservableList list, int[] perm) { - assertFalse(tooManyCalls); - assertEquals(1, calls.size()); - checkPermutation(0, list, 0, list.size(), perm); - } - - public void check1Permutation(ObservableList list, int from, int to, int[] perm) { - assertFalse(tooManyCalls); - assertEquals(1, calls.size()); - checkPermutation(0, list, from, to, perm); - } - - public void checkPermutation(int idx, ObservableList list, int from, int to, int[] perm) { - assertFalse(tooManyCalls); - Call call = calls.get(idx); - assertEquals(list, call.list); - assertEquals(Collections.EMPTY_LIST, call.removed); - assertEquals(from, call.from); - assertEquals(to, call.to); - assertArrayEquals(perm, call.permutation); - } - - public void check1Update(ObservableList list, int from, int to) { - assertFalse(tooManyCalls); - assertEquals(1, calls.size()); - checkUpdate(0, list, from, to); - } - - public void checkUpdate(int idx, ObservableList list, int from, int to) { - assertFalse(tooManyCalls); - Call call = calls.get(idx); - assertEquals(list, call.list); - assertEquals(Collections.EMPTY_LIST, call.removed); - assertArrayEquals(new int[0], call.permutation); - assertEquals(true, call.update); - assertEquals(from, call.from); - assertEquals(to, call.to); - } - - public void check1() { - assertFalse(tooManyCalls); - assertEquals(1, calls.size()); - } - - public void clear() { - calls.clear(); - tooManyCalls = false; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/MockListObserver.java 2015-08-31 10:24:50.709216538 -0400 @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import static org.junit.Assert.* ; + +/** + * A mock observer that tracks calls to its onChanged() method, + * combined with utility methods to make assertions on the calls made. + * + */ +public class MockListObserver implements ListChangeListener { + private boolean tooManyCalls; + + static class Call { + ObservableList list; + List removed; + int from; + int to; + private int[] permutation; + private boolean update; + @Override + public String toString() { + return "removed: " + removed + ", from: " + from + ", to: " + to + ", permutation: " + Arrays.toString(permutation); + } + } + + List> calls = new LinkedList>(); + + @Override + public void onChanged(Change change) { + if (calls.isEmpty()) { + while (change.next()) { + Call call = new Call(); + call.list = change.getList(); + call.removed = change.getRemoved(); + call.from = change.getFrom(); + call.to = change.getTo(); + if (change.wasPermutated()) { + call.permutation = new int[call.to - call.from]; + for (int i = 0; i < call.permutation.length; ++i) { + call.permutation[i] = change.getPermutation(i + call.from); + } + } else { + call.permutation = new int[0]; + } + call.update = change.wasUpdated(); + calls.add(call); + + // Check generic change assertions + assertFalse(change.wasPermutated() && change.wasUpdated()); + assertFalse((change.wasAdded() || change.wasRemoved()) && change.wasUpdated()); + assertFalse((change.wasAdded() || change.wasRemoved()) && change.wasPermutated()); + } + } else { + tooManyCalls = true; + } + } + + public void check0() { + assertEquals(0, calls.size()); + } + + public void check1AddRemove(ObservableList list, + List removed, + int from, + int to) { + assertFalse(tooManyCalls); + assertEquals(1, calls.size()); + checkAddRemove(0, list, removed, from, to); + } + + public void checkAddRemove(int idx, ObservableList list, + List removed, + int from, + int to) { + if (removed == null) { + removed = Collections.emptyList(); + } + assertFalse(tooManyCalls); + Call call = calls.get(idx); + assertSame(call.list, list); + assertEquals(call.removed, removed); + assertEquals(call.from, from); + assertEquals(call.to, to); + assertEquals(call.permutation.length, 0); + } + + public void check1Permutation(ObservableList list, int[] perm) { + assertFalse(tooManyCalls); + assertEquals(1, calls.size()); + checkPermutation(0, list, 0, list.size(), perm); + } + + public void check1Permutation(ObservableList list, int from, int to, int[] perm) { + assertFalse(tooManyCalls); + assertEquals(1, calls.size()); + checkPermutation(0, list, from, to, perm); + } + + public void checkPermutation(int idx, ObservableList list, int from, int to, int[] perm) { + assertFalse(tooManyCalls); + Call call = calls.get(idx); + assertEquals(list, call.list); + assertEquals(Collections.EMPTY_LIST, call.removed); + assertEquals(from, call.from); + assertEquals(to, call.to); + assertArrayEquals(perm, call.permutation); + } + + public void check1Update(ObservableList list, int from, int to) { + assertFalse(tooManyCalls); + assertEquals(1, calls.size()); + checkUpdate(0, list, from, to); + } + + public void checkUpdate(int idx, ObservableList list, int from, int to) { + assertFalse(tooManyCalls); + Call call = calls.get(idx); + assertEquals(list, call.list); + assertEquals(Collections.EMPTY_LIST, call.removed); + assertArrayEquals(new int[0], call.permutation); + assertEquals(true, call.update); + assertEquals(from, call.from); + assertEquals(to, call.to); + } + + public void check1() { + assertFalse(tooManyCalls); + assertEquals(1, calls.size()); + } + + public void clear() { + calls.clear(); + tooManyCalls = false; + } +} --- old/modules/base/src/test/java/javafx/collections/MockMapObserver.java 2015-08-31 10:24:51.505216529 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import java.util.Arrays; -import java.util.ArrayList; -import java.util.List; -import static org.junit.Assert.*; - -public class MockMapObserver implements MapChangeListener { - - private List calls = new ArrayList(); - - @Override - public void onChanged(Change c) { - calls.add(new Call(c.getKey(), c.getValueRemoved(), c.getValueAdded())); - } - - public int getCallsNumber() { - return calls.size(); - } - - public void clear() { - calls.clear(); - } - - public void check0() { - assertEquals(0, calls.size()); - } - - public void assertAdded(Tuple tuple) { - assertAdded(0, tuple); - } - - public void assertAdded(int call, Tuple tuple) { - assertTrue("Missing call to the observer # " + call, call < calls.size()); - assertEquals(calls.get(call).key, tuple.key); - assertEquals(calls.get(call).added, tuple.val); - } - - public void assertMultipleCalls(Call... calls) { - assertEquals(this.calls.size(), calls.length); - for (Call c : calls) { - assertTrue(Arrays.toString(calls) + " doesn't contain " + c, this.calls.contains(c)); - } - } - - public void assertMultipleRemove(Tuple... tuples) { - assertEquals(this.calls.size(), tuples.length); - for (Tuple t : tuples) { - assertTrue(calls + " doesn't contain " + t, this.calls.contains(new Call(t.key, t.val, null))); - } - } - - public void assertRemoved(Tuple tuple) { - assertRemoved(0, tuple); - } - - public void assertRemoved(int call, Tuple tuple) { - assertTrue("Missing call to the observer # " + call, call < calls.size()); - assertEquals(calls.get(call).key, tuple.key); - assertEquals(calls.get(call).removed, tuple.val); - } - - public void assertMultipleRemoved(Tuple... tuples) { - for (Tuple t : tuples) { - boolean found = false; - for (Call c : calls ) { - if (c.key.equals(t.key)) { - assertEquals(c.removed, t.val); - found = true; - break; - } - } - assertTrue(found); - } - } - - public static class Call { - private K key; - private V removed; - private V added; - - public Call(K key, V removed, V added) { - this.key = key; - this.removed = removed; - this.added = added; - } - - public static Call call(K k, V o, V n) { - return new Call(k, o, n); - } - - @Override - @SuppressWarnings("unchecked") - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final Call other = (Call) obj; - if (this.key != other.key && (this.key == null || !this.key.equals(other.key))) { - return false; - } - if (this.removed != other.removed && (this.removed == null || !this.removed.equals(other.removed))) { - return false; - } - if (this.added != other.added && (this.added == null || !this.added.equals(other.added))) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int hash = 7; - hash = 47 * hash + (this.key != null ? this.key.hashCode() : 0); - hash = 47 * hash + (this.removed != null ? this.removed.hashCode() : 0); - hash = 47 * hash + (this.added != null ? this.added.hashCode() : 0); - return hash; - } - - @Override - public String toString() { - return "[ " + key + " -> " + added + " (" + removed + ") ]"; - } - - } - - public static class Tuple { - public K key; - public V val; - - private Tuple(K key, V val) { - this.key = key; - this.val = val; - } - - public static Tuple tup(K k, V v) { - return new Tuple(k, v); - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/MockMapObserver.java 2015-08-31 10:24:51.369216531 -0400 @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; +import javafx.collections.MapChangeListener; +import static org.junit.Assert.*; + +public class MockMapObserver implements MapChangeListener { + + private List calls = new ArrayList(); + + @Override + public void onChanged(Change c) { + calls.add(new Call(c.getKey(), c.getValueRemoved(), c.getValueAdded())); + } + + public int getCallsNumber() { + return calls.size(); + } + + public void clear() { + calls.clear(); + } + + public void check0() { + assertEquals(0, calls.size()); + } + + public void assertAdded(Tuple tuple) { + assertAdded(0, tuple); + } + + public void assertAdded(int call, Tuple tuple) { + assertTrue("Missing call to the observer # " + call, call < calls.size()); + assertEquals(calls.get(call).key, tuple.key); + assertEquals(calls.get(call).added, tuple.val); + } + + public void assertMultipleCalls(Call... calls) { + assertEquals(this.calls.size(), calls.length); + for (Call c : calls) { + assertTrue(Arrays.toString(calls) + " doesn't contain " + c, this.calls.contains(c)); + } + } + + public void assertMultipleRemove(Tuple... tuples) { + assertEquals(this.calls.size(), tuples.length); + for (Tuple t : tuples) { + assertTrue(calls + " doesn't contain " + t, this.calls.contains(new Call(t.key, t.val, null))); + } + } + + public void assertRemoved(Tuple tuple) { + assertRemoved(0, tuple); + } + + public void assertRemoved(int call, Tuple tuple) { + assertTrue("Missing call to the observer # " + call, call < calls.size()); + assertEquals(calls.get(call).key, tuple.key); + assertEquals(calls.get(call).removed, tuple.val); + } + + public void assertMultipleRemoved(Tuple... tuples) { + for (Tuple t : tuples) { + boolean found = false; + for (Call c : calls ) { + if (c.key.equals(t.key)) { + assertEquals(c.removed, t.val); + found = true; + break; + } + } + assertTrue(found); + } + } + + public static class Call { + private K key; + private V removed; + private V added; + + public Call(K key, V removed, V added) { + this.key = key; + this.removed = removed; + this.added = added; + } + + public static Call call(K k, V o, V n) { + return new Call(k, o, n); + } + + @Override + @SuppressWarnings("unchecked") + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Call other = (Call) obj; + if (this.key != other.key && (this.key == null || !this.key.equals(other.key))) { + return false; + } + if (this.removed != other.removed && (this.removed == null || !this.removed.equals(other.removed))) { + return false; + } + if (this.added != other.added && (this.added == null || !this.added.equals(other.added))) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 47 * hash + (this.key != null ? this.key.hashCode() : 0); + hash = 47 * hash + (this.removed != null ? this.removed.hashCode() : 0); + hash = 47 * hash + (this.added != null ? this.added.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + return "[ " + key + " -> " + added + " (" + removed + ") ]"; + } + + } + + public static class Tuple { + public K key; + public V val; + + private Tuple(K key, V val) { + this.key = key; + this.val = val; + } + + public static Tuple tup(K k, V v) { + return new Tuple(k, v); + } + } + +} --- old/modules/base/src/test/java/javafx/collections/MockSetObserver.java 2015-08-31 10:24:52.237216521 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class MockSetObserver implements SetChangeListener { - - private List calls = new ArrayList(); - - @Override - public void onChanged(Change c) { - calls.add(new Call(c.getElementRemoved(), c.getElementAdded())); - } - - public int getCallsNumber() { - return calls.size(); - } - - public void clear() { - calls.clear(); - } - - public void check0() { - assertEquals(0, calls.size()); - } - - public void assertAdded(Tuple tuple) { - assertAdded(0, tuple); - } - - public void assertAdded(int call, Tuple tuple) { - assertTrue("Missing call to the observer # " + call, call < calls.size()); - assertEquals(calls.get(call).added, tuple.val); - } - - public void assertMultipleCalls(Call... calls) { - assertEquals(this.calls.size(), calls.length); - for (Call c : calls) { - assertTrue(Arrays.toString(calls) + " doesn't contain " + c, this.calls.contains(c)); - } - } - - public void assertMultipleRemove(Tuple... tuples) { - assertEquals(this.calls.size(), tuples.length); - for (Tuple t : tuples) { - assertTrue(calls + " doesn't contain " + t, this.calls.contains(new Call(t.val, null))); - } - } - - public void assertRemoved(Tuple tuple) { - assertRemoved(0, tuple); - } - - public void assertRemoved(int call, Tuple tuple) { - assertTrue("Missing call to the observer # " + call, call < calls.size()); - assertEquals(calls.get(call).removed, tuple.val); - } - - public void assertMultipleRemoved(Tuple... tuples) { - for (Tuple t : tuples) { - boolean found = false; - for (Call c : calls) { - if (c.removed.equals(t.val)) { - found = true; - break; - } - } - assertTrue(found); - } - } - - public static class Call { - private E removed; - private E added; - - public Call(E removed, E added) { - this.removed = removed; - this.added = added; - } - - public static Call call(E o, E n) { - return new Call(o, n); - } - - @Override - @SuppressWarnings("unchecked") - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final Call other = (Call) obj; - if (this.removed != other.removed && (this.removed == null || !this.removed.equals(other.removed))) { - return false; - } - if (this.added != other.added && (this.added == null || !this.added.equals(other.added))) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int hash = 7; - hash = 47 * hash + (this.removed != null ? this.removed.hashCode() : 0); - hash = 47 * hash + (this.added != null ? this.added.hashCode() : 0); - return hash; - } - - @Override - public String toString() { - return "[ " + added + " (" + removed + ") ]"; - } - - } - - public static class Tuple { - public E val; - - private Tuple(E val) { - this.val = val; - } - - public static Tuple tup(E v) { - return new Tuple(v); - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/MockSetObserver.java 2015-08-31 10:24:52.029216523 -0400 @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javafx.collections.SetChangeListener; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class MockSetObserver implements SetChangeListener { + + private List calls = new ArrayList(); + + @Override + public void onChanged(Change c) { + calls.add(new Call(c.getElementRemoved(), c.getElementAdded())); + } + + public int getCallsNumber() { + return calls.size(); + } + + public void clear() { + calls.clear(); + } + + public void check0() { + assertEquals(0, calls.size()); + } + + public void assertAdded(Tuple tuple) { + assertAdded(0, tuple); + } + + public void assertAdded(int call, Tuple tuple) { + assertTrue("Missing call to the observer # " + call, call < calls.size()); + assertEquals(calls.get(call).added, tuple.val); + } + + public void assertMultipleCalls(Call... calls) { + assertEquals(this.calls.size(), calls.length); + for (Call c : calls) { + assertTrue(Arrays.toString(calls) + " doesn't contain " + c, this.calls.contains(c)); + } + } + + public void assertMultipleRemove(Tuple... tuples) { + assertEquals(this.calls.size(), tuples.length); + for (Tuple t : tuples) { + assertTrue(calls + " doesn't contain " + t, this.calls.contains(new Call(t.val, null))); + } + } + + public void assertRemoved(Tuple tuple) { + assertRemoved(0, tuple); + } + + public void assertRemoved(int call, Tuple tuple) { + assertTrue("Missing call to the observer # " + call, call < calls.size()); + assertEquals(calls.get(call).removed, tuple.val); + } + + public void assertMultipleRemoved(Tuple... tuples) { + for (Tuple t : tuples) { + boolean found = false; + for (Call c : calls) { + if (c.removed.equals(t.val)) { + found = true; + break; + } + } + assertTrue(found); + } + } + + public static class Call { + private E removed; + private E added; + + public Call(E removed, E added) { + this.removed = removed; + this.added = added; + } + + public static Call call(E o, E n) { + return new Call(o, n); + } + + @Override + @SuppressWarnings("unchecked") + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Call other = (Call) obj; + if (this.removed != other.removed && (this.removed == null || !this.removed.equals(other.removed))) { + return false; + } + if (this.added != other.added && (this.added == null || !this.added.equals(other.added))) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 47 * hash + (this.removed != null ? this.removed.hashCode() : 0); + hash = 47 * hash + (this.added != null ? this.added.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + return "[ " + added + " (" + removed + ") ]"; + } + + } + + public static class Tuple { + public E val; + + private Tuple(E val) { + this.val = val; + } + + public static Tuple tup(E v) { + return new Tuple(v); + } + } + +} --- old/modules/base/src/test/java/javafx/collections/ObservableArrayTest.java 2015-08-31 10:24:52.905216513 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,2701 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import javafx.beans.InvalidationListener; - -import static org.junit.Assert.*; -import org.junit.Ignore; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - * Tests for ObservableArray. - */ -@RunWith(Parameterized.class) -public class ObservableArrayTest { - public static final int INITIAL_SIZE = 6; - - /** - * @param ObservableArray subclass - * @param corresponding primitive array - * @param

corresponding class for boxed elements - */ - public static abstract class ArrayWrapper, A, P> { - - T array; - final T array() { - return array; - } - - abstract T createEmptyArray(); - abstract T createNotEmptyArray(A src); - abstract ArrayWrapper newInstance(); - abstract P getNextValue(); - abstract void set(int index, P value); - abstract void setAllA(A src); - abstract void setAllT(T src); - abstract void setAllA(A src, int srcIndex, int length); - abstract void setAllT(T src, int srcIndex, int length); - abstract void addAllA(A src); - abstract void addAllT(T src); - abstract void addAllA(A src, int srcIndex, int length); - abstract void addAllT(T src, int srcIndex, int length); - abstract void setA(int destIndex, A src, int srcIndex, int length); - abstract void setT(int destIndex, T src, int srcIndex, int length); - abstract void copyToA(int srcIndex, A dest, int destIndex, int length); - abstract void copyToT(int srcIndex, T dest, int destIndex, int length); - abstract P get(int index); - abstract A toArray(A dest); - abstract A toArray(int srcIndex, A dest, int length); - - A createPrimitiveArray(int size) { - return createPrimitiveArray(size, true); - } - abstract A createPrimitiveArray(int size, boolean fillWithData); - abstract A clonePrimitiveArray(A array); - abstract int arrayLength(A array); - abstract P get(A array, int index); - abstract void assertElementsEqual(A actual, int from, int to, A expected, int expFrom); - abstract String primitiveArrayToString(A array); - } - - private static class IntegerArrayWrapper extends ArrayWrapper { - - int nextValue = 0; - - @Override IntegerArrayWrapper newInstance() { - return new IntegerArrayWrapper(); - } - - @Override ObservableIntegerArray createEmptyArray() { - return array = FXCollections.observableIntegerArray(); - } - - @Override ObservableIntegerArray createNotEmptyArray(int[] src) { - return array = FXCollections.observableIntegerArray(src); - } - - @Override Integer getNextValue() { - return nextValue++; - } - - @Override void set(int index, Integer value) { - array.set(index, value); - } - - @Override int[] createPrimitiveArray(int size, boolean fillWithData) { - int[] res = new int[size]; - if (fillWithData) { - for (int i = 0; i < size; i++) { - res[i] = nextValue++; - } - } - return res; - } - - @Override void setAllA(int[] src) { - array.setAll(src); - } - - @Override void setAllA(int[] src, int srcIndex, int length) { - array.setAll(src, srcIndex, length); - } - - @Override void setAllT(ObservableIntegerArray src) { - array.setAll(src); - } - - @Override void setAllT(ObservableIntegerArray src, int srcIndex, int length) { - array.setAll(src, srcIndex, length); - } - - @Override void addAllA(int[] src) { - array.addAll(src); - } - - @Override void addAllA(int[] src, int srcIndex, int length) { - array.addAll(src, srcIndex, length); - } - - @Override void addAllT(ObservableIntegerArray src) { - array.addAll(src); - } - - @Override void addAllT(ObservableIntegerArray src, int srcIndex, int length) { - array.addAll(src, srcIndex, length); - } - - @Override void copyToA(int srcIndex, int[] dest, int destIndex, int length) { - array.copyTo(srcIndex, dest, destIndex, length); - } - - @Override void copyToT(int srcIndex, ObservableIntegerArray dest, int destIndex, int length) { - array.copyTo(srcIndex, dest, destIndex, length); - } - - @Override Integer get(int index) { - return array.get(index); - } - - @Override int[] toArray(int[] src) { - return array.toArray(src); - } - - @Override int[] toArray(int srcIndex, int[] dest, int length) { - return array.toArray(srcIndex, dest, length); - } - - @Override void setA(int destIndex, int[] src, int srcIndex, int length) { - array.set(destIndex, src, srcIndex, length); - } - - @Override void setT(int destIndex, ObservableIntegerArray src, int srcIndex, int length) { - array.set(destIndex, src, srcIndex, length); - } - - @Override int arrayLength(int[] array) { - return array.length; - } - - @Override - Integer get(int[] array, int index) { - return array[index]; - } - - @Override - void assertElementsEqual(int[] actual, int from, int to, int[] expected, int expFrom) { - for(int i = from, j = expFrom; i < to; i++, j++) { - assertEquals(actual[i], expected[j]); - } - } - - @Override int[] clonePrimitiveArray(int[] array) { - return Arrays.copyOf(array, array.length); - } - - @Override - String primitiveArrayToString(int[] array) { - return Arrays.toString(array); - } - } - - private static class FloatArrayWrapper extends ArrayWrapper { - - float nextValue = 0; - - @Override FloatArrayWrapper newInstance() { - return new FloatArrayWrapper(); - } - - @Override ObservableFloatArray createEmptyArray() { - return array = FXCollections.observableFloatArray(); - } - - @Override ObservableFloatArray createNotEmptyArray(float[] elements) { - return array = FXCollections.observableFloatArray(elements); - } - - @Override - Float getNextValue() { - return nextValue++; - } - - @Override void set(int index, Float value) { - array.set(index, value); - } - - @Override float[] createPrimitiveArray(int size, boolean fillWithData) { - float[] res = new float[size]; - if (fillWithData) { - for (int i = 0; i < size; i++) { - res[i] = nextValue++; - } - } - return res; - } - - @Override void setAllA(float[] src) { - array.setAll(src); - } - - @Override void copyToA(int srcIndex, float[] dest, int destIndex, int length) { - array.copyTo(srcIndex, dest, destIndex, length); - } - - @Override void copyToT(int srcIndex, ObservableFloatArray dest, int destIndex, int length) { - array.copyTo(srcIndex, dest, destIndex, length); - } - - @Override Float get(int index) { - return array.get(index); - } - - @Override float[] toArray(float[] dest) { - return array.toArray(dest); - } - - @Override float[] toArray(int srcIndex, float[] dest, int length) { - return array.toArray(srcIndex, dest, length); - } - - @Override void setA(int destIndex, float[] src, int srcIndex, int length) { - array.set(destIndex, src, srcIndex, length); - } - - @Override int arrayLength(float[] array) { - return array.length; - } - - @Override - Float get(float[] array, int index) { - return array[index]; - } - - @Override - void assertElementsEqual(float[] actual, int from, int to, float[] expected, int expFrom) { - for(int i = from, j = expFrom; i < to; i++, j++) { - assertEquals("expected float = " + expected[j] + ", actual float = " + actual[i], - Float.floatToRawIntBits(expected[j]), - Float.floatToRawIntBits(actual[i])); - } - } - - @Override float[] clonePrimitiveArray(float[] array) { - return Arrays.copyOf(array, array.length); - } - - @Override void setAllT(ObservableFloatArray src) { - array.setAll(src); - } - - @Override void setAllA(float[] src, int srcIndex, int length) { - array.setAll(src, srcIndex, length); - } - - @Override void setAllT(ObservableFloatArray src, int srcIndex, int length) { - array.setAll(src, srcIndex, length); - } - - @Override void addAllA(float[] src) { - array.addAll(src); - } - - @Override void addAllT(ObservableFloatArray src) { - array.addAll(src); - } - - @Override void addAllA(float[] src, int srcIndex, int length) { - array.addAll(src, srcIndex, length); - } - - @Override void addAllT(ObservableFloatArray src, int srcIndex, int length) { - array.addAll(src, srcIndex, length); - } - - @Override void setT(int destIndex, ObservableFloatArray src, int srcIndex, int length) { - array.set(destIndex, src, srcIndex, length); - } - - @Override - String primitiveArrayToString(float[] array) { - return Arrays.toString(array); - } - } - - static final List EMPTY = Collections.emptyList(); - final ArrayWrapper wrapper; - private int initialSize; - private Object initialElements; - private ObservableArray array; - private MockArrayObserver mao; - - public ObservableArrayTest(final ArrayWrapper arrayWrapper) { - this.wrapper = arrayWrapper; - } - - @Parameterized.Parameters - public static Collection createParameters() { - Object[][] data = new Object[][] { - { new FloatArrayWrapper() }, - { new IntegerArrayWrapper() }, - }; - return Arrays.asList(data); - } - - @Before - public void setUp() throws Exception { - initialSize = INITIAL_SIZE; - initialElements = wrapper.createPrimitiveArray(initialSize); - array = wrapper.createNotEmptyArray(initialElements); - mao = new MockArrayObserver(); - array.addListener(mao); - } - - private void makeEmpty() { - initialSize = 0; - initialElements = wrapper.createPrimitiveArray(initialSize); - array.clear(); - mao.reset(); - } - - private void assertUnchanged() { - mao.check0(); - assertEquals(initialSize, array.size()); - Object actual = wrapper.toArray(null); - assertEquals(initialSize, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, array.size(), initialElements, 0); - } - - // ========== pre-condition tests ================ - - @Test public void testSize() { - mao.check0(); - assertEquals(INITIAL_SIZE, array.size()); - } - - @Test public void testClear() { - array.clear(); - mao.checkOnlySizeChanged(array); - assertEquals(0, array.size()); - } - - @Test public void testGet() { - for (int i = 0; i < array.size(); i++) { - Object expected = wrapper.get(initialElements, i); - Object actural = wrapper.get(i); - assertEquals(expected, actural); - } - assertUnchanged(); - } - - @Test public void testToArray() { - Object expected = initialElements; - Object actual = wrapper.toArray(null); - assertEquals(INITIAL_SIZE, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, array.size(), expected, 0); - assertUnchanged(); - } - - // ========== add/remove listener tests ========== - - @Test public void testAddRemoveListener() { - MockArrayObserver mao2 = new MockArrayObserver(); - array.addListener(mao2); - array.removeListener(mao); - wrapper.set(0, wrapper.getNextValue()); - mao.check0(); - mao2.check(array, false, 0, 1); - } - - @Test public void testAddTwoListenersElementChange() { - MockArrayObserver mao2 = new MockArrayObserver(); - array.addListener(mao2); - wrapper.set(0, wrapper.getNextValue()); - mao.check(array, false, 0, 1); - mao2.check(array, false, 0, 1); - } - - @Test public void testAddTwoListenersSizeChange() { - MockArrayObserver mao2 = new MockArrayObserver(); - array.addListener(mao2); - array.resize(3); - mao.checkOnlySizeChanged(array); - mao2.checkOnlySizeChanged(array); - } - - @Test public void testAddThreeListeners() { - MockArrayObserver mao2 = new MockArrayObserver(); - MockArrayObserver mao3 = new MockArrayObserver(); - array.addListener(mao2); - array.addListener(mao3); - wrapper.set(0, wrapper.getNextValue()); - mao.check(array, false, 0, 1); - mao2.check(array, false, 0, 1); - mao3.check(array, false, 0, 1); - } - - @Test public void testAddThreeListenersSizeChange() { - MockArrayObserver mao2 = new MockArrayObserver(); - MockArrayObserver mao3 = new MockArrayObserver(); - array.addListener(mao2); - array.addListener(mao3); - array.resize(10); - mao.checkOnlySizeChanged(array); - mao2.checkOnlySizeChanged(array); - mao3.checkOnlySizeChanged(array); - } - - @Test @Ignore - public void testAddListenerTwice() { - array.addListener(mao); // add it a second time - wrapper.set(1, wrapper.getNextValue()); - mao.check(array, false, 1, 2); - } - - @Test public void testRemoveListenerTwice() { - array.removeListener(mao); - array.removeListener(mao); - wrapper.set(1, wrapper.getNextValue()); - mao.check0(); - } - - @Test (expected = NullPointerException.class) - public void testAddNullArrayChangeListener() { - try { - array.addListener((ArrayChangeListener) null); - } finally { - mao.check0(); - array.resize(1); - mao.check1(); - } - } - - @Test (expected = NullPointerException.class) - public void testAddNullInvalidationListener() { - try { - array.addListener((InvalidationListener) null); - } finally { - mao.check0(); - array.resize(1); - mao.check1(); - } - } - - @Test (expected = NullPointerException.class) - public void testRemoveNullArrayChangeListener() { - try { - array.removeListener((ArrayChangeListener) null); - } finally { - mao.check0(); - array.resize(1); - mao.check1(); - } - } - - @Test (expected = NullPointerException.class) - public void testRemoveNullInvalidationListener() { - try { - array.removeListener((InvalidationListener) null); - } finally { - mao.check0(); - array.resize(1); - mao.check1(); - } - } - - // ========== resize tests ========== - - private void testResize(boolean noChange, int newSize, int matchingElements) { - Object expected = wrapper.toArray(null); - array.resize(newSize); - if (noChange) { - assertUnchanged(); - } else { - mao.checkOnlySizeChanged(array); - } - Object actual = wrapper.toArray(null); - assertEquals(newSize, array.size()); - assertEquals(newSize, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, matchingElements, expected, 0); - wrapper.assertElementsEqual(actual, matchingElements, newSize, - wrapper.createPrimitiveArray(Math.max(0, newSize - matchingElements), false), 0); - } - - @Test public void testResizeTo0() { - testResize(false, 0, 0); - } - - @Test public void testResizeToSmaller() { - testResize(false, 3, 3); - } - - @Test public void testResizeToSameSize() { - testResize(true, array.size(), array.size()); - } - - @Test public void testResizeToBigger() { - testResize(false, 10, array.size()); - } - - @Test public void testResizeOnEmpty() { - makeEmpty(); - testResize(false, 10, 0); - } - - @Test public void testResizeOnEmptyToEmpty() { - makeEmpty(); - testResize(true, 0, 0); - } - - @Test (expected = NegativeArraySizeException.class) - public void testResizeToNegative() { - try { - array.resize(-5); - } finally { - assertUnchanged(); - } - } - - // ========== setAll(primitive array) tests ========== - - private void testSetAllA(boolean sizeChanged, int newSize) { - Object expected = wrapper.createPrimitiveArray(newSize); - - wrapper.setAllA(expected); - - mao.check(array, sizeChanged, 0, newSize); - Object actual = wrapper.toArray(null); - assertEquals(wrapper.arrayLength(expected), array.size()); - assertEquals(wrapper.arrayLength(expected), wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, wrapper.arrayLength(expected), expected, 0); - } - - @Test public void testSetAllASmaller() { - testSetAllA(true, 3); - } - - @Test public void testSetAllABigger() { - testSetAllA(true, 10); - } - - @Test public void testSetAllAOnSameSize() { - testSetAllA(false, INITIAL_SIZE); - } - - @Test public void testSetAllAOnEmpty() { - makeEmpty(); - testSetAllA(true, 3); - } - - @Test public void testSetAllAOnEmptyToEmpty() { - makeEmpty(); - wrapper.setAllA(wrapper.createPrimitiveArray(0)); - assertUnchanged(); - assertEquals(0, array.size()); - } - - @Test (expected = NullPointerException.class) - public void testSetAllAToNull() { - try { - wrapper.setAllA(null); - } finally { - assertUnchanged(); - } - } - - // ========== setAll(ObservableArray) tests ========== - - private void testSetAllT(boolean sizeChanged, int newSize) { - ArrayWrapper wrapper2 = wrapper.newInstance(); - Object expected = wrapper.createPrimitiveArray(newSize); - ObservableArray src = wrapper2.createNotEmptyArray(expected); - - wrapper.setAllT(src); - - mao.check(array, sizeChanged, 0, newSize); - Object actual = wrapper.toArray(null); - assertEquals(wrapper.arrayLength(expected), array.size()); - assertEquals(wrapper.arrayLength(expected), wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, wrapper.arrayLength(expected), expected, 0); - } - - @Test public void testSetAllTSmaller() { - testSetAllT(true, 3); - } - - @Test public void testSetAllTBigger() { - testSetAllT(true, 10); - } - - @Test public void testSetAllTOnSameSize() { - testSetAllT(false, INITIAL_SIZE); - } - - @Test public void testSetAllTOnEmpty() { - makeEmpty(); - testSetAllT(true, 3); - } - - @Test public void testSetAllTOnEmptyToEmpty() { - makeEmpty(); - wrapper.setAllT(wrapper.newInstance().createEmptyArray()); - assertUnchanged(); - assertEquals(0, array.size()); - } - - @Test (expected = NullPointerException.class) - public void testSetAllTToNull() { - try { - wrapper.setAllT(null); - } finally { - assertUnchanged(); - } - } - - @Test public void testSetAllTSelf() { - - wrapper.setAllT(array); - - mao.check0(); - Object actual = wrapper.toArray(null); - assertEquals(initialSize, array.size()); - assertEquals(initialSize, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, initialSize, initialElements, 0); - } - - @Test public void testSetAllTSelfEmpty() { - makeEmpty(); - - wrapper.setAllT(array); - - mao.check0(); - Object actual = wrapper.toArray(null); - assertEquals(0, array.size()); - assertEquals(0, wrapper.arrayLength(actual)); - } - - // ========== setAll(primitive array, range) tests ========== - - private void testSetAllARange(boolean sizeChanged, int newSize, int srcIndex, int length) { - Object expected = wrapper.createPrimitiveArray(newSize); - - wrapper.setAllA(expected, srcIndex, length); - - mao.check(array, sizeChanged, 0, length); - Object actual = wrapper.toArray(null); - assertEquals(length, array.size()); - assertEquals(length, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, length, expected, srcIndex); - } - - @Test public void testSetAllARange1() { - testSetAllARange(false, INITIAL_SIZE, 0, INITIAL_SIZE); - } - - @Test public void testSetAllARange2() { - testSetAllARange(false, INITIAL_SIZE + 10, 0, INITIAL_SIZE); - } - - @Test public void testSetAllARange3() { - testSetAllARange(false, INITIAL_SIZE + 10, 10, INITIAL_SIZE); - } - - @Test public void testSetAllARange4() { - testSetAllARange(false, INITIAL_SIZE + 10, 2, INITIAL_SIZE); - } - - @Test public void testSetAllARange5() { - testSetAllARange(true, INITIAL_SIZE, 0, INITIAL_SIZE / 2); - } - - @Test public void testSetAllARange6() { - testSetAllARange(true, INITIAL_SIZE + 10, 0, INITIAL_SIZE + 10); - } - - @Test public void testSetAllARange7() { - testSetAllARange(true, INITIAL_SIZE + 20, 10, INITIAL_SIZE + 10); - } - - @Test public void testSetAllARange8() { - testSetAllARange(true, INITIAL_SIZE + 10, 2, INITIAL_SIZE - 3); - } - - @Test public void testSetAllARangeOnEmpty() { - makeEmpty(); - testSetAllARange(true, INITIAL_SIZE, 1, 3); - } - - @Test public void testSetAllARangeOnEmptyToEmpty() { - makeEmpty(); - wrapper.setAllA(wrapper.createPrimitiveArray(INITIAL_SIZE), 1, 0); - assertUnchanged(); - } - - @Test (expected = NullPointerException.class) - public void testSetAllARangeToNull() { - try { - wrapper.setAllA(null, 0, 0); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllARangeNegative1() { - try { - testSetAllARange(true, INITIAL_SIZE, -1, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllARangeNegative2() { - try { - testSetAllARange(true, INITIAL_SIZE, 0, INITIAL_SIZE + 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllARangeNegative3() { - try { - testSetAllARange(true, INITIAL_SIZE, 1, -1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllARangeNegative4() { - try { - testSetAllARange(true, INITIAL_SIZE, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - // ========== setAll(observable array, range) tests ========== - - private void testSetAllTRange(boolean sizeChanged, int srcSize, int srcIndex, int length) { - Object expected = wrapper.createPrimitiveArray(srcSize); - ObservableArray src = wrapper.newInstance().createNotEmptyArray(expected); - - wrapper.setAllT(src, srcIndex, length); - - mao.check(array, sizeChanged, 0, length); - Object actual = wrapper.toArray(null); - assertEquals(length, array.size()); - assertEquals(length, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, length, expected, srcIndex); - } - - @Test public void testSetAllTRange1() { - testSetAllTRange(false, INITIAL_SIZE, 0, INITIAL_SIZE); - } - - @Test public void testSetAllTRange2() { - testSetAllTRange(false, INITIAL_SIZE + 10, 0, INITIAL_SIZE); - } - - @Test public void testSetAllTRange3() { - testSetAllTRange(false, INITIAL_SIZE + 10, 10, INITIAL_SIZE); - } - - @Test public void testSetAllTRange4() { - testSetAllTRange(false, INITIAL_SIZE + 10, 2, INITIAL_SIZE); - } - - @Test public void testSetAllTRange5() { - testSetAllTRange(true, INITIAL_SIZE, 0, INITIAL_SIZE / 2); - } - - @Test public void testSetAllTRange6() { - testSetAllTRange(true, INITIAL_SIZE + 10, 0, INITIAL_SIZE + 10); - } - - @Test public void testSetAllTRange7() { - testSetAllTRange(true, INITIAL_SIZE + 20, 10, INITIAL_SIZE + 10); - } - - @Test public void testSetAllTRange8() { - testSetAllTRange(true, INITIAL_SIZE + 10, 2, INITIAL_SIZE - 3); - } - - @Test public void testSetAllTRangeOnEmpty() { - makeEmpty(); - testSetAllTRange(true, INITIAL_SIZE, 1, 3); - } - - @Test public void testSetAllTRangeOnEmptyToEmpty() { - makeEmpty(); - wrapper.setAllT(wrapper.newInstance().createNotEmptyArray(wrapper.createPrimitiveArray(INITIAL_SIZE)), 1, 0); - assertUnchanged(); - } - - @Test (expected = NullPointerException.class) - public void testSetAllTRangeToNull() { - try { - wrapper.setAllT(null, 0, 0); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeNegative1() { - try { - testSetAllTRange(true, INITIAL_SIZE, -1, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeNegative2() { - try { - testSetAllTRange(true, INITIAL_SIZE, 0, INITIAL_SIZE + 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeNegative3() { - try { - testSetAllTRange(true, INITIAL_SIZE, 1, -1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeNegative4() { - try { - testSetAllTRange(true, INITIAL_SIZE, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeNegativeAfterSrcEnsureCapacity() { - Object expected = wrapper.createPrimitiveArray(INITIAL_SIZE); - ObservableArray src = wrapper.newInstance().createNotEmptyArray(expected); - src.ensureCapacity(INITIAL_SIZE * 2); - try { - wrapper.setAllT(src, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeNegativeAfterSrcClear() { - Object expected = wrapper.createPrimitiveArray(INITIAL_SIZE); - ObservableArray src = wrapper.newInstance().createNotEmptyArray(expected); - src.clear(); - try { - wrapper.setAllT(src, 0, 1); - } finally { - assertUnchanged(); - } - } - - private void testSetAllTRangeSelf(boolean sizeChanged, int srcIndex, int length) { - - wrapper.setAllT(array, srcIndex, length); - - if (srcIndex == 0) { - if (length == initialSize) { - mao.check0(); - } else { - mao.checkOnlySizeChanged(array); - } - } else { - mao.check(array, sizeChanged, 0, length); - } - Object actual = wrapper.toArray(null); - assertEquals(length, array.size()); - assertEquals(length, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, length, initialElements, srcIndex); - } - - @Test public void testSetAllTRangeSelf() { - testSetAllTRangeSelf(true, 0, INITIAL_SIZE); - } - - @Test public void testSetAllTRangeSelfBeginning() { - testSetAllTRangeSelf(true, 0, INITIAL_SIZE / 2); - } - - @Test public void testSetAllTRangeSelfTrailing() { - testSetAllTRangeSelf(true, INITIAL_SIZE / 2, INITIAL_SIZE / 2); - } - - @Test public void testSetAllTRangeSelfMiddle() { - testSetAllTRangeSelf(true, 3, 2); - } - - @Test public void testSetAllTRangeSelfEmpty() { - makeEmpty(); - testSetAllTRangeSelf(false, 0, 0); - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeSelfNegative1() { - try { - wrapper.setAllT(array, -1, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeSelfNegative2() { - try { - wrapper.setAllT(array, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeSelfNegative3() { - try { - wrapper.setAllT(array, 0, -1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeSelfNegative4() { - try { - wrapper.setAllT(array, 0, INITIAL_SIZE + 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeSelfNegativeAfterEnsureCapacity() { - array.ensureCapacity(INITIAL_SIZE * 2); - try { - wrapper.setAllT(array, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetAllTRangeSelfNegativeAfterClear() { - makeEmpty(); - try { - wrapper.setAllT(array, 0, 1); - } finally { - assertUnchanged(); - } - } - - // ========== addAll(primitive array) tests ========== - - private void testAddAllA(int srcSize) { - Object src = wrapper.createPrimitiveArray(srcSize); - int oldSize = array.size(); - - wrapper.addAllA(src); - - int newSize = oldSize + srcSize; - boolean sizeChanged = newSize != oldSize; - mao.check(array, sizeChanged, oldSize, newSize); - Object actual = wrapper.toArray(null); - assertEquals(newSize, array.size()); - assertEquals(newSize, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, oldSize, initialElements, 0); - wrapper.assertElementsEqual(actual, oldSize, newSize, src, 0); - } - - @Test public void testAddAllA0() { - wrapper.addAllA(wrapper.createPrimitiveArray(0)); - assertUnchanged(); - } - - @Test public void testAddAllA1() { - testAddAllA(1); - } - - @Test public void testAddAllA3() { - testAddAllA(3); - } - - @Test public void testAddAllABig() { - testAddAllA(INITIAL_SIZE * 2); - } - - @Test public void testAddAllASameSize() { - testAddAllA(INITIAL_SIZE); - } - - @Test public void testAddAllAOnEmpty1() { - makeEmpty(); - testAddAllA(1); - } - - @Test public void testAddAllAOnEmptySameSize() { - makeEmpty(); - testAddAllA(INITIAL_SIZE); - } - - @Test public void testAddAllAOnEmptyBig() { - makeEmpty(); - testAddAllA(INITIAL_SIZE * 3); - } - - @Test public void testAddAllAOnEmpty0() { - makeEmpty(); - wrapper.addAllA(wrapper.createPrimitiveArray(0)); - assertUnchanged(); - } - - @Test (expected = NullPointerException.class) - public void testAddAllANull() { - try { - wrapper.addAllA(null); - } finally { - assertUnchanged(); - } - } - - @Test public void testAddAllAManyPoints() { - for (int i = 0; i < 65_000; i++) { - wrapper.addAllA(wrapper.createPrimitiveArray(3)); - } - } - - // ========== addAll(ObservableArray) tests ========== - - private void testAddAllT(int srcSize) { - Object src = wrapper.createPrimitiveArray(srcSize); - int oldSize = array.size(); - - wrapper.addAllT(wrapper.newInstance().createNotEmptyArray(src)); - - int newSize = oldSize + srcSize; - boolean sizeChanged = newSize != oldSize; - mao.check(array, sizeChanged, oldSize, newSize); - Object actual = wrapper.toArray(null); - assertEquals(newSize, array.size()); - assertEquals(newSize, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, oldSize, initialElements, 0); - wrapper.assertElementsEqual(actual, oldSize, newSize, src, 0); - } - - @Test public void testAddAllT0() { - wrapper.addAllT(wrapper.newInstance().createEmptyArray()); - assertUnchanged(); - } - - @Test public void testAddAllT1() { - testAddAllT(1); - } - - @Test public void testAddAllT3() { - testAddAllT(3); - } - - @Test public void testAddAllTBig() { - testAddAllT(INITIAL_SIZE * 2); - } - - @Test public void testAddAllTSameSize() { - testAddAllT(INITIAL_SIZE); - } - - @Test public void testAddAllTOnEmpty1() { - makeEmpty(); - testAddAllT(1); - } - - @Test public void testAddAllTOnEmptySameSize() { - makeEmpty(); - testAddAllT(INITIAL_SIZE); - } - - @Test public void testAddAllTOnEmptyBig() { - makeEmpty(); - testAddAllT(INITIAL_SIZE * 3); - } - - @Test public void testAddAllTOnEmpty0() { - makeEmpty(); - wrapper.addAllT(wrapper.newInstance().createEmptyArray()); - assertUnchanged(); - } - - @Test (expected = NullPointerException.class) - public void testAddAllTNull() { - try { - wrapper.addAllT(null); - } finally { - assertUnchanged(); - } - } - - @Test public void testAddAllTSelf() { - wrapper.addAllT(array); - - mao.check(array, true, initialSize, initialSize * 2); - assertEquals(initialSize * 2, array.size()); - Object actual = wrapper.toArray(null); - wrapper.assertElementsEqual(actual, 0, initialSize, initialElements, 0); - wrapper.assertElementsEqual(actual, initialSize, initialSize * 2, initialElements, 0); - } - - @Test public void testAddAllTSelfEmpty() { - makeEmpty(); - - wrapper.addAllT(array); - - mao.check0(); - Object actual = wrapper.toArray(null); - assertEquals(0, array.size()); - assertEquals(0, wrapper.arrayLength(actual)); - } - - @Test public void testAddAllTManyPoints() { - for (int i = 0; i < 65_000; i++) { - wrapper.addAllT(wrapper.createNotEmptyArray(wrapper.createPrimitiveArray(3))); - } - } - - // ========== addAll(primitive array, range) tests ========== - - private void testAddAllARange(int srcSize, int srcIndex, int length) { - Object src = wrapper.createPrimitiveArray(srcSize); - int oldSize = array.size(); - - wrapper.addAllA(src, srcIndex, length); - - int newSize = oldSize + length; - boolean sizeChanged = newSize != oldSize; - - mao.check(array, sizeChanged, oldSize, newSize); - Object actual = wrapper.toArray(null); - assertEquals(newSize, array.size()); - assertEquals(newSize, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, oldSize, initialElements, 0); - wrapper.assertElementsEqual(actual, oldSize, newSize, src, srcIndex); - } - - @Test public void testAddAllARange1() { - testAddAllARange(INITIAL_SIZE, 0, INITIAL_SIZE); - } - - @Test public void testAddAllARange2() { - testAddAllARange(INITIAL_SIZE + 10, 0, INITIAL_SIZE); - } - - @Test public void testAddAllARange3() { - testAddAllARange(INITIAL_SIZE + 10, 10, INITIAL_SIZE); - } - - @Test public void testAddAllARange4() { - testAddAllARange(INITIAL_SIZE + 10, 2, INITIAL_SIZE); - } - - @Test public void testAddAllARange5() { - testAddAllARange(INITIAL_SIZE, 0, INITIAL_SIZE / 2); - } - - @Test public void testAddAllARange6() { - testAddAllARange(INITIAL_SIZE + 10, 0, INITIAL_SIZE + 10); - } - - @Test public void testAddAllARange7() { - testAddAllARange(INITIAL_SIZE + 20, 10, INITIAL_SIZE + 10); - } - - @Test public void testAddAllARange8() { - testAddAllARange(INITIAL_SIZE + 10, 2, INITIAL_SIZE - 3); - } - - @Test public void testAddAllARangeOnEmpty1() { - makeEmpty(); - testAddAllARange(INITIAL_SIZE, 1, 3); - } - - @Test public void testAddAllARangeOnEmpty2() { - makeEmpty(); - testAddAllARange(INITIAL_SIZE * 3, INITIAL_SIZE, INITIAL_SIZE * 2); - } - - @Test public void testAddAllARangeOnEmpty3() { - makeEmpty(); - wrapper.addAllA(wrapper.createPrimitiveArray(INITIAL_SIZE), 1, 0); - assertUnchanged(); - } - - @Test (expected = NullPointerException.class) - public void testAddAllARangeNull() { - try { - wrapper.addAllA(null, 0, 0); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllARangeNegative1() { - try { - testAddAllARange(INITIAL_SIZE, -1, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllARangeNegative2() { - try { - testAddAllARange(INITIAL_SIZE, 0, INITIAL_SIZE + 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllARangeNegative3() { - try { - testAddAllARange(INITIAL_SIZE, 1, -1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllARangeNegative4() { - try { - testAddAllARange(INITIAL_SIZE, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - // ========== addAll(observable array, range) tests ========== - - private void testAddAllTRange(int srcSize, int srcIndex, int length) { - Object src = wrapper.createPrimitiveArray(srcSize); - int oldSize = array.size(); - - wrapper.addAllT(wrapper.newInstance().createNotEmptyArray(src), srcIndex, length); - - int newSize = oldSize + length; - boolean sizeChanged = newSize != oldSize; - - mao.check(array, sizeChanged, oldSize, newSize); - Object actual = wrapper.toArray(null); - assertEquals(newSize, array.size()); - assertEquals(newSize, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, oldSize, initialElements, 0); - wrapper.assertElementsEqual(actual, oldSize, newSize, src, srcIndex); - } - - @Test public void testAddAllTRange1() { - testAddAllTRange(INITIAL_SIZE, 0, INITIAL_SIZE); - } - - @Test public void testAddAllTRange2() { - testAddAllTRange(INITIAL_SIZE + 10, 0, INITIAL_SIZE); - } - - @Test public void testAddAllTRange3() { - testAddAllTRange(INITIAL_SIZE + 10, 10, INITIAL_SIZE); - } - - @Test public void testAddAllTRange4() { - testAddAllTRange(INITIAL_SIZE + 10, 2, INITIAL_SIZE); - } - - @Test public void testAddAllTRange5() { - testAddAllTRange(INITIAL_SIZE, 0, INITIAL_SIZE / 2); - } - - @Test public void testAddAllTRange6() { - testAddAllTRange(INITIAL_SIZE + 10, 0, INITIAL_SIZE + 10); - } - - @Test public void testAddAllTRange7() { - testAddAllTRange(INITIAL_SIZE + 20, 10, INITIAL_SIZE + 10); - } - - @Test public void testAddAllTRange8() { - testAddAllTRange(INITIAL_SIZE + 10, 2, INITIAL_SIZE - 3); - } - - @Test public void testAddAllTRangeOnEmpty1() { - makeEmpty(); - testAddAllTRange(INITIAL_SIZE, 1, 3); - } - - @Test public void testAddAllTRangeOnEmpty2() { - makeEmpty(); - testAddAllTRange(INITIAL_SIZE * 3, INITIAL_SIZE, INITIAL_SIZE * 2); - } - - @Test public void testAddAllTRangeOnEmpty3() { - makeEmpty(); - wrapper.addAllT(wrapper.newInstance().createNotEmptyArray(wrapper.createPrimitiveArray(INITIAL_SIZE)), 1, 0); - assertUnchanged(); - } - - @Test (expected = NullPointerException.class) - public void testAddAllTRangeNull() { - try { - wrapper.addAllT(null, 0, 0); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeNegative1() { - try { - testAddAllTRange(INITIAL_SIZE, -1, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeNegative2() { - try { - testAddAllTRange(INITIAL_SIZE, 0, INITIAL_SIZE + 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeNegative3() { - try { - testAddAllTRange(INITIAL_SIZE, 1, -1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeNegative4() { - try { - testAddAllTRange(INITIAL_SIZE, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeNegativeAfterSrcEnsureCapacity() { - Object srcA = wrapper.createPrimitiveArray(INITIAL_SIZE); - ObservableArray src = wrapper.newInstance().createNotEmptyArray(srcA); - src.ensureCapacity(INITIAL_SIZE * 2); - try { - wrapper.addAllT(src, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeNegativeAfterSrcClear() { - Object srcA = wrapper.createPrimitiveArray(INITIAL_SIZE); - ObservableArray src = wrapper.newInstance().createNotEmptyArray(srcA); - src.clear(); - try { - wrapper.addAllT(src, 0, 1); - } finally { - assertUnchanged(); - } - } - - private void testAddAllTRangeSelf(int srcIndex, int length) { - wrapper.addAllT(array, srcIndex, length); - - int expSize = initialSize + length; - mao.check(array, true, initialSize, expSize); - Object actual = wrapper.toArray(null); - assertEquals(expSize, array.size()); - assertEquals(expSize, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, initialSize, initialElements, 0); - wrapper.assertElementsEqual(actual, initialSize, expSize, initialElements, srcIndex); - } - - @Test public void testAddAllTRangeSelf() { - testAddAllTRangeSelf(0, INITIAL_SIZE); - } - - @Test public void testAddAllTRangeSelfBeginning() { - testAddAllTRangeSelf(0, INITIAL_SIZE / 2); - } - - @Test public void testAddAllTRangeSelfTrailing() { - testAddAllTRangeSelf(INITIAL_SIZE / 2, INITIAL_SIZE / 2); - } - - @Test public void testAddAllTRangeSelfMiddle() { - testAddAllTRangeSelf(2, 2); - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeSelfNegative1() { - try { - testAddAllTRangeSelf(-1, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeSelfNegative2() { - try { - testAddAllTRangeSelf(0, INITIAL_SIZE + 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeSelfNegative3() { - try { - testAddAllTRangeSelf(1, -1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeSelfNegative4() { - try { - testAddAllTRangeSelf(INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeSelfNegativeAfterEnsureCapacity() { - array.ensureCapacity(INITIAL_SIZE * 2); - try { - wrapper.addAllT(array, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testAddAllTRangeSelfNegativeAfterClear() { - makeEmpty(); - try { - wrapper.addAllT(array, 0, 1); - } finally { - assertUnchanged(); - } - } - - // ========== set(primitive array, range) tests ========== - - private void testSetARange(int srcLength, int destIndex, int srcIndex, int length) { - Object expected = wrapper.createPrimitiveArray(srcLength); - - wrapper.setA(destIndex, expected, srcIndex, length); - - mao.checkOnlyElementsChanged(array, destIndex, destIndex + length); - Object actual = wrapper.toArray(null); - assertEquals(INITIAL_SIZE, array.size()); - assertEquals(INITIAL_SIZE, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, destIndex, initialElements, 0); - wrapper.assertElementsEqual(actual, destIndex, destIndex + length, expected, srcIndex); - wrapper.assertElementsEqual(actual, destIndex + length, INITIAL_SIZE, initialElements, destIndex + length); - } - - @Test public void testSetARange1() { - testSetARange(5, 0, 0, 5); - } - - @Test public void testSetARange2() { - testSetARange(3, 2, 0, 3); - } - - @Test public void testSetARange3() { - testSetARange(5, 0, 2, 3); - } - - @Test public void testSetARange4() { - testSetARange(5, 0, 0, 3); - } - - @Test public void testSetARange5() { - testSetARange(10, 3, 5, 3); - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetARangeNegative1() { - try { - testSetARange(10, -1, 0, 3); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetARangeNegative2() { - try { - testSetARange(10, 0, -1, 3); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetARangeNegative3() { - try { - testSetARange(10, 1, 1, -1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetARangeNegative4() { - try { - testSetARange(10, INITIAL_SIZE, 0, 3); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetARangeNegative5() { - try { - testSetARange(10, 0, 10, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetARangeNegative6() { - try { - testSetARange(3, 0, 1, 4); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetARangeNegative7() { - try { - testSetARange(10, INITIAL_SIZE - 3, 0, 4); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetARangeNegativeAfterEnsureCapacity() { - array.ensureCapacity(INITIAL_SIZE * 2); - try { - testSetARange(1, INITIAL_SIZE, 0, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetARangeNegativeAfterClear() { - makeEmpty(); - try { - testSetARange(1, 0, 0, 1); - } finally { - assertUnchanged(); - } - } - - // ========== set(ObservableArray, range) tests ========== - - private void testSetTRange(int srcLength, int destIndex, int srcIndex, int length) { - Object expected = wrapper.createPrimitiveArray(srcLength); - ObservableArray src = wrapper.newInstance().createNotEmptyArray(expected); - - wrapper.setT(destIndex, src, srcIndex, length); - - mao.checkOnlyElementsChanged(array, destIndex, destIndex + length); - Object actual = wrapper.toArray(null); - assertEquals(INITIAL_SIZE, array.size()); - assertEquals(INITIAL_SIZE, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, destIndex, initialElements, 0); - wrapper.assertElementsEqual(actual, destIndex, destIndex + length, expected, srcIndex); - wrapper.assertElementsEqual(actual, destIndex + length, initialSize, initialElements, destIndex + length); - } - - @Test public void testSetTRange1() { - testSetTRange(5, 0, 0, 5); - } - - @Test public void testSetTRange2() { - testSetTRange(3, 2, 0, 3); - } - - @Test public void testSetTRange3() { - testSetTRange(5, 0, 2, 3); - } - - @Test public void testSetTRange4() { - testSetTRange(5, 0, 0, 3); - } - - @Test public void testSetTRange5() { - testSetTRange(10, 3, 5, 3); - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeNegative1() { - try { - testSetTRange(10, -1, 0, 3); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeNegative2() { - try { - testSetTRange(10, 0, -1, 3); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeNegative3() { - try { - testSetTRange(10, 1, 1, -1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeNegative4() { - try { - testSetTRange(10, INITIAL_SIZE, 0, 3); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeNegative5() { - try { - testSetTRange(10, 0, 10, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeNegative6() { - try { - testSetTRange(3, 0, 1, 4); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeNegative7() { - try { - testSetTRange(10, INITIAL_SIZE - 3, 0, 4); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeNegativeAfterEnsureCapacity() { - array.ensureCapacity(INITIAL_SIZE * 2); - try { - testSetTRange(1, INITIAL_SIZE, 0, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeNegativeAfterClear() { - makeEmpty(); - try { - testSetTRange(1, 0, 0, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeNegativeAfterSrcEnsureCapacity() { - try { - Object srcA = wrapper.createPrimitiveArray(1); - ObservableArray src = wrapper.newInstance().createNotEmptyArray(srcA); - src.ensureCapacity(2); - - wrapper.setT(0, src, 1, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeNegativeAfterSrcClear() { - try { - Object srcA = wrapper.createPrimitiveArray(1); - ObservableArray src = wrapper.newInstance().createNotEmptyArray(srcA); - src.clear(); - - wrapper.setT(0, src, 0, 1); - } finally { - assertUnchanged(); - } - } - - private void testSetTRangeSelf(int destIndex, int srcIndex, int length) { - - wrapper.setT(destIndex, array, srcIndex, length); - - mao.checkOnlyElementsChanged(array, destIndex, destIndex + length); - Object actual = wrapper.toArray(null); - assertEquals(INITIAL_SIZE, array.size()); - assertEquals(INITIAL_SIZE, wrapper.arrayLength(actual)); - wrapper.assertElementsEqual(actual, 0, destIndex, initialElements, 0); - wrapper.assertElementsEqual(actual, destIndex, destIndex + length, initialElements, srcIndex); - wrapper.assertElementsEqual(actual, destIndex + length, initialSize, initialElements, destIndex + length); - } - - @Test public void testSetTRangeSelf() { - testSetTRangeSelf(0, 0, INITIAL_SIZE); - } - - @Test public void testSetTRangeSelfLeft() { - testSetTRangeSelf(0, 1, INITIAL_SIZE - 1); - } - - @Test public void testSetTRangeSelfRight() { - testSetTRangeSelf(1, 0, INITIAL_SIZE - 1); - } - - @Test public void testSetTRangeSelfRightDifferentParts() { - testSetTRangeSelf(0, INITIAL_SIZE / 2, INITIAL_SIZE / 2); - } - - @Test public void testSetTRangeSelfLeftDifferentParts() { - testSetTRangeSelf(INITIAL_SIZE / 2, 0, INITIAL_SIZE / 2); - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeSelfNegative1() { - try { - wrapper.setT(-1, array, 0, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeSelfNegative2() { - try { - wrapper.setT(0, array, -1, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeSelfNegative3() { - try { - wrapper.setT(0, array, 0, INITIAL_SIZE + 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeSelfNegative4() { - try { - wrapper.setT(0, array, 1, -1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeSelfNegative5() { - try { - wrapper.setT(INITIAL_SIZE, array, 0, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeSelfNegative6() { - try { - wrapper.setT(0, array, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeSelfNegativeAfterEnsureCapacity() { - try { - array.ensureCapacity(INITIAL_SIZE * 2); - - wrapper.setT(0, array, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetTRangeSelfNegativeAfterClear() { - makeEmpty(); - try { - wrapper.setT(0, array, 0, 1); - } finally { - assertUnchanged(); - } - } - - - // ========== negative get(index) tests ========== - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testGetNegative() { - try { - wrapper.get(-1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testGetOutOfBounds() { - try { - wrapper.get(array.size()); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testGetAfterEnsureCapacity() { - try { - array.ensureCapacity(INITIAL_SIZE * 2); - wrapper.get(INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testGetAfterClear() { - makeEmpty(); - try { - wrapper.get(0); - } finally { - assertUnchanged(); - } - } - - // ================== set(index) tests =============== - - @Test public void testSetValue() { - for (int i = 0; i < INITIAL_SIZE; i++) { - Object expected = wrapper.getNextValue(); - - wrapper.set(i, expected); - - mao.check(array, false, i, i + 1); - mao.reset(); - assertEquals(expected, wrapper.get(i)); - assertEquals(INITIAL_SIZE, array.size()); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetValueNegative() { - try { - wrapper.set(-1, wrapper.getNextValue()); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetValueOutOfBounds() { - try { - wrapper.set(INITIAL_SIZE, wrapper.getNextValue()); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetValueNegativeAfterClear() { - makeEmpty(); - try { - wrapper.set(0, wrapper.getNextValue()); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testSetValueNegativeAfterEnsureCapacity() { - array.ensureCapacity(INITIAL_SIZE * 2); - try { - wrapper.set(INITIAL_SIZE, wrapper.getNextValue()); - } finally { - assertUnchanged(); - } - } - - // ================= toArray(array) tests ====================== - - private void testToArray(int arraySize, boolean same) { - Object param = wrapper.createPrimitiveArray(arraySize); - Object actual = wrapper.toArray(param); - assertUnchanged(); - if (same) { - assertSame(param, actual); - } else { - assertNotSame(param, actual); - assertEquals(array.size(), wrapper.arrayLength(actual)); - } - wrapper.assertElementsEqual(actual, 0, array.size(), wrapper.toArray(null), 0); - } - - @Test public void testToArraySameSize() { - testToArray(array.size(), true); - } - - @Test public void testToArraySmaller() { - testToArray(3, false); - } - - @Test public void testToArrayBigger() { - testToArray(10, true); - } - - @Test public void testToArrayEmpty() { - makeEmpty(); - testToArray(10, true); - } - - @Test public void testToArrayEmptyToEmpty() { - makeEmpty(); - testToArray(0, true); - } - - // ============ toArray range tests ========================= - - private void testToArrayRange(int srcIndex, int destSize, int length) { - Object dest = wrapper.createPrimitiveArray(destSize); - Object initial = wrapper.clonePrimitiveArray(dest); - Object actual = wrapper.toArray(srcIndex, dest, length); - assertUnchanged(); - Object expected = wrapper.toArray(null); - wrapper.assertElementsEqual(actual, 0, length, expected, srcIndex); - wrapper.assertElementsEqual(actual, length, wrapper.arrayLength(actual), initial, length); - } - - @Test public void testToArrayRange0() { - testToArrayRange(0, array.size(), array.size()); - } - - @Test public void testToArrayRange1() { - testToArrayRange(3, array.size(), array.size() - 3); - } - - @Test public void testToArrayRange2() { - testToArrayRange(0, array.size(), array.size() - 3); - } - - @Test public void testToArrayRange3() { - testToArrayRange(2, array.size(), 2); - } - - @Test public void testToArrayRange4() { - testToArrayRange(2, 0, 0); - } - - @Test public void testToArrayRange5() { - makeEmpty(); - testToArrayRange(0, 0, 0); - } - - @Test public void testToArrayRange6() { - testToArrayRange(3, 2, 2); - } - - @Test public void testToArrayRange7() { - testToArrayRange(5, 1, 1); - } - - @Test public void testToArrayRange8() { - testToArrayRange(0, array.size() * 2, array.size()); - } - - @Test public void testToArrayRange9() { - testToArrayRange(0, array.size() - 1, array.size()); - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testToArrayRangeNegative1() { - try { - testToArrayRange(-1, array.size(), 2); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testToArrayRangeNegative2() { - try { - testToArrayRange(array.size(), array.size(), 2); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testToArrayRangeNegative3() { - try { - testToArrayRange(5, array.size(), array.size() + 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testToArrayRangeNegative5() { - makeEmpty(); - try { - testToArrayRange(2, 0, 0); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testToArrayRangeNegativeAfterEnsureCapacity() { - array.ensureCapacity(INITIAL_SIZE * 2); - try { - testToArrayRange(INITIAL_SIZE, 1, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testToArrayRangeNegativeAfterClear() { - makeEmpty(); - try { - testToArrayRange(0, 1, 1); - } finally { - assertUnchanged(); - } - } - - // ============ copyTo(primitive array) tests ========================= - - private void testCopyToA(int srcIndex, int destSize, int destIndex, int length) { - Object actual = wrapper.createPrimitiveArray(destSize); - Object initial = wrapper.clonePrimitiveArray(actual); - wrapper.copyToA(srcIndex, actual, destIndex, length); - assertUnchanged(); - Object expected = wrapper.toArray(null); - wrapper.assertElementsEqual(actual, 0, destIndex, initial, 0); - wrapper.assertElementsEqual(actual, destIndex, destIndex + length, expected, srcIndex); - wrapper.assertElementsEqual(actual, destIndex + length, wrapper.arrayLength(actual), initial, destIndex + length); - } - - @Test public void testCopyToA0() { - testCopyToA(0, array.size(), 0, array.size()); - } - - @Test public void testCopyToA1() { - testCopyToA(1, array.size(), 2, 3); - } - - @Test public void testCopyToA2() { - testCopyToA(2, array.size(), 2, 2); - } - - @Test public void testCopyToA3() { - testCopyToA(0, array.size(), 2, 2); - } - - @Test public void testCopyToA4() { - testCopyToA(0, 3, 1, 2); - } - - @Test public void testCopyToA5() { - testCopyToA(0, array.size() * 3, array.size() * 2, array.size()); - } - - @Test public void testCopyToA6() { - testCopyToA(3, array.size(), 0, array.size() - 3); - } - - @Test public void testCopyToA7() { - testCopyToA(0, 10, 7, 3); - } - - @Test public void testCopyToA8() { - testCopyToA(1, 0, 0, 0); - } - - @Test public void testCopyToA9() { - makeEmpty(); - testCopyToA(0, 0, 0, 0); - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToANegative1() { - try { - testCopyToA(-1, array.size(), 0, array.size()); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToANegative2() { - try { - testCopyToA(0, array.size() / 2, 0, array.size()); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToANegative3() { - try { - testCopyToA(array.size(), array.size(), 0, array.size()); - } finally { - assertUnchanged(); - } - - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToANegative4() { - try { - testCopyToA(0, array.size(), -1, array.size()); - } finally { - assertUnchanged(); - } - - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToANegative5() { - try { - testCopyToA(0, array.size(), array.size(), array.size()); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToANegative6() { - try { - testCopyToA(0, array.size(), 0, array.size() * 2); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToANegative7() { - makeEmpty(); - try { - testCopyToA(1, 0, 0, 0); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToANegative8() { - try { - testCopyToA(0, 0, 1, 0); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToANegativeAfterEnsureCapacity() { - array.ensureCapacity(INITIAL_SIZE * 2); - try { - testCopyToA(INITIAL_SIZE, 1, 0, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToANegativeAfterClear() { - makeEmpty(); - try { - testCopyToA(0, 1, 0, 1); - } finally { - assertUnchanged(); - } - } - - // ============ copyTo(ObservableArray) tests ========================= - - private void testCopyToT(int srcIndex, int destSize, int destIndex, int length) { - ArrayWrapper wrapper2 = wrapper.newInstance(); - Object initial = wrapper2.createPrimitiveArray(destSize); - ObservableArray dest = wrapper2.createNotEmptyArray(initial); - - wrapper.copyToT(srcIndex, dest, destIndex, length); - - assertUnchanged(); - Object expected = wrapper.toArray(null); - Object actual = wrapper2.toArray(null); - wrapper.assertElementsEqual(actual, 0, destIndex, initial, 0); - wrapper.assertElementsEqual(actual, destIndex, destIndex + length, expected, srcIndex); - wrapper.assertElementsEqual(actual, destIndex + length, wrapper.arrayLength(actual), initial, destIndex + length); - } - - @Test public void testCopyToT0() { - testCopyToT(0, array.size(), 0, array.size()); - } - - @Test public void testCopyToT1() { - testCopyToT(1, array.size(), 2, 3); - } - - @Test public void testCopyToT2() { - testCopyToT(2, array.size(), 2, 2); - } - - @Test public void testCopyToT3() { - testCopyToT(0, array.size(), 2, 2); - } - - @Test public void testCopyToT4() { - testCopyToT(0, 3, 1, 2); - } - - @Test public void testCopyToT5() { - testCopyToT(0, array.size() * 3, array.size() * 2, array.size()); - } - - @Test public void testCopyToT6() { - testCopyToT(3, array.size(), 0, array.size() - 3); - } - - @Test public void testCopyToT7() { - testCopyToT(0, 10, 7, 3); - } - - @Test public void testCopyToT8() { - testCopyToT(1, 0, 0, 0); - } - - @Test public void testCopyToT9() { - makeEmpty(); - testCopyToT(0, 0, 0, 0); - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegative1() { - try { - testCopyToT(-1, array.size(), 0, array.size()); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegative2() { - try { - testCopyToT(0, array.size() / 2, 0, array.size()); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegative3() { - try { - testCopyToT(array.size(), array.size(), 0, array.size()); - } finally { - assertUnchanged(); - } - - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegative4() { - try { - testCopyToT(0, array.size(), -1, array.size()); - } finally { - assertUnchanged(); - } - - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegative5() { - try { - testCopyToT(0, array.size(), array.size(), array.size()); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegative6() { - try { - testCopyToT(0, array.size(), 0, array.size() * 2); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegative7() { - makeEmpty(); - try { - testCopyToT(1, 0, 0, 0); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegative8() { - try { - testCopyToT(0, 0, 1, 0); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegativeAfterEnsureCapacity() { - array.ensureCapacity(INITIAL_SIZE * 2); - try { - testCopyToT(INITIAL_SIZE, 1, 0, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegativeAfterClear() { - makeEmpty(); - try { - testCopyToT(0, 1, 0, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegativeAfterDestEnsureCapacity() { - try { - ArrayWrapper wrapper2 = wrapper.newInstance(); - Object destA = wrapper2.createPrimitiveArray(1); - ObservableArray dest = wrapper2.createNotEmptyArray(destA); - dest.ensureCapacity(2); - - wrapper.copyToT(0, dest, 1, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTNegativeAfterDestClear() { - try { - ArrayWrapper wrapper2 = wrapper.newInstance(); - Object destA = wrapper2.createPrimitiveArray(1); - ObservableArray dest = wrapper2.createNotEmptyArray(destA); - dest.clear(); - - wrapper.copyToT(0, dest, 0, 1); - } finally { - assertUnchanged(); - } - } - - private void testCopyToTSelf(int srcIndex, int destIndex, int length) { - - wrapper.copyToT(srcIndex, array, destIndex, length); - - mao.checkOnlyElementsChanged(array, destIndex, destIndex + length); - Object actual = wrapper.toArray(null); - wrapper.assertElementsEqual(actual, 0, destIndex, initialElements, 0); - wrapper.assertElementsEqual(actual, destIndex, destIndex + length, initialElements, srcIndex); - wrapper.assertElementsEqual(actual, destIndex + length, initialSize, initialElements, destIndex + length); - } - - @Test public void testCopyToTSelf() { - testCopyToTSelf(0, 0, INITIAL_SIZE); - } - - @Test public void testCopyToTSelfRight() { - testCopyToTSelf(0, 1, INITIAL_SIZE - 1); - } - - @Test public void testCopyToTSelfLeft() { - testCopyToTSelf(1, 0, INITIAL_SIZE - 1); - } - - @Test public void testCopyToTSelfRightDifferentParts() { - testCopyToTSelf(0, INITIAL_SIZE / 2, INITIAL_SIZE / 2); - } - - @Test public void testCopyToTSelfLeftDifferentParts() { - testCopyToTSelf(INITIAL_SIZE / 2, 0, INITIAL_SIZE / 2); - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTSelfNegative1() { - try { - testCopyToTSelf(-1, 0, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTSelfNegative2() { - try { - testCopyToTSelf(INITIAL_SIZE, 0, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTSelfNegative3() { - try { - testCopyToTSelf(0, -1, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTSelfNegative4() { - try { - testCopyToTSelf(0, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTSelfNegative5() { - try { - testCopyToTSelf(1, 1, -1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTSelfNegative6() { - try { - testCopyToTSelf(0, 1, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTSelfNegative7() { - try { - testCopyToTSelf(1, 0, INITIAL_SIZE); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTSelfNegativeAfterEnsureCapacity() { - array.ensureCapacity(INITIAL_SIZE * 2); - try { - testCopyToTSelf(0, INITIAL_SIZE, 1); - } finally { - assertUnchanged(); - } - } - - @Test (expected = ArrayIndexOutOfBoundsException.class) - public void testCopyToTSelfNegativeAfterClear() { - makeEmpty(); - try { - testCopyToTSelf(0, 0, 1); - } finally { - assertUnchanged(); - } - } - - // ============ ensureCapacity() and trimToSize() tests ==================== - - @Test public void testTrimToSize() { - array.trimToSize(); - assertUnchanged(); - } - - @Test public void testTrimToSizeEmpty() { - makeEmpty(); - array.trimToSize(); - assertUnchanged(); - } - - @Test public void testTrimToSizeResize() { - array.resize(3); - initialSize = 3; - mao.reset(); - - array.trimToSize(); - - assertUnchanged(); - } - - @Test public void testTrimToSizeAddRemove() { - array.resize(1000); - array.resize(INITIAL_SIZE); - mao.reset(); - - array.trimToSize(); - - assertUnchanged(); - } - - @Test public void testEnsureCapacity0() { - array.ensureCapacity(0); - assertUnchanged(); - } - - @Test public void testEnsureCapacityBy1() { - array.ensureCapacity(INITIAL_SIZE + 1); - assertUnchanged(); - } - - @Test public void testEnsureCapacity1000() { - array.ensureCapacity(1000); - assertUnchanged(); - } - - @Test public void testEnsureCapacitySmaller() { - array.ensureCapacity(INITIAL_SIZE / 2); - assertUnchanged(); - } - - @Test public void testEnsureCapacityNegative() { - array.ensureCapacity(-1000); - assertUnchanged(); - } - - @Test public void testEnsureCapacityOnEmpty() { - makeEmpty(); - array.ensureCapacity(100); - assertUnchanged(); - } - - @Test public void testEnsureCapacityOnEmpty0() { - makeEmpty(); - array.ensureCapacity(0); - assertUnchanged(); - } - - @Test public void testEnsureCapacityOnEmptyNegative() { - makeEmpty(); - array.ensureCapacity(-1); - assertUnchanged(); - } - - @Test public void testTrimToSizeEnsureCapacity() { - array.ensureCapacity(1000); - array.trimToSize(); - assertUnchanged(); - } - - // ================= clear() tests ==================== - - @Test public void testClearEmpty() { - makeEmpty(); - array.clear(); - mao.check0(); - assertEquals(0, array.size()); - } - - @Test public void testClear1000() { - array.resize(1000); - mao.reset(); - - array.clear(); - - mao.checkOnlySizeChanged(array); - assertEquals(0, array.size()); - } - - // ================= toString() tests =================== - - @Test public void testToString() { - String actual = array.toString(); - String expected = wrapper.primitiveArrayToString(wrapper.toArray(null)); - assertEquals(expected, actual); - String regex = "\\[[0-9]+(\\.[0-9]+){0,1}(\\, [0-9]+(.[0-9]+){0,1}){" + (initialSize - 1) + "}\\]"; - assertTrue("toString() output matches to regex '" + regex + "'. Actual = '" + actual + "'", - actual.matches(regex)); - } - - @Test public void testToStringAfterResize() { - array.resize(initialSize / 2); - String actual = array.toString(); - String expected = wrapper.primitiveArrayToString(wrapper.toArray(null)); - assertEquals(expected, actual); - String regex = "\\[[0-9]+(\\.[0-9]+){0,1}(\\, [0-9]+(.[0-9]+){0,1}){" + (array.size() - 1) + "}\\]"; - assertTrue("toString() output matches to regex '" + regex + "'. Actual = '" + actual + "'", - actual.matches(regex)); - } - - @Test public void testToStringAfterClear() { - array.clear(); - String actual = array.toString(); - assertEquals("[]", actual); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/ObservableArrayTest.java 2015-08-31 10:24:52.705216515 -0400 @@ -0,0 +1,2706 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import javafx.beans.InvalidationListener; +import javafx.collections.ArrayChangeListener; +import javafx.collections.FXCollections; +import javafx.collections.ObservableArray; +import javafx.collections.ObservableFloatArray; +import javafx.collections.ObservableIntegerArray; + +import static org.junit.Assert.*; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + * Tests for ObservableArray. + */ +@RunWith(Parameterized.class) +public class ObservableArrayTest { + public static final int INITIAL_SIZE = 6; + + /** + * @param ObservableArray subclass + * @param corresponding primitive array + * @param

corresponding class for boxed elements + */ + public static abstract class ArrayWrapper, A, P> { + + T array; + final T array() { + return array; + } + + abstract T createEmptyArray(); + abstract T createNotEmptyArray(A src); + abstract ArrayWrapper newInstance(); + abstract P getNextValue(); + abstract void set(int index, P value); + abstract void setAllA(A src); + abstract void setAllT(T src); + abstract void setAllA(A src, int srcIndex, int length); + abstract void setAllT(T src, int srcIndex, int length); + abstract void addAllA(A src); + abstract void addAllT(T src); + abstract void addAllA(A src, int srcIndex, int length); + abstract void addAllT(T src, int srcIndex, int length); + abstract void setA(int destIndex, A src, int srcIndex, int length); + abstract void setT(int destIndex, T src, int srcIndex, int length); + abstract void copyToA(int srcIndex, A dest, int destIndex, int length); + abstract void copyToT(int srcIndex, T dest, int destIndex, int length); + abstract P get(int index); + abstract A toArray(A dest); + abstract A toArray(int srcIndex, A dest, int length); + + A createPrimitiveArray(int size) { + return createPrimitiveArray(size, true); + } + abstract A createPrimitiveArray(int size, boolean fillWithData); + abstract A clonePrimitiveArray(A array); + abstract int arrayLength(A array); + abstract P get(A array, int index); + abstract void assertElementsEqual(A actual, int from, int to, A expected, int expFrom); + abstract String primitiveArrayToString(A array); + } + + private static class IntegerArrayWrapper extends ArrayWrapper { + + int nextValue = 0; + + @Override IntegerArrayWrapper newInstance() { + return new IntegerArrayWrapper(); + } + + @Override ObservableIntegerArray createEmptyArray() { + return array = FXCollections.observableIntegerArray(); + } + + @Override ObservableIntegerArray createNotEmptyArray(int[] src) { + return array = FXCollections.observableIntegerArray(src); + } + + @Override Integer getNextValue() { + return nextValue++; + } + + @Override void set(int index, Integer value) { + array.set(index, value); + } + + @Override int[] createPrimitiveArray(int size, boolean fillWithData) { + int[] res = new int[size]; + if (fillWithData) { + for (int i = 0; i < size; i++) { + res[i] = nextValue++; + } + } + return res; + } + + @Override void setAllA(int[] src) { + array.setAll(src); + } + + @Override void setAllA(int[] src, int srcIndex, int length) { + array.setAll(src, srcIndex, length); + } + + @Override void setAllT(ObservableIntegerArray src) { + array.setAll(src); + } + + @Override void setAllT(ObservableIntegerArray src, int srcIndex, int length) { + array.setAll(src, srcIndex, length); + } + + @Override void addAllA(int[] src) { + array.addAll(src); + } + + @Override void addAllA(int[] src, int srcIndex, int length) { + array.addAll(src, srcIndex, length); + } + + @Override void addAllT(ObservableIntegerArray src) { + array.addAll(src); + } + + @Override void addAllT(ObservableIntegerArray src, int srcIndex, int length) { + array.addAll(src, srcIndex, length); + } + + @Override void copyToA(int srcIndex, int[] dest, int destIndex, int length) { + array.copyTo(srcIndex, dest, destIndex, length); + } + + @Override void copyToT(int srcIndex, ObservableIntegerArray dest, int destIndex, int length) { + array.copyTo(srcIndex, dest, destIndex, length); + } + + @Override Integer get(int index) { + return array.get(index); + } + + @Override int[] toArray(int[] src) { + return array.toArray(src); + } + + @Override int[] toArray(int srcIndex, int[] dest, int length) { + return array.toArray(srcIndex, dest, length); + } + + @Override void setA(int destIndex, int[] src, int srcIndex, int length) { + array.set(destIndex, src, srcIndex, length); + } + + @Override void setT(int destIndex, ObservableIntegerArray src, int srcIndex, int length) { + array.set(destIndex, src, srcIndex, length); + } + + @Override int arrayLength(int[] array) { + return array.length; + } + + @Override + Integer get(int[] array, int index) { + return array[index]; + } + + @Override + void assertElementsEqual(int[] actual, int from, int to, int[] expected, int expFrom) { + for(int i = from, j = expFrom; i < to; i++, j++) { + assertEquals(actual[i], expected[j]); + } + } + + @Override int[] clonePrimitiveArray(int[] array) { + return Arrays.copyOf(array, array.length); + } + + @Override + String primitiveArrayToString(int[] array) { + return Arrays.toString(array); + } + } + + private static class FloatArrayWrapper extends ArrayWrapper { + + float nextValue = 0; + + @Override FloatArrayWrapper newInstance() { + return new FloatArrayWrapper(); + } + + @Override ObservableFloatArray createEmptyArray() { + return array = FXCollections.observableFloatArray(); + } + + @Override ObservableFloatArray createNotEmptyArray(float[] elements) { + return array = FXCollections.observableFloatArray(elements); + } + + @Override + Float getNextValue() { + return nextValue++; + } + + @Override void set(int index, Float value) { + array.set(index, value); + } + + @Override float[] createPrimitiveArray(int size, boolean fillWithData) { + float[] res = new float[size]; + if (fillWithData) { + for (int i = 0; i < size; i++) { + res[i] = nextValue++; + } + } + return res; + } + + @Override void setAllA(float[] src) { + array.setAll(src); + } + + @Override void copyToA(int srcIndex, float[] dest, int destIndex, int length) { + array.copyTo(srcIndex, dest, destIndex, length); + } + + @Override void copyToT(int srcIndex, ObservableFloatArray dest, int destIndex, int length) { + array.copyTo(srcIndex, dest, destIndex, length); + } + + @Override Float get(int index) { + return array.get(index); + } + + @Override float[] toArray(float[] dest) { + return array.toArray(dest); + } + + @Override float[] toArray(int srcIndex, float[] dest, int length) { + return array.toArray(srcIndex, dest, length); + } + + @Override void setA(int destIndex, float[] src, int srcIndex, int length) { + array.set(destIndex, src, srcIndex, length); + } + + @Override int arrayLength(float[] array) { + return array.length; + } + + @Override + Float get(float[] array, int index) { + return array[index]; + } + + @Override + void assertElementsEqual(float[] actual, int from, int to, float[] expected, int expFrom) { + for(int i = from, j = expFrom; i < to; i++, j++) { + assertEquals("expected float = " + expected[j] + ", actual float = " + actual[i], + Float.floatToRawIntBits(expected[j]), + Float.floatToRawIntBits(actual[i])); + } + } + + @Override float[] clonePrimitiveArray(float[] array) { + return Arrays.copyOf(array, array.length); + } + + @Override void setAllT(ObservableFloatArray src) { + array.setAll(src); + } + + @Override void setAllA(float[] src, int srcIndex, int length) { + array.setAll(src, srcIndex, length); + } + + @Override void setAllT(ObservableFloatArray src, int srcIndex, int length) { + array.setAll(src, srcIndex, length); + } + + @Override void addAllA(float[] src) { + array.addAll(src); + } + + @Override void addAllT(ObservableFloatArray src) { + array.addAll(src); + } + + @Override void addAllA(float[] src, int srcIndex, int length) { + array.addAll(src, srcIndex, length); + } + + @Override void addAllT(ObservableFloatArray src, int srcIndex, int length) { + array.addAll(src, srcIndex, length); + } + + @Override void setT(int destIndex, ObservableFloatArray src, int srcIndex, int length) { + array.set(destIndex, src, srcIndex, length); + } + + @Override + String primitiveArrayToString(float[] array) { + return Arrays.toString(array); + } + } + + static final List EMPTY = Collections.emptyList(); + final ArrayWrapper wrapper; + private int initialSize; + private Object initialElements; + private ObservableArray array; + private MockArrayObserver mao; + + public ObservableArrayTest(final ArrayWrapper arrayWrapper) { + this.wrapper = arrayWrapper; + } + + @Parameterized.Parameters + public static Collection createParameters() { + Object[][] data = new Object[][] { + { new FloatArrayWrapper() }, + { new IntegerArrayWrapper() }, + }; + return Arrays.asList(data); + } + + @Before + public void setUp() throws Exception { + initialSize = INITIAL_SIZE; + initialElements = wrapper.createPrimitiveArray(initialSize); + array = wrapper.createNotEmptyArray(initialElements); + mao = new MockArrayObserver(); + array.addListener(mao); + } + + private void makeEmpty() { + initialSize = 0; + initialElements = wrapper.createPrimitiveArray(initialSize); + array.clear(); + mao.reset(); + } + + private void assertUnchanged() { + mao.check0(); + assertEquals(initialSize, array.size()); + Object actual = wrapper.toArray(null); + assertEquals(initialSize, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, array.size(), initialElements, 0); + } + + // ========== pre-condition tests ================ + + @Test public void testSize() { + mao.check0(); + assertEquals(INITIAL_SIZE, array.size()); + } + + @Test public void testClear() { + array.clear(); + mao.checkOnlySizeChanged(array); + assertEquals(0, array.size()); + } + + @Test public void testGet() { + for (int i = 0; i < array.size(); i++) { + Object expected = wrapper.get(initialElements, i); + Object actural = wrapper.get(i); + assertEquals(expected, actural); + } + assertUnchanged(); + } + + @Test public void testToArray() { + Object expected = initialElements; + Object actual = wrapper.toArray(null); + assertEquals(INITIAL_SIZE, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, array.size(), expected, 0); + assertUnchanged(); + } + + // ========== add/remove listener tests ========== + + @Test public void testAddRemoveListener() { + MockArrayObserver mao2 = new MockArrayObserver(); + array.addListener(mao2); + array.removeListener(mao); + wrapper.set(0, wrapper.getNextValue()); + mao.check0(); + mao2.check(array, false, 0, 1); + } + + @Test public void testAddTwoListenersElementChange() { + MockArrayObserver mao2 = new MockArrayObserver(); + array.addListener(mao2); + wrapper.set(0, wrapper.getNextValue()); + mao.check(array, false, 0, 1); + mao2.check(array, false, 0, 1); + } + + @Test public void testAddTwoListenersSizeChange() { + MockArrayObserver mao2 = new MockArrayObserver(); + array.addListener(mao2); + array.resize(3); + mao.checkOnlySizeChanged(array); + mao2.checkOnlySizeChanged(array); + } + + @Test public void testAddThreeListeners() { + MockArrayObserver mao2 = new MockArrayObserver(); + MockArrayObserver mao3 = new MockArrayObserver(); + array.addListener(mao2); + array.addListener(mao3); + wrapper.set(0, wrapper.getNextValue()); + mao.check(array, false, 0, 1); + mao2.check(array, false, 0, 1); + mao3.check(array, false, 0, 1); + } + + @Test public void testAddThreeListenersSizeChange() { + MockArrayObserver mao2 = new MockArrayObserver(); + MockArrayObserver mao3 = new MockArrayObserver(); + array.addListener(mao2); + array.addListener(mao3); + array.resize(10); + mao.checkOnlySizeChanged(array); + mao2.checkOnlySizeChanged(array); + mao3.checkOnlySizeChanged(array); + } + + @Test @Ignore + public void testAddListenerTwice() { + array.addListener(mao); // add it a second time + wrapper.set(1, wrapper.getNextValue()); + mao.check(array, false, 1, 2); + } + + @Test public void testRemoveListenerTwice() { + array.removeListener(mao); + array.removeListener(mao); + wrapper.set(1, wrapper.getNextValue()); + mao.check0(); + } + + @Test (expected = NullPointerException.class) + public void testAddNullArrayChangeListener() { + try { + array.addListener((ArrayChangeListener) null); + } finally { + mao.check0(); + array.resize(1); + mao.check1(); + } + } + + @Test (expected = NullPointerException.class) + public void testAddNullInvalidationListener() { + try { + array.addListener((InvalidationListener) null); + } finally { + mao.check0(); + array.resize(1); + mao.check1(); + } + } + + @Test (expected = NullPointerException.class) + public void testRemoveNullArrayChangeListener() { + try { + array.removeListener((ArrayChangeListener) null); + } finally { + mao.check0(); + array.resize(1); + mao.check1(); + } + } + + @Test (expected = NullPointerException.class) + public void testRemoveNullInvalidationListener() { + try { + array.removeListener((InvalidationListener) null); + } finally { + mao.check0(); + array.resize(1); + mao.check1(); + } + } + + // ========== resize tests ========== + + private void testResize(boolean noChange, int newSize, int matchingElements) { + Object expected = wrapper.toArray(null); + array.resize(newSize); + if (noChange) { + assertUnchanged(); + } else { + mao.checkOnlySizeChanged(array); + } + Object actual = wrapper.toArray(null); + assertEquals(newSize, array.size()); + assertEquals(newSize, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, matchingElements, expected, 0); + wrapper.assertElementsEqual(actual, matchingElements, newSize, + wrapper.createPrimitiveArray(Math.max(0, newSize - matchingElements), false), 0); + } + + @Test public void testResizeTo0() { + testResize(false, 0, 0); + } + + @Test public void testResizeToSmaller() { + testResize(false, 3, 3); + } + + @Test public void testResizeToSameSize() { + testResize(true, array.size(), array.size()); + } + + @Test public void testResizeToBigger() { + testResize(false, 10, array.size()); + } + + @Test public void testResizeOnEmpty() { + makeEmpty(); + testResize(false, 10, 0); + } + + @Test public void testResizeOnEmptyToEmpty() { + makeEmpty(); + testResize(true, 0, 0); + } + + @Test (expected = NegativeArraySizeException.class) + public void testResizeToNegative() { + try { + array.resize(-5); + } finally { + assertUnchanged(); + } + } + + // ========== setAll(primitive array) tests ========== + + private void testSetAllA(boolean sizeChanged, int newSize) { + Object expected = wrapper.createPrimitiveArray(newSize); + + wrapper.setAllA(expected); + + mao.check(array, sizeChanged, 0, newSize); + Object actual = wrapper.toArray(null); + assertEquals(wrapper.arrayLength(expected), array.size()); + assertEquals(wrapper.arrayLength(expected), wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, wrapper.arrayLength(expected), expected, 0); + } + + @Test public void testSetAllASmaller() { + testSetAllA(true, 3); + } + + @Test public void testSetAllABigger() { + testSetAllA(true, 10); + } + + @Test public void testSetAllAOnSameSize() { + testSetAllA(false, INITIAL_SIZE); + } + + @Test public void testSetAllAOnEmpty() { + makeEmpty(); + testSetAllA(true, 3); + } + + @Test public void testSetAllAOnEmptyToEmpty() { + makeEmpty(); + wrapper.setAllA(wrapper.createPrimitiveArray(0)); + assertUnchanged(); + assertEquals(0, array.size()); + } + + @Test (expected = NullPointerException.class) + public void testSetAllAToNull() { + try { + wrapper.setAllA(null); + } finally { + assertUnchanged(); + } + } + + // ========== setAll(ObservableArray) tests ========== + + private void testSetAllT(boolean sizeChanged, int newSize) { + ArrayWrapper wrapper2 = wrapper.newInstance(); + Object expected = wrapper.createPrimitiveArray(newSize); + ObservableArray src = wrapper2.createNotEmptyArray(expected); + + wrapper.setAllT(src); + + mao.check(array, sizeChanged, 0, newSize); + Object actual = wrapper.toArray(null); + assertEquals(wrapper.arrayLength(expected), array.size()); + assertEquals(wrapper.arrayLength(expected), wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, wrapper.arrayLength(expected), expected, 0); + } + + @Test public void testSetAllTSmaller() { + testSetAllT(true, 3); + } + + @Test public void testSetAllTBigger() { + testSetAllT(true, 10); + } + + @Test public void testSetAllTOnSameSize() { + testSetAllT(false, INITIAL_SIZE); + } + + @Test public void testSetAllTOnEmpty() { + makeEmpty(); + testSetAllT(true, 3); + } + + @Test public void testSetAllTOnEmptyToEmpty() { + makeEmpty(); + wrapper.setAllT(wrapper.newInstance().createEmptyArray()); + assertUnchanged(); + assertEquals(0, array.size()); + } + + @Test (expected = NullPointerException.class) + public void testSetAllTToNull() { + try { + wrapper.setAllT(null); + } finally { + assertUnchanged(); + } + } + + @Test public void testSetAllTSelf() { + + wrapper.setAllT(array); + + mao.check0(); + Object actual = wrapper.toArray(null); + assertEquals(initialSize, array.size()); + assertEquals(initialSize, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, initialSize, initialElements, 0); + } + + @Test public void testSetAllTSelfEmpty() { + makeEmpty(); + + wrapper.setAllT(array); + + mao.check0(); + Object actual = wrapper.toArray(null); + assertEquals(0, array.size()); + assertEquals(0, wrapper.arrayLength(actual)); + } + + // ========== setAll(primitive array, range) tests ========== + + private void testSetAllARange(boolean sizeChanged, int newSize, int srcIndex, int length) { + Object expected = wrapper.createPrimitiveArray(newSize); + + wrapper.setAllA(expected, srcIndex, length); + + mao.check(array, sizeChanged, 0, length); + Object actual = wrapper.toArray(null); + assertEquals(length, array.size()); + assertEquals(length, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, length, expected, srcIndex); + } + + @Test public void testSetAllARange1() { + testSetAllARange(false, INITIAL_SIZE, 0, INITIAL_SIZE); + } + + @Test public void testSetAllARange2() { + testSetAllARange(false, INITIAL_SIZE + 10, 0, INITIAL_SIZE); + } + + @Test public void testSetAllARange3() { + testSetAllARange(false, INITIAL_SIZE + 10, 10, INITIAL_SIZE); + } + + @Test public void testSetAllARange4() { + testSetAllARange(false, INITIAL_SIZE + 10, 2, INITIAL_SIZE); + } + + @Test public void testSetAllARange5() { + testSetAllARange(true, INITIAL_SIZE, 0, INITIAL_SIZE / 2); + } + + @Test public void testSetAllARange6() { + testSetAllARange(true, INITIAL_SIZE + 10, 0, INITIAL_SIZE + 10); + } + + @Test public void testSetAllARange7() { + testSetAllARange(true, INITIAL_SIZE + 20, 10, INITIAL_SIZE + 10); + } + + @Test public void testSetAllARange8() { + testSetAllARange(true, INITIAL_SIZE + 10, 2, INITIAL_SIZE - 3); + } + + @Test public void testSetAllARangeOnEmpty() { + makeEmpty(); + testSetAllARange(true, INITIAL_SIZE, 1, 3); + } + + @Test public void testSetAllARangeOnEmptyToEmpty() { + makeEmpty(); + wrapper.setAllA(wrapper.createPrimitiveArray(INITIAL_SIZE), 1, 0); + assertUnchanged(); + } + + @Test (expected = NullPointerException.class) + public void testSetAllARangeToNull() { + try { + wrapper.setAllA(null, 0, 0); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllARangeNegative1() { + try { + testSetAllARange(true, INITIAL_SIZE, -1, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllARangeNegative2() { + try { + testSetAllARange(true, INITIAL_SIZE, 0, INITIAL_SIZE + 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllARangeNegative3() { + try { + testSetAllARange(true, INITIAL_SIZE, 1, -1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllARangeNegative4() { + try { + testSetAllARange(true, INITIAL_SIZE, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + // ========== setAll(observable array, range) tests ========== + + private void testSetAllTRange(boolean sizeChanged, int srcSize, int srcIndex, int length) { + Object expected = wrapper.createPrimitiveArray(srcSize); + ObservableArray src = wrapper.newInstance().createNotEmptyArray(expected); + + wrapper.setAllT(src, srcIndex, length); + + mao.check(array, sizeChanged, 0, length); + Object actual = wrapper.toArray(null); + assertEquals(length, array.size()); + assertEquals(length, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, length, expected, srcIndex); + } + + @Test public void testSetAllTRange1() { + testSetAllTRange(false, INITIAL_SIZE, 0, INITIAL_SIZE); + } + + @Test public void testSetAllTRange2() { + testSetAllTRange(false, INITIAL_SIZE + 10, 0, INITIAL_SIZE); + } + + @Test public void testSetAllTRange3() { + testSetAllTRange(false, INITIAL_SIZE + 10, 10, INITIAL_SIZE); + } + + @Test public void testSetAllTRange4() { + testSetAllTRange(false, INITIAL_SIZE + 10, 2, INITIAL_SIZE); + } + + @Test public void testSetAllTRange5() { + testSetAllTRange(true, INITIAL_SIZE, 0, INITIAL_SIZE / 2); + } + + @Test public void testSetAllTRange6() { + testSetAllTRange(true, INITIAL_SIZE + 10, 0, INITIAL_SIZE + 10); + } + + @Test public void testSetAllTRange7() { + testSetAllTRange(true, INITIAL_SIZE + 20, 10, INITIAL_SIZE + 10); + } + + @Test public void testSetAllTRange8() { + testSetAllTRange(true, INITIAL_SIZE + 10, 2, INITIAL_SIZE - 3); + } + + @Test public void testSetAllTRangeOnEmpty() { + makeEmpty(); + testSetAllTRange(true, INITIAL_SIZE, 1, 3); + } + + @Test public void testSetAllTRangeOnEmptyToEmpty() { + makeEmpty(); + wrapper.setAllT(wrapper.newInstance().createNotEmptyArray(wrapper.createPrimitiveArray(INITIAL_SIZE)), 1, 0); + assertUnchanged(); + } + + @Test (expected = NullPointerException.class) + public void testSetAllTRangeToNull() { + try { + wrapper.setAllT(null, 0, 0); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeNegative1() { + try { + testSetAllTRange(true, INITIAL_SIZE, -1, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeNegative2() { + try { + testSetAllTRange(true, INITIAL_SIZE, 0, INITIAL_SIZE + 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeNegative3() { + try { + testSetAllTRange(true, INITIAL_SIZE, 1, -1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeNegative4() { + try { + testSetAllTRange(true, INITIAL_SIZE, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeNegativeAfterSrcEnsureCapacity() { + Object expected = wrapper.createPrimitiveArray(INITIAL_SIZE); + ObservableArray src = wrapper.newInstance().createNotEmptyArray(expected); + src.ensureCapacity(INITIAL_SIZE * 2); + try { + wrapper.setAllT(src, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeNegativeAfterSrcClear() { + Object expected = wrapper.createPrimitiveArray(INITIAL_SIZE); + ObservableArray src = wrapper.newInstance().createNotEmptyArray(expected); + src.clear(); + try { + wrapper.setAllT(src, 0, 1); + } finally { + assertUnchanged(); + } + } + + private void testSetAllTRangeSelf(boolean sizeChanged, int srcIndex, int length) { + + wrapper.setAllT(array, srcIndex, length); + + if (srcIndex == 0) { + if (length == initialSize) { + mao.check0(); + } else { + mao.checkOnlySizeChanged(array); + } + } else { + mao.check(array, sizeChanged, 0, length); + } + Object actual = wrapper.toArray(null); + assertEquals(length, array.size()); + assertEquals(length, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, length, initialElements, srcIndex); + } + + @Test public void testSetAllTRangeSelf() { + testSetAllTRangeSelf(true, 0, INITIAL_SIZE); + } + + @Test public void testSetAllTRangeSelfBeginning() { + testSetAllTRangeSelf(true, 0, INITIAL_SIZE / 2); + } + + @Test public void testSetAllTRangeSelfTrailing() { + testSetAllTRangeSelf(true, INITIAL_SIZE / 2, INITIAL_SIZE / 2); + } + + @Test public void testSetAllTRangeSelfMiddle() { + testSetAllTRangeSelf(true, 3, 2); + } + + @Test public void testSetAllTRangeSelfEmpty() { + makeEmpty(); + testSetAllTRangeSelf(false, 0, 0); + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeSelfNegative1() { + try { + wrapper.setAllT(array, -1, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeSelfNegative2() { + try { + wrapper.setAllT(array, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeSelfNegative3() { + try { + wrapper.setAllT(array, 0, -1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeSelfNegative4() { + try { + wrapper.setAllT(array, 0, INITIAL_SIZE + 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeSelfNegativeAfterEnsureCapacity() { + array.ensureCapacity(INITIAL_SIZE * 2); + try { + wrapper.setAllT(array, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetAllTRangeSelfNegativeAfterClear() { + makeEmpty(); + try { + wrapper.setAllT(array, 0, 1); + } finally { + assertUnchanged(); + } + } + + // ========== addAll(primitive array) tests ========== + + private void testAddAllA(int srcSize) { + Object src = wrapper.createPrimitiveArray(srcSize); + int oldSize = array.size(); + + wrapper.addAllA(src); + + int newSize = oldSize + srcSize; + boolean sizeChanged = newSize != oldSize; + mao.check(array, sizeChanged, oldSize, newSize); + Object actual = wrapper.toArray(null); + assertEquals(newSize, array.size()); + assertEquals(newSize, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, oldSize, initialElements, 0); + wrapper.assertElementsEqual(actual, oldSize, newSize, src, 0); + } + + @Test public void testAddAllA0() { + wrapper.addAllA(wrapper.createPrimitiveArray(0)); + assertUnchanged(); + } + + @Test public void testAddAllA1() { + testAddAllA(1); + } + + @Test public void testAddAllA3() { + testAddAllA(3); + } + + @Test public void testAddAllABig() { + testAddAllA(INITIAL_SIZE * 2); + } + + @Test public void testAddAllASameSize() { + testAddAllA(INITIAL_SIZE); + } + + @Test public void testAddAllAOnEmpty1() { + makeEmpty(); + testAddAllA(1); + } + + @Test public void testAddAllAOnEmptySameSize() { + makeEmpty(); + testAddAllA(INITIAL_SIZE); + } + + @Test public void testAddAllAOnEmptyBig() { + makeEmpty(); + testAddAllA(INITIAL_SIZE * 3); + } + + @Test public void testAddAllAOnEmpty0() { + makeEmpty(); + wrapper.addAllA(wrapper.createPrimitiveArray(0)); + assertUnchanged(); + } + + @Test (expected = NullPointerException.class) + public void testAddAllANull() { + try { + wrapper.addAllA(null); + } finally { + assertUnchanged(); + } + } + + @Test public void testAddAllAManyPoints() { + for (int i = 0; i < 65_000; i++) { + wrapper.addAllA(wrapper.createPrimitiveArray(3)); + } + } + + // ========== addAll(ObservableArray) tests ========== + + private void testAddAllT(int srcSize) { + Object src = wrapper.createPrimitiveArray(srcSize); + int oldSize = array.size(); + + wrapper.addAllT(wrapper.newInstance().createNotEmptyArray(src)); + + int newSize = oldSize + srcSize; + boolean sizeChanged = newSize != oldSize; + mao.check(array, sizeChanged, oldSize, newSize); + Object actual = wrapper.toArray(null); + assertEquals(newSize, array.size()); + assertEquals(newSize, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, oldSize, initialElements, 0); + wrapper.assertElementsEqual(actual, oldSize, newSize, src, 0); + } + + @Test public void testAddAllT0() { + wrapper.addAllT(wrapper.newInstance().createEmptyArray()); + assertUnchanged(); + } + + @Test public void testAddAllT1() { + testAddAllT(1); + } + + @Test public void testAddAllT3() { + testAddAllT(3); + } + + @Test public void testAddAllTBig() { + testAddAllT(INITIAL_SIZE * 2); + } + + @Test public void testAddAllTSameSize() { + testAddAllT(INITIAL_SIZE); + } + + @Test public void testAddAllTOnEmpty1() { + makeEmpty(); + testAddAllT(1); + } + + @Test public void testAddAllTOnEmptySameSize() { + makeEmpty(); + testAddAllT(INITIAL_SIZE); + } + + @Test public void testAddAllTOnEmptyBig() { + makeEmpty(); + testAddAllT(INITIAL_SIZE * 3); + } + + @Test public void testAddAllTOnEmpty0() { + makeEmpty(); + wrapper.addAllT(wrapper.newInstance().createEmptyArray()); + assertUnchanged(); + } + + @Test (expected = NullPointerException.class) + public void testAddAllTNull() { + try { + wrapper.addAllT(null); + } finally { + assertUnchanged(); + } + } + + @Test public void testAddAllTSelf() { + wrapper.addAllT(array); + + mao.check(array, true, initialSize, initialSize * 2); + assertEquals(initialSize * 2, array.size()); + Object actual = wrapper.toArray(null); + wrapper.assertElementsEqual(actual, 0, initialSize, initialElements, 0); + wrapper.assertElementsEqual(actual, initialSize, initialSize * 2, initialElements, 0); + } + + @Test public void testAddAllTSelfEmpty() { + makeEmpty(); + + wrapper.addAllT(array); + + mao.check0(); + Object actual = wrapper.toArray(null); + assertEquals(0, array.size()); + assertEquals(0, wrapper.arrayLength(actual)); + } + + @Test public void testAddAllTManyPoints() { + for (int i = 0; i < 65_000; i++) { + wrapper.addAllT(wrapper.createNotEmptyArray(wrapper.createPrimitiveArray(3))); + } + } + + // ========== addAll(primitive array, range) tests ========== + + private void testAddAllARange(int srcSize, int srcIndex, int length) { + Object src = wrapper.createPrimitiveArray(srcSize); + int oldSize = array.size(); + + wrapper.addAllA(src, srcIndex, length); + + int newSize = oldSize + length; + boolean sizeChanged = newSize != oldSize; + + mao.check(array, sizeChanged, oldSize, newSize); + Object actual = wrapper.toArray(null); + assertEquals(newSize, array.size()); + assertEquals(newSize, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, oldSize, initialElements, 0); + wrapper.assertElementsEqual(actual, oldSize, newSize, src, srcIndex); + } + + @Test public void testAddAllARange1() { + testAddAllARange(INITIAL_SIZE, 0, INITIAL_SIZE); + } + + @Test public void testAddAllARange2() { + testAddAllARange(INITIAL_SIZE + 10, 0, INITIAL_SIZE); + } + + @Test public void testAddAllARange3() { + testAddAllARange(INITIAL_SIZE + 10, 10, INITIAL_SIZE); + } + + @Test public void testAddAllARange4() { + testAddAllARange(INITIAL_SIZE + 10, 2, INITIAL_SIZE); + } + + @Test public void testAddAllARange5() { + testAddAllARange(INITIAL_SIZE, 0, INITIAL_SIZE / 2); + } + + @Test public void testAddAllARange6() { + testAddAllARange(INITIAL_SIZE + 10, 0, INITIAL_SIZE + 10); + } + + @Test public void testAddAllARange7() { + testAddAllARange(INITIAL_SIZE + 20, 10, INITIAL_SIZE + 10); + } + + @Test public void testAddAllARange8() { + testAddAllARange(INITIAL_SIZE + 10, 2, INITIAL_SIZE - 3); + } + + @Test public void testAddAllARangeOnEmpty1() { + makeEmpty(); + testAddAllARange(INITIAL_SIZE, 1, 3); + } + + @Test public void testAddAllARangeOnEmpty2() { + makeEmpty(); + testAddAllARange(INITIAL_SIZE * 3, INITIAL_SIZE, INITIAL_SIZE * 2); + } + + @Test public void testAddAllARangeOnEmpty3() { + makeEmpty(); + wrapper.addAllA(wrapper.createPrimitiveArray(INITIAL_SIZE), 1, 0); + assertUnchanged(); + } + + @Test (expected = NullPointerException.class) + public void testAddAllARangeNull() { + try { + wrapper.addAllA(null, 0, 0); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllARangeNegative1() { + try { + testAddAllARange(INITIAL_SIZE, -1, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllARangeNegative2() { + try { + testAddAllARange(INITIAL_SIZE, 0, INITIAL_SIZE + 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllARangeNegative3() { + try { + testAddAllARange(INITIAL_SIZE, 1, -1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllARangeNegative4() { + try { + testAddAllARange(INITIAL_SIZE, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + // ========== addAll(observable array, range) tests ========== + + private void testAddAllTRange(int srcSize, int srcIndex, int length) { + Object src = wrapper.createPrimitiveArray(srcSize); + int oldSize = array.size(); + + wrapper.addAllT(wrapper.newInstance().createNotEmptyArray(src), srcIndex, length); + + int newSize = oldSize + length; + boolean sizeChanged = newSize != oldSize; + + mao.check(array, sizeChanged, oldSize, newSize); + Object actual = wrapper.toArray(null); + assertEquals(newSize, array.size()); + assertEquals(newSize, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, oldSize, initialElements, 0); + wrapper.assertElementsEqual(actual, oldSize, newSize, src, srcIndex); + } + + @Test public void testAddAllTRange1() { + testAddAllTRange(INITIAL_SIZE, 0, INITIAL_SIZE); + } + + @Test public void testAddAllTRange2() { + testAddAllTRange(INITIAL_SIZE + 10, 0, INITIAL_SIZE); + } + + @Test public void testAddAllTRange3() { + testAddAllTRange(INITIAL_SIZE + 10, 10, INITIAL_SIZE); + } + + @Test public void testAddAllTRange4() { + testAddAllTRange(INITIAL_SIZE + 10, 2, INITIAL_SIZE); + } + + @Test public void testAddAllTRange5() { + testAddAllTRange(INITIAL_SIZE, 0, INITIAL_SIZE / 2); + } + + @Test public void testAddAllTRange6() { + testAddAllTRange(INITIAL_SIZE + 10, 0, INITIAL_SIZE + 10); + } + + @Test public void testAddAllTRange7() { + testAddAllTRange(INITIAL_SIZE + 20, 10, INITIAL_SIZE + 10); + } + + @Test public void testAddAllTRange8() { + testAddAllTRange(INITIAL_SIZE + 10, 2, INITIAL_SIZE - 3); + } + + @Test public void testAddAllTRangeOnEmpty1() { + makeEmpty(); + testAddAllTRange(INITIAL_SIZE, 1, 3); + } + + @Test public void testAddAllTRangeOnEmpty2() { + makeEmpty(); + testAddAllTRange(INITIAL_SIZE * 3, INITIAL_SIZE, INITIAL_SIZE * 2); + } + + @Test public void testAddAllTRangeOnEmpty3() { + makeEmpty(); + wrapper.addAllT(wrapper.newInstance().createNotEmptyArray(wrapper.createPrimitiveArray(INITIAL_SIZE)), 1, 0); + assertUnchanged(); + } + + @Test (expected = NullPointerException.class) + public void testAddAllTRangeNull() { + try { + wrapper.addAllT(null, 0, 0); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeNegative1() { + try { + testAddAllTRange(INITIAL_SIZE, -1, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeNegative2() { + try { + testAddAllTRange(INITIAL_SIZE, 0, INITIAL_SIZE + 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeNegative3() { + try { + testAddAllTRange(INITIAL_SIZE, 1, -1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeNegative4() { + try { + testAddAllTRange(INITIAL_SIZE, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeNegativeAfterSrcEnsureCapacity() { + Object srcA = wrapper.createPrimitiveArray(INITIAL_SIZE); + ObservableArray src = wrapper.newInstance().createNotEmptyArray(srcA); + src.ensureCapacity(INITIAL_SIZE * 2); + try { + wrapper.addAllT(src, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeNegativeAfterSrcClear() { + Object srcA = wrapper.createPrimitiveArray(INITIAL_SIZE); + ObservableArray src = wrapper.newInstance().createNotEmptyArray(srcA); + src.clear(); + try { + wrapper.addAllT(src, 0, 1); + } finally { + assertUnchanged(); + } + } + + private void testAddAllTRangeSelf(int srcIndex, int length) { + wrapper.addAllT(array, srcIndex, length); + + int expSize = initialSize + length; + mao.check(array, true, initialSize, expSize); + Object actual = wrapper.toArray(null); + assertEquals(expSize, array.size()); + assertEquals(expSize, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, initialSize, initialElements, 0); + wrapper.assertElementsEqual(actual, initialSize, expSize, initialElements, srcIndex); + } + + @Test public void testAddAllTRangeSelf() { + testAddAllTRangeSelf(0, INITIAL_SIZE); + } + + @Test public void testAddAllTRangeSelfBeginning() { + testAddAllTRangeSelf(0, INITIAL_SIZE / 2); + } + + @Test public void testAddAllTRangeSelfTrailing() { + testAddAllTRangeSelf(INITIAL_SIZE / 2, INITIAL_SIZE / 2); + } + + @Test public void testAddAllTRangeSelfMiddle() { + testAddAllTRangeSelf(2, 2); + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeSelfNegative1() { + try { + testAddAllTRangeSelf(-1, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeSelfNegative2() { + try { + testAddAllTRangeSelf(0, INITIAL_SIZE + 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeSelfNegative3() { + try { + testAddAllTRangeSelf(1, -1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeSelfNegative4() { + try { + testAddAllTRangeSelf(INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeSelfNegativeAfterEnsureCapacity() { + array.ensureCapacity(INITIAL_SIZE * 2); + try { + wrapper.addAllT(array, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testAddAllTRangeSelfNegativeAfterClear() { + makeEmpty(); + try { + wrapper.addAllT(array, 0, 1); + } finally { + assertUnchanged(); + } + } + + // ========== set(primitive array, range) tests ========== + + private void testSetARange(int srcLength, int destIndex, int srcIndex, int length) { + Object expected = wrapper.createPrimitiveArray(srcLength); + + wrapper.setA(destIndex, expected, srcIndex, length); + + mao.checkOnlyElementsChanged(array, destIndex, destIndex + length); + Object actual = wrapper.toArray(null); + assertEquals(INITIAL_SIZE, array.size()); + assertEquals(INITIAL_SIZE, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, destIndex, initialElements, 0); + wrapper.assertElementsEqual(actual, destIndex, destIndex + length, expected, srcIndex); + wrapper.assertElementsEqual(actual, destIndex + length, INITIAL_SIZE, initialElements, destIndex + length); + } + + @Test public void testSetARange1() { + testSetARange(5, 0, 0, 5); + } + + @Test public void testSetARange2() { + testSetARange(3, 2, 0, 3); + } + + @Test public void testSetARange3() { + testSetARange(5, 0, 2, 3); + } + + @Test public void testSetARange4() { + testSetARange(5, 0, 0, 3); + } + + @Test public void testSetARange5() { + testSetARange(10, 3, 5, 3); + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetARangeNegative1() { + try { + testSetARange(10, -1, 0, 3); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetARangeNegative2() { + try { + testSetARange(10, 0, -1, 3); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetARangeNegative3() { + try { + testSetARange(10, 1, 1, -1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetARangeNegative4() { + try { + testSetARange(10, INITIAL_SIZE, 0, 3); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetARangeNegative5() { + try { + testSetARange(10, 0, 10, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetARangeNegative6() { + try { + testSetARange(3, 0, 1, 4); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetARangeNegative7() { + try { + testSetARange(10, INITIAL_SIZE - 3, 0, 4); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetARangeNegativeAfterEnsureCapacity() { + array.ensureCapacity(INITIAL_SIZE * 2); + try { + testSetARange(1, INITIAL_SIZE, 0, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetARangeNegativeAfterClear() { + makeEmpty(); + try { + testSetARange(1, 0, 0, 1); + } finally { + assertUnchanged(); + } + } + + // ========== set(ObservableArray, range) tests ========== + + private void testSetTRange(int srcLength, int destIndex, int srcIndex, int length) { + Object expected = wrapper.createPrimitiveArray(srcLength); + ObservableArray src = wrapper.newInstance().createNotEmptyArray(expected); + + wrapper.setT(destIndex, src, srcIndex, length); + + mao.checkOnlyElementsChanged(array, destIndex, destIndex + length); + Object actual = wrapper.toArray(null); + assertEquals(INITIAL_SIZE, array.size()); + assertEquals(INITIAL_SIZE, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, destIndex, initialElements, 0); + wrapper.assertElementsEqual(actual, destIndex, destIndex + length, expected, srcIndex); + wrapper.assertElementsEqual(actual, destIndex + length, initialSize, initialElements, destIndex + length); + } + + @Test public void testSetTRange1() { + testSetTRange(5, 0, 0, 5); + } + + @Test public void testSetTRange2() { + testSetTRange(3, 2, 0, 3); + } + + @Test public void testSetTRange3() { + testSetTRange(5, 0, 2, 3); + } + + @Test public void testSetTRange4() { + testSetTRange(5, 0, 0, 3); + } + + @Test public void testSetTRange5() { + testSetTRange(10, 3, 5, 3); + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeNegative1() { + try { + testSetTRange(10, -1, 0, 3); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeNegative2() { + try { + testSetTRange(10, 0, -1, 3); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeNegative3() { + try { + testSetTRange(10, 1, 1, -1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeNegative4() { + try { + testSetTRange(10, INITIAL_SIZE, 0, 3); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeNegative5() { + try { + testSetTRange(10, 0, 10, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeNegative6() { + try { + testSetTRange(3, 0, 1, 4); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeNegative7() { + try { + testSetTRange(10, INITIAL_SIZE - 3, 0, 4); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeNegativeAfterEnsureCapacity() { + array.ensureCapacity(INITIAL_SIZE * 2); + try { + testSetTRange(1, INITIAL_SIZE, 0, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeNegativeAfterClear() { + makeEmpty(); + try { + testSetTRange(1, 0, 0, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeNegativeAfterSrcEnsureCapacity() { + try { + Object srcA = wrapper.createPrimitiveArray(1); + ObservableArray src = wrapper.newInstance().createNotEmptyArray(srcA); + src.ensureCapacity(2); + + wrapper.setT(0, src, 1, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeNegativeAfterSrcClear() { + try { + Object srcA = wrapper.createPrimitiveArray(1); + ObservableArray src = wrapper.newInstance().createNotEmptyArray(srcA); + src.clear(); + + wrapper.setT(0, src, 0, 1); + } finally { + assertUnchanged(); + } + } + + private void testSetTRangeSelf(int destIndex, int srcIndex, int length) { + + wrapper.setT(destIndex, array, srcIndex, length); + + mao.checkOnlyElementsChanged(array, destIndex, destIndex + length); + Object actual = wrapper.toArray(null); + assertEquals(INITIAL_SIZE, array.size()); + assertEquals(INITIAL_SIZE, wrapper.arrayLength(actual)); + wrapper.assertElementsEqual(actual, 0, destIndex, initialElements, 0); + wrapper.assertElementsEqual(actual, destIndex, destIndex + length, initialElements, srcIndex); + wrapper.assertElementsEqual(actual, destIndex + length, initialSize, initialElements, destIndex + length); + } + + @Test public void testSetTRangeSelf() { + testSetTRangeSelf(0, 0, INITIAL_SIZE); + } + + @Test public void testSetTRangeSelfLeft() { + testSetTRangeSelf(0, 1, INITIAL_SIZE - 1); + } + + @Test public void testSetTRangeSelfRight() { + testSetTRangeSelf(1, 0, INITIAL_SIZE - 1); + } + + @Test public void testSetTRangeSelfRightDifferentParts() { + testSetTRangeSelf(0, INITIAL_SIZE / 2, INITIAL_SIZE / 2); + } + + @Test public void testSetTRangeSelfLeftDifferentParts() { + testSetTRangeSelf(INITIAL_SIZE / 2, 0, INITIAL_SIZE / 2); + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeSelfNegative1() { + try { + wrapper.setT(-1, array, 0, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeSelfNegative2() { + try { + wrapper.setT(0, array, -1, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeSelfNegative3() { + try { + wrapper.setT(0, array, 0, INITIAL_SIZE + 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeSelfNegative4() { + try { + wrapper.setT(0, array, 1, -1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeSelfNegative5() { + try { + wrapper.setT(INITIAL_SIZE, array, 0, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeSelfNegative6() { + try { + wrapper.setT(0, array, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeSelfNegativeAfterEnsureCapacity() { + try { + array.ensureCapacity(INITIAL_SIZE * 2); + + wrapper.setT(0, array, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetTRangeSelfNegativeAfterClear() { + makeEmpty(); + try { + wrapper.setT(0, array, 0, 1); + } finally { + assertUnchanged(); + } + } + + + // ========== negative get(index) tests ========== + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testGetNegative() { + try { + wrapper.get(-1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testGetOutOfBounds() { + try { + wrapper.get(array.size()); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testGetAfterEnsureCapacity() { + try { + array.ensureCapacity(INITIAL_SIZE * 2); + wrapper.get(INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testGetAfterClear() { + makeEmpty(); + try { + wrapper.get(0); + } finally { + assertUnchanged(); + } + } + + // ================== set(index) tests =============== + + @Test public void testSetValue() { + for (int i = 0; i < INITIAL_SIZE; i++) { + Object expected = wrapper.getNextValue(); + + wrapper.set(i, expected); + + mao.check(array, false, i, i + 1); + mao.reset(); + assertEquals(expected, wrapper.get(i)); + assertEquals(INITIAL_SIZE, array.size()); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetValueNegative() { + try { + wrapper.set(-1, wrapper.getNextValue()); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetValueOutOfBounds() { + try { + wrapper.set(INITIAL_SIZE, wrapper.getNextValue()); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetValueNegativeAfterClear() { + makeEmpty(); + try { + wrapper.set(0, wrapper.getNextValue()); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testSetValueNegativeAfterEnsureCapacity() { + array.ensureCapacity(INITIAL_SIZE * 2); + try { + wrapper.set(INITIAL_SIZE, wrapper.getNextValue()); + } finally { + assertUnchanged(); + } + } + + // ================= toArray(array) tests ====================== + + private void testToArray(int arraySize, boolean same) { + Object param = wrapper.createPrimitiveArray(arraySize); + Object actual = wrapper.toArray(param); + assertUnchanged(); + if (same) { + assertSame(param, actual); + } else { + assertNotSame(param, actual); + assertEquals(array.size(), wrapper.arrayLength(actual)); + } + wrapper.assertElementsEqual(actual, 0, array.size(), wrapper.toArray(null), 0); + } + + @Test public void testToArraySameSize() { + testToArray(array.size(), true); + } + + @Test public void testToArraySmaller() { + testToArray(3, false); + } + + @Test public void testToArrayBigger() { + testToArray(10, true); + } + + @Test public void testToArrayEmpty() { + makeEmpty(); + testToArray(10, true); + } + + @Test public void testToArrayEmptyToEmpty() { + makeEmpty(); + testToArray(0, true); + } + + // ============ toArray range tests ========================= + + private void testToArrayRange(int srcIndex, int destSize, int length) { + Object dest = wrapper.createPrimitiveArray(destSize); + Object initial = wrapper.clonePrimitiveArray(dest); + Object actual = wrapper.toArray(srcIndex, dest, length); + assertUnchanged(); + Object expected = wrapper.toArray(null); + wrapper.assertElementsEqual(actual, 0, length, expected, srcIndex); + wrapper.assertElementsEqual(actual, length, wrapper.arrayLength(actual), initial, length); + } + + @Test public void testToArrayRange0() { + testToArrayRange(0, array.size(), array.size()); + } + + @Test public void testToArrayRange1() { + testToArrayRange(3, array.size(), array.size() - 3); + } + + @Test public void testToArrayRange2() { + testToArrayRange(0, array.size(), array.size() - 3); + } + + @Test public void testToArrayRange3() { + testToArrayRange(2, array.size(), 2); + } + + @Test public void testToArrayRange4() { + testToArrayRange(2, 0, 0); + } + + @Test public void testToArrayRange5() { + makeEmpty(); + testToArrayRange(0, 0, 0); + } + + @Test public void testToArrayRange6() { + testToArrayRange(3, 2, 2); + } + + @Test public void testToArrayRange7() { + testToArrayRange(5, 1, 1); + } + + @Test public void testToArrayRange8() { + testToArrayRange(0, array.size() * 2, array.size()); + } + + @Test public void testToArrayRange9() { + testToArrayRange(0, array.size() - 1, array.size()); + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testToArrayRangeNegative1() { + try { + testToArrayRange(-1, array.size(), 2); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testToArrayRangeNegative2() { + try { + testToArrayRange(array.size(), array.size(), 2); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testToArrayRangeNegative3() { + try { + testToArrayRange(5, array.size(), array.size() + 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testToArrayRangeNegative5() { + makeEmpty(); + try { + testToArrayRange(2, 0, 0); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testToArrayRangeNegativeAfterEnsureCapacity() { + array.ensureCapacity(INITIAL_SIZE * 2); + try { + testToArrayRange(INITIAL_SIZE, 1, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testToArrayRangeNegativeAfterClear() { + makeEmpty(); + try { + testToArrayRange(0, 1, 1); + } finally { + assertUnchanged(); + } + } + + // ============ copyTo(primitive array) tests ========================= + + private void testCopyToA(int srcIndex, int destSize, int destIndex, int length) { + Object actual = wrapper.createPrimitiveArray(destSize); + Object initial = wrapper.clonePrimitiveArray(actual); + wrapper.copyToA(srcIndex, actual, destIndex, length); + assertUnchanged(); + Object expected = wrapper.toArray(null); + wrapper.assertElementsEqual(actual, 0, destIndex, initial, 0); + wrapper.assertElementsEqual(actual, destIndex, destIndex + length, expected, srcIndex); + wrapper.assertElementsEqual(actual, destIndex + length, wrapper.arrayLength(actual), initial, destIndex + length); + } + + @Test public void testCopyToA0() { + testCopyToA(0, array.size(), 0, array.size()); + } + + @Test public void testCopyToA1() { + testCopyToA(1, array.size(), 2, 3); + } + + @Test public void testCopyToA2() { + testCopyToA(2, array.size(), 2, 2); + } + + @Test public void testCopyToA3() { + testCopyToA(0, array.size(), 2, 2); + } + + @Test public void testCopyToA4() { + testCopyToA(0, 3, 1, 2); + } + + @Test public void testCopyToA5() { + testCopyToA(0, array.size() * 3, array.size() * 2, array.size()); + } + + @Test public void testCopyToA6() { + testCopyToA(3, array.size(), 0, array.size() - 3); + } + + @Test public void testCopyToA7() { + testCopyToA(0, 10, 7, 3); + } + + @Test public void testCopyToA8() { + testCopyToA(1, 0, 0, 0); + } + + @Test public void testCopyToA9() { + makeEmpty(); + testCopyToA(0, 0, 0, 0); + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToANegative1() { + try { + testCopyToA(-1, array.size(), 0, array.size()); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToANegative2() { + try { + testCopyToA(0, array.size() / 2, 0, array.size()); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToANegative3() { + try { + testCopyToA(array.size(), array.size(), 0, array.size()); + } finally { + assertUnchanged(); + } + + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToANegative4() { + try { + testCopyToA(0, array.size(), -1, array.size()); + } finally { + assertUnchanged(); + } + + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToANegative5() { + try { + testCopyToA(0, array.size(), array.size(), array.size()); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToANegative6() { + try { + testCopyToA(0, array.size(), 0, array.size() * 2); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToANegative7() { + makeEmpty(); + try { + testCopyToA(1, 0, 0, 0); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToANegative8() { + try { + testCopyToA(0, 0, 1, 0); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToANegativeAfterEnsureCapacity() { + array.ensureCapacity(INITIAL_SIZE * 2); + try { + testCopyToA(INITIAL_SIZE, 1, 0, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToANegativeAfterClear() { + makeEmpty(); + try { + testCopyToA(0, 1, 0, 1); + } finally { + assertUnchanged(); + } + } + + // ============ copyTo(ObservableArray) tests ========================= + + private void testCopyToT(int srcIndex, int destSize, int destIndex, int length) { + ArrayWrapper wrapper2 = wrapper.newInstance(); + Object initial = wrapper2.createPrimitiveArray(destSize); + ObservableArray dest = wrapper2.createNotEmptyArray(initial); + + wrapper.copyToT(srcIndex, dest, destIndex, length); + + assertUnchanged(); + Object expected = wrapper.toArray(null); + Object actual = wrapper2.toArray(null); + wrapper.assertElementsEqual(actual, 0, destIndex, initial, 0); + wrapper.assertElementsEqual(actual, destIndex, destIndex + length, expected, srcIndex); + wrapper.assertElementsEqual(actual, destIndex + length, wrapper.arrayLength(actual), initial, destIndex + length); + } + + @Test public void testCopyToT0() { + testCopyToT(0, array.size(), 0, array.size()); + } + + @Test public void testCopyToT1() { + testCopyToT(1, array.size(), 2, 3); + } + + @Test public void testCopyToT2() { + testCopyToT(2, array.size(), 2, 2); + } + + @Test public void testCopyToT3() { + testCopyToT(0, array.size(), 2, 2); + } + + @Test public void testCopyToT4() { + testCopyToT(0, 3, 1, 2); + } + + @Test public void testCopyToT5() { + testCopyToT(0, array.size() * 3, array.size() * 2, array.size()); + } + + @Test public void testCopyToT6() { + testCopyToT(3, array.size(), 0, array.size() - 3); + } + + @Test public void testCopyToT7() { + testCopyToT(0, 10, 7, 3); + } + + @Test public void testCopyToT8() { + testCopyToT(1, 0, 0, 0); + } + + @Test public void testCopyToT9() { + makeEmpty(); + testCopyToT(0, 0, 0, 0); + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegative1() { + try { + testCopyToT(-1, array.size(), 0, array.size()); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegative2() { + try { + testCopyToT(0, array.size() / 2, 0, array.size()); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegative3() { + try { + testCopyToT(array.size(), array.size(), 0, array.size()); + } finally { + assertUnchanged(); + } + + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegative4() { + try { + testCopyToT(0, array.size(), -1, array.size()); + } finally { + assertUnchanged(); + } + + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegative5() { + try { + testCopyToT(0, array.size(), array.size(), array.size()); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegative6() { + try { + testCopyToT(0, array.size(), 0, array.size() * 2); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegative7() { + makeEmpty(); + try { + testCopyToT(1, 0, 0, 0); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegative8() { + try { + testCopyToT(0, 0, 1, 0); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegativeAfterEnsureCapacity() { + array.ensureCapacity(INITIAL_SIZE * 2); + try { + testCopyToT(INITIAL_SIZE, 1, 0, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegativeAfterClear() { + makeEmpty(); + try { + testCopyToT(0, 1, 0, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegativeAfterDestEnsureCapacity() { + try { + ArrayWrapper wrapper2 = wrapper.newInstance(); + Object destA = wrapper2.createPrimitiveArray(1); + ObservableArray dest = wrapper2.createNotEmptyArray(destA); + dest.ensureCapacity(2); + + wrapper.copyToT(0, dest, 1, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTNegativeAfterDestClear() { + try { + ArrayWrapper wrapper2 = wrapper.newInstance(); + Object destA = wrapper2.createPrimitiveArray(1); + ObservableArray dest = wrapper2.createNotEmptyArray(destA); + dest.clear(); + + wrapper.copyToT(0, dest, 0, 1); + } finally { + assertUnchanged(); + } + } + + private void testCopyToTSelf(int srcIndex, int destIndex, int length) { + + wrapper.copyToT(srcIndex, array, destIndex, length); + + mao.checkOnlyElementsChanged(array, destIndex, destIndex + length); + Object actual = wrapper.toArray(null); + wrapper.assertElementsEqual(actual, 0, destIndex, initialElements, 0); + wrapper.assertElementsEqual(actual, destIndex, destIndex + length, initialElements, srcIndex); + wrapper.assertElementsEqual(actual, destIndex + length, initialSize, initialElements, destIndex + length); + } + + @Test public void testCopyToTSelf() { + testCopyToTSelf(0, 0, INITIAL_SIZE); + } + + @Test public void testCopyToTSelfRight() { + testCopyToTSelf(0, 1, INITIAL_SIZE - 1); + } + + @Test public void testCopyToTSelfLeft() { + testCopyToTSelf(1, 0, INITIAL_SIZE - 1); + } + + @Test public void testCopyToTSelfRightDifferentParts() { + testCopyToTSelf(0, INITIAL_SIZE / 2, INITIAL_SIZE / 2); + } + + @Test public void testCopyToTSelfLeftDifferentParts() { + testCopyToTSelf(INITIAL_SIZE / 2, 0, INITIAL_SIZE / 2); + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTSelfNegative1() { + try { + testCopyToTSelf(-1, 0, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTSelfNegative2() { + try { + testCopyToTSelf(INITIAL_SIZE, 0, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTSelfNegative3() { + try { + testCopyToTSelf(0, -1, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTSelfNegative4() { + try { + testCopyToTSelf(0, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTSelfNegative5() { + try { + testCopyToTSelf(1, 1, -1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTSelfNegative6() { + try { + testCopyToTSelf(0, 1, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTSelfNegative7() { + try { + testCopyToTSelf(1, 0, INITIAL_SIZE); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTSelfNegativeAfterEnsureCapacity() { + array.ensureCapacity(INITIAL_SIZE * 2); + try { + testCopyToTSelf(0, INITIAL_SIZE, 1); + } finally { + assertUnchanged(); + } + } + + @Test (expected = ArrayIndexOutOfBoundsException.class) + public void testCopyToTSelfNegativeAfterClear() { + makeEmpty(); + try { + testCopyToTSelf(0, 0, 1); + } finally { + assertUnchanged(); + } + } + + // ============ ensureCapacity() and trimToSize() tests ==================== + + @Test public void testTrimToSize() { + array.trimToSize(); + assertUnchanged(); + } + + @Test public void testTrimToSizeEmpty() { + makeEmpty(); + array.trimToSize(); + assertUnchanged(); + } + + @Test public void testTrimToSizeResize() { + array.resize(3); + initialSize = 3; + mao.reset(); + + array.trimToSize(); + + assertUnchanged(); + } + + @Test public void testTrimToSizeAddRemove() { + array.resize(1000); + array.resize(INITIAL_SIZE); + mao.reset(); + + array.trimToSize(); + + assertUnchanged(); + } + + @Test public void testEnsureCapacity0() { + array.ensureCapacity(0); + assertUnchanged(); + } + + @Test public void testEnsureCapacityBy1() { + array.ensureCapacity(INITIAL_SIZE + 1); + assertUnchanged(); + } + + @Test public void testEnsureCapacity1000() { + array.ensureCapacity(1000); + assertUnchanged(); + } + + @Test public void testEnsureCapacitySmaller() { + array.ensureCapacity(INITIAL_SIZE / 2); + assertUnchanged(); + } + + @Test public void testEnsureCapacityNegative() { + array.ensureCapacity(-1000); + assertUnchanged(); + } + + @Test public void testEnsureCapacityOnEmpty() { + makeEmpty(); + array.ensureCapacity(100); + assertUnchanged(); + } + + @Test public void testEnsureCapacityOnEmpty0() { + makeEmpty(); + array.ensureCapacity(0); + assertUnchanged(); + } + + @Test public void testEnsureCapacityOnEmptyNegative() { + makeEmpty(); + array.ensureCapacity(-1); + assertUnchanged(); + } + + @Test public void testTrimToSizeEnsureCapacity() { + array.ensureCapacity(1000); + array.trimToSize(); + assertUnchanged(); + } + + // ================= clear() tests ==================== + + @Test public void testClearEmpty() { + makeEmpty(); + array.clear(); + mao.check0(); + assertEquals(0, array.size()); + } + + @Test public void testClear1000() { + array.resize(1000); + mao.reset(); + + array.clear(); + + mao.checkOnlySizeChanged(array); + assertEquals(0, array.size()); + } + + // ================= toString() tests =================== + + @Test public void testToString() { + String actual = array.toString(); + String expected = wrapper.primitiveArrayToString(wrapper.toArray(null)); + assertEquals(expected, actual); + String regex = "\\[[0-9]+(\\.[0-9]+){0,1}(\\, [0-9]+(.[0-9]+){0,1}){" + (initialSize - 1) + "}\\]"; + assertTrue("toString() output matches to regex '" + regex + "'. Actual = '" + actual + "'", + actual.matches(regex)); + } + + @Test public void testToStringAfterResize() { + array.resize(initialSize / 2); + String actual = array.toString(); + String expected = wrapper.primitiveArrayToString(wrapper.toArray(null)); + assertEquals(expected, actual); + String regex = "\\[[0-9]+(\\.[0-9]+){0,1}(\\, [0-9]+(.[0-9]+){0,1}){" + (array.size() - 1) + "}\\]"; + assertTrue("toString() output matches to regex '" + regex + "'. Actual = '" + actual + "'", + actual.matches(regex)); + } + + @Test public void testToStringAfterClear() { + array.clear(); + String actual = array.toString(); + assertEquals("[]", actual); + } +} --- old/modules/base/src/test/java/javafx/collections/ObservableListEmptyTest.java 2015-08-31 10:24:53.613216505 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import java.util.Arrays; -import java.util.Collection; -import org.junit.Before; -import org.junit.Test; - -import java.util.Collections; -import java.util.List; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - * Tests for initially empty ObservableList. - */ -@RunWith(Parameterized.class) -public class ObservableListEmptyTest { - - static final List EMPTY = Collections.emptyList(); - final Callable> listFactory; - ObservableList list; - MockListObserver mlo; - - - public ObservableListEmptyTest(final Callable> listFactory) { - this.listFactory = listFactory; - } - - @Parameterized.Parameters - public static Collection createParameters() { - Object[][] data = new Object[][] { - { TestedObservableLists.ARRAY_LIST }, - { TestedObservableLists.LINKED_LIST }, - { TestedObservableLists.VETOABLE_LIST }, - { TestedObservableLists.CHECKED_OBSERVABLE_ARRAY_LIST }, - { TestedObservableLists.SYNCHRONIZED_OBSERVABLE_ARRAY_LIST } - }; - return Arrays.asList(data); - } - - @Before - public void setUp() throws Exception { - list = listFactory.call(); - mlo = new MockListObserver(); - list.addListener(mlo); - } - - @Test - public void testClearEmpty() { - list = FXCollections.observableList(EMPTY); - list.addListener(mlo); - list.clear(); - mlo.check0(); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/ObservableListEmptyTest.java 2015-08-31 10:24:53.473216507 -0400 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import java.util.Arrays; +import java.util.Collection; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import java.util.List; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + * Tests for initially empty ObservableList. + */ +@RunWith(Parameterized.class) +public class ObservableListEmptyTest { + + static final List EMPTY = Collections.emptyList(); + final Callable> listFactory; + ObservableList list; + MockListObserver mlo; + + + public ObservableListEmptyTest(final Callable> listFactory) { + this.listFactory = listFactory; + } + + @Parameterized.Parameters + public static Collection createParameters() { + Object[][] data = new Object[][] { + { TestedObservableLists.ARRAY_LIST }, + { TestedObservableLists.LINKED_LIST }, + { TestedObservableLists.VETOABLE_LIST }, + { TestedObservableLists.CHECKED_OBSERVABLE_ARRAY_LIST }, + { TestedObservableLists.SYNCHRONIZED_OBSERVABLE_ARRAY_LIST } + }; + return Arrays.asList(data); + } + + @Before + public void setUp() throws Exception { + list = listFactory.call(); + mlo = new MockListObserver(); + list.addListener(mlo); + } + + @Test + public void testClearEmpty() { + list = FXCollections.observableList(EMPTY); + list.addListener(mlo); + list.clear(); + mlo.check0(); + } +} --- old/modules/base/src/test/java/javafx/collections/ObservableListIteratorTest.java 2015-08-31 10:24:54.313216497 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,809 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import org.junit.Before; -import org.junit.Test; - -import java.util.*; - -import static org.junit.Assert.*; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - - -/** - * Tests for iterators of ObservableList. - * - */ -@RunWith(Parameterized.class) -public class ObservableListIteratorTest { - - // ========== Test Fixture ========== - final Callable> listFactory; - List list; - ListIterator iter; - - public ObservableListIteratorTest(final Callable> listFactory) { - this.listFactory = listFactory; - } - - @Parameterized.Parameters - public static Collection createParameters() { - Object[][] data = new Object[][] { - { TestedObservableLists.ARRAY_LIST }, - { TestedObservableLists.LINKED_LIST }, - { TestedObservableLists.VETOABLE_LIST }, - { TestedObservableLists.CHECKED_OBSERVABLE_ARRAY_LIST }, - { TestedObservableLists.SYNCHRONIZED_OBSERVABLE_ARRAY_LIST } - }; - return Arrays.asList(data); - } - - @Before - public void setup() throws Exception { - list = listFactory.call(); - list.addAll(Arrays.asList("a", "b", "c", "d", "e", "f")); - iter = list.listIterator(); - } - - // ========== Utility Functions ========== - - List copyOut(Iterator itr) { - List out = new ArrayList(); - while (itr.hasNext()) { - out.add(itr.next()); - } - return out; - } - - void advance(Iterator itr, int count) { - for (int i = 0; i < count; i += 1) { - itr.next(); - } - } - - void toEnd(Iterator itr) { - while (itr.hasNext()) { - itr.next(); - } - } - - void rewind(ListIterator itr) { - while (itr.hasPrevious()) { - itr.previous(); - } - } - - List contents(ListIterator itr) { - rewind(itr); - return copyOut(itr); - } - - // ========== Basic Tests ========== - - @Test - public void testCompleteIteration() { - assertEquals("[a, b, c, d, e, f]", copyOut(iter).toString()); - } - - @Test - public void testBeginningState() { - assertTrue(iter.hasNext()); - assertFalse(iter.hasPrevious()); - assertEquals(-1, iter.previousIndex()); - assertEquals(0, iter.nextIndex()); - } - - @Test - public void testMiddleState() { - advance(iter, 3); - assertTrue(iter.hasNext()); - assertTrue(iter.hasPrevious()); - assertEquals(2, iter.previousIndex()); - assertEquals(3, iter.nextIndex()); - } - - @Test - public void testEndState() { - toEnd(iter); - assertFalse(iter.hasNext()); - assertTrue(iter.hasPrevious()); - assertEquals(5, iter.previousIndex()); - assertEquals(6, iter.nextIndex()); - } - - @Test - public void testSwitchDirections() { - advance(iter, 2); - assertEquals("c", iter.next()); - assertEquals("d", iter.next()); - assertEquals("d", iter.previous()); - assertEquals("c", iter.previous()); - assertEquals("c", iter.next()); - } - - @Test(expected = NoSuchElementException.class) - public void testBoundaryStart() { - iter.previous(); - } - - @Test(expected = NoSuchElementException.class) - public void testBoundaryEnd() { - advance(iter, 6); - iter.next(); - } - - @Test - public void testForEachLoop() { - List output = new ArrayList(); - for (String s : list) { - output.add(s); - } - assertEquals(list.toString(), output.toString()); - } - - // ========== Add Tests ========== - - @Test - public void testAddBeginning() { - iter.add("X"); - - assertEquals(0, iter.previousIndex()); - assertEquals(1, iter.nextIndex()); - assertEquals("a", iter.next()); - assertEquals("[X, a, b, c, d, e, f]", list.toString()); - } - - @Test - public void testAddMiddle() { - advance(iter, 3); - iter.add("X"); - - assertEquals(3, iter.previousIndex()); - assertEquals(4, iter.nextIndex()); - assertEquals("d", iter.next()); - assertEquals("[a, b, c, X, d, e, f]", list.toString()); - } - - @Test - public void testAddEnd() { - advance(iter, 6); - iter.add("X"); - - assertEquals(6, iter.previousIndex()); - assertEquals(7, iter.nextIndex()); - assertFalse(iter.hasNext()); - assertEquals("[a, b, c, d, e, f, X]", list.toString()); - } - - @Test - public void testPreviousAfterAddBeginning() { - iter.add("X"); - assertEquals("X", iter.previous()); - assertEquals(-1, iter.previousIndex()); - assertEquals(0, iter.nextIndex()); - assertEquals("[X, a, b, c, d, e, f]", list.toString()); - } - - @Test - public void testPreviousAfterAddMiddle() { - advance(iter, 3); - iter.add("X"); - assertEquals("X", iter.previous()); - assertEquals(2, iter.previousIndex()); - assertEquals(3, iter.nextIndex()); - assertEquals("[a, b, c, X, d, e, f]", list.toString()); - } - - @Test - public void testPreviousAfterAddEnd() { - advance(iter, 6); - iter.add("X"); - assertEquals("X", iter.previous()); - assertEquals(5, iter.previousIndex()); - assertEquals(6, iter.nextIndex()); - assertEquals("[a, b, c, d, e, f, X]", list.toString()); - } - - @Test - public void testAddMultiple() { - advance(iter, 3); - iter.add("X"); - iter.add("Y"); - iter.add("Z"); - assertEquals(5, iter.previousIndex()); - assertEquals(6, iter.nextIndex()); - assertEquals("d", iter.next()); - assertEquals("d", iter.previous()); - assertEquals("Z", iter.previous()); - assertEquals("[a, b, c, X, Y, Z, d, e, f]", list.toString()); - } - - @Test - public void testAddAfterPrevious() { - advance(iter, 3); - iter.previous(); // c - iter.add("X"); - assertEquals(2, iter.previousIndex()); - assertEquals(3, iter.nextIndex()); - assertEquals("[a, b, X, c, d, e, f]", list.toString()); - } - - @Test - public void testAddAfterRemove() { - advance(iter, 3); - iter.remove(); - iter.add("X"); - assertEquals(2, iter.previousIndex()); - assertEquals(3, iter.nextIndex()); - assertEquals("[a, b, X, d, e, f]", list.toString()); - } - - @Test - public void testAddAfterSet() { - advance(iter, 3); - iter.set("X"); - iter.add("Y"); - assertEquals(3, iter.previousIndex()); - assertEquals(4, iter.nextIndex()); - assertEquals("[a, b, X, Y, d, e, f]", list.toString()); - } - - // ========== Remove Tests ========== - - @Test - public void testRemoveBeginning() { - iter.next(); - iter.remove(); - assertEquals(-1, iter.previousIndex()); - assertEquals(0, iter.nextIndex()); - assertEquals("[b, c, d, e, f]", list.toString()); - } - - @Test - public void testRemoveMiddle() { - advance(iter, 3); - iter.remove(); - assertEquals(1, iter.previousIndex()); - assertEquals(2, iter.nextIndex()); - assertEquals("[a, b, d, e, f]", list.toString()); - } - - @Test - public void testRemoveEnd() { - toEnd(iter); - iter.remove(); - assertEquals(4, iter.previousIndex()); - assertEquals(5, iter.nextIndex()); - assertEquals("[a, b, c, d, e]", list.toString()); - } - - @Test - public void testRemoveAfterPrevious() { - advance(iter, 4); - iter.previous(); // d - iter.previous(); // c - iter.remove(); - assertEquals(1, iter.previousIndex()); - assertEquals(2, iter.nextIndex()); - assertEquals("[a, b, d, e, f]", list.toString()); - } - - @Test - public void testRemoveAfterSet() { - advance(iter, 3); - iter.set("X"); - iter.remove(); - assertEquals(1, iter.previousIndex()); - assertEquals(2, iter.nextIndex()); - assertEquals("[a, b, d, e, f]", list.toString()); - } - - @Test(expected = IllegalStateException.class) - public void testRemoveInitialThrowsException() { - iter.remove(); - } - - @Test - public void testRemoveTwiceThrowsException() { - iter.next(); - iter.remove(); - try { iter.remove(); } catch (IllegalStateException e) {return;} - fail("Expected IllegalStateException"); - } - - @Test - public void testRemoveAfterAddThrowsException() { - iter.next(); - iter.add("X"); - try { iter.remove(); } catch (IllegalStateException e) {return;} - fail("Expected IllegalStateException"); - } - - // ========== Set Tests ========== - - @Test - public void testSetBeginning() { - iter.next(); - iter.set("X"); - assertEquals(0, iter.previousIndex()); - assertEquals(1, iter.nextIndex()); - assertEquals("[X, b, c, d, e, f]", list.toString()); - } - - @Test - public void testSetMiddle() { - advance(iter, 3); - iter.set("X"); - assertEquals(2, iter.previousIndex()); - assertEquals(3, iter.nextIndex()); - assertEquals("[a, b, X, d, e, f]", list.toString()); - } - - @Test - public void testSetEnd() { - toEnd(iter); - iter.set("X"); - assertEquals(5, iter.previousIndex()); - assertEquals(6, iter.nextIndex()); - assertEquals("[a, b, c, d, e, X]", list.toString()); - } - - @Test - public void testSetTwice() { - advance(iter, 3); - iter.set("X"); - assertEquals(2, iter.previousIndex()); - assertEquals(3, iter.nextIndex()); - assertEquals("[a, b, X, d, e, f]", list.toString()); - iter.set("Y"); - assertEquals(2, iter.previousIndex()); - assertEquals(3, iter.nextIndex()); - assertEquals("[a, b, Y, d, e, f]", list.toString()); - } - - @Test - public void testSetAfterPrevious() { - advance(iter, 4); - iter.previous(); // d - iter.previous(); // c - iter.set("X"); - assertEquals(1, iter.previousIndex()); - assertEquals(2, iter.nextIndex()); - assertEquals("[a, b, X, d, e, f]", list.toString()); - } - - @Test - public void testSetInitialThrowsException() { - try { iter.set("X"); } catch (IllegalStateException e) {return;} - fail("Expected IllegalStateException"); - } - - @Test - public void testSetAfterAddThrowsException() { - iter.next(); - iter.add("X"); - try { iter.set("Y"); } catch (IllegalStateException e) {return;} - fail("Expected IllegalStateException"); - } - - @Test - public void testSetAfterRemoveThrowsException() { - iter.next(); - iter.remove(); - try { iter.set("X"); } catch (IllegalStateException e) {return;} - fail("Expected IllegalStateException"); - } - - // ========== Positioned Iterator Tests ========== - - @Test - public void testPosBeginning() { - iter = list.listIterator(0); - assertFalse(iter.hasPrevious()); - assertTrue(iter.hasNext()); - assertEquals(-1, iter.previousIndex()); - assertEquals(0, iter.nextIndex()); - assertEquals("a", iter.next()); - } - - @Test - public void testPosMiddle() { - iter = list.listIterator(3); - assertTrue(iter.hasPrevious()); - assertTrue(iter.hasNext()); - assertEquals(2, iter.previousIndex()); - assertEquals(3, iter.nextIndex()); - assertEquals("d", iter.next()); - } - - @Test - public void testPosEnd() { - iter = list.listIterator(6); - assertTrue(iter.hasPrevious()); - assertFalse(iter.hasNext()); - assertEquals(5, iter.previousIndex()); - assertEquals(6, iter.nextIndex()); - assertEquals("f", iter.previous()); - } - - @Test - public void testPosAdd() { - iter = list.listIterator(3); - iter.add("X"); - assertEquals(3, iter.previousIndex()); - assertEquals(4, iter.nextIndex()); - assertEquals("[a, b, c, X, d, e, f]", list.toString()); - } - - @Test - public void testPosInitialRemoveThrowsException() { - iter = list.listIterator(3); - try { iter.remove(); } catch (IllegalStateException e) {return;} - fail("Expected IllegalStateException"); - } - - @Test - public void testPosInitialSetThrowsException() { - iter = list.listIterator(3); - try { iter.set("X"); } catch (IllegalStateException e) {return;} - fail("Expected IllegalStateException"); - } - - // ========== Concurrency Tests ========== - - @Test - public void testConcurrencyAddIteratorNext() { - iter = list.listIterator(); - list.add("aa"); - try { iter.next(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddIndexedIteratorNext() { - iter = list.listIterator(); - list.add(1, "aa"); - try { iter.next(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyRemoveIteratorNext() { - iter = list.listIterator(); - list.remove("b"); - try { iter.next(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRemoveIndexedIteratorNext() { - iter = list.listIterator(); - list.remove(2); - try { iter.next(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddAllIteratorNext() { - iter = list.listIterator(); - list.addAll(Collections.singleton("f")); - try { iter.next(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddAllIndexedIteratorNext() { - iter = list.listIterator(); - list.addAll(1, Collections.singleton("f")); - try { iter.next(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyGetIteratorNext() { - iter = list.listIterator(); - list.get(2); - iter.next(); - } - - @Test - public void testConcurrencyRemoveAllIteratorNext() { - iter = list.listIterator(); - list.removeAll(Arrays.asList("a", "c")); - try { iter.next(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRetainAllIteratorNext() { - iter = list.listIterator(); - list.retainAll(Arrays.asList("a", "c")); - try { iter.next(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyIteratorIteratorNext() { - iter = list.listIterator(); - final Iterator iterator = list.iterator(); - iterator.next(); - iterator.remove(); - try { iter.next(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddIteratorPrevious() { - iter = list.listIterator(2); - list.add("aa"); - try { iter.previous(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddIndexedIteratorPrevious() { - iter = list.listIterator(2); - list.add(1, "aa"); - try { iter.previous(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyRemoveIteratorPrevious() { - iter = list.listIterator(2); - list.remove("b"); - try { iter.previous(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRemoveIndexedIteratorPrevious() { - iter = list.listIterator(2); - list.remove(2); - try { iter.previous(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddAllIteratorPrevious() { - iter = list.listIterator(2); - list.addAll(Collections.singleton("f")); - try { iter.previous(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddAllIndexedIteratorPrevious() { - iter = list.listIterator(2); - list.addAll(1, Collections.singleton("f")); - try { iter.previous(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyGetIteratorPrevious() { - iter = list.listIterator(2); - list.get(2); - iter.previous(); - } - - @Test - public void testConcurrencyRemoveAllIteratorPrevious() { - iter = list.listIterator(2); - list.removeAll(Arrays.asList("a", "c")); - try { iter.previous(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRetainAllIteratorPrevious() { - iter = list.listIterator(2); - list.retainAll(Arrays.asList("a", "c")); - try { iter.previous(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyIteratorIteratorPrevious() { - iter = list.listIterator(2); - final Iterator iterator = list.iterator(); - iterator.next(); - iterator.remove(); - try { iter.previous(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyAddIteratorRemove() { - iter = list.listIterator(); - iter.next(); - list.add("aa"); - try { iter.remove(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyAddIndexedIteratorRemove() { - iter = list.listIterator(); - iter.next(); - list.add(1, "aa"); - try { iter.remove(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRemoveIteratorRemove() { - iter = list.listIterator(); - iter.next(); - list.remove("b"); - try { iter.remove(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRemoveIndexedIteratorRemove() { - iter = list.listIterator(); - iter.next(); - list.remove(2); - try { iter.remove(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddAllIteratorRemove() { - iter = list.listIterator(); - iter.next(); - list.addAll(Collections.singleton("f")); - try { iter.remove(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddAllIndexedIteratorRemove() { - iter = list.listIterator(); - iter.next(); - list.addAll(1, Collections.singleton("f")); - try { iter.remove(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyGetIteratorRemove() { - iter = list.listIterator(); - iter.next(); - list.get(2); - iter.remove(); - } - - @Test - public void testConcurrencyRemoveAllIteratorRemove() { - iter = list.listIterator(); - iter.next(); - list.removeAll(Arrays.asList("a", "c")); - try { iter.remove(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRetainAllIteratorRemove() { - iter = list.listIterator(); - iter.next(); - list.retainAll(Arrays.asList("a", "c")); - try { iter.remove(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyIteratorIteratorRemove() { - iter = list.listIterator(); - iter.next(); - final Iterator iterator = list.iterator(); - iterator.next(); - iterator.remove(); - try { iter.remove(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyAddIteratorSet() { - iter = list.listIterator(); - iter.next(); - list.add("aa"); - try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyAddIndexedIteratorSet() { - iter = list.listIterator(); - iter.next(); - list.add(1, "aa"); - try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRemoveIteratorSet() { - iter = list.listIterator(); - iter.next(); - list.remove("b"); - try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRemoveIndexedIteratorSet() { - iter = list.listIterator(); - iter.next(); - list.remove(2); - try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddAllIteratorSet() { - iter = list.listIterator(); - iter.next(); - list.addAll(Collections.singleton("f")); - try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddAllIndexedIteratorSet() { - iter = list.listIterator(); - iter.next(); - list.addAll(1, Collections.singleton("f")); - try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyGetIteratorSet() { - iter = list.listIterator(); - iter.next(); - list.get(2); - iter.set("x"); - } - - @Test - public void testConcurrencyRemoveAllIteratorSet() { - iter = list.listIterator(); - iter.next(); - list.removeAll(Arrays.asList("a", "c")); - try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRetainAllIteratorSet() { - iter = list.listIterator(); - iter.next(); - list.retainAll(Arrays.asList("a", "c")); - try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyIteratorIteratorSet() { - iter = list.listIterator(); - iter.next(); - final Iterator iterator = list.iterator(); - iterator.next(); - iterator.remove(); - try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/ObservableListIteratorTest.java 2015-08-31 10:24:54.101216500 -0400 @@ -0,0 +1,809 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import org.junit.Before; +import org.junit.Test; + +import java.util.*; + +import static org.junit.Assert.*; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + + +/** + * Tests for iterators of ObservableList. + * + */ +@RunWith(Parameterized.class) +public class ObservableListIteratorTest { + + // ========== Test Fixture ========== + final Callable> listFactory; + List list; + ListIterator iter; + + public ObservableListIteratorTest(final Callable> listFactory) { + this.listFactory = listFactory; + } + + @Parameterized.Parameters + public static Collection createParameters() { + Object[][] data = new Object[][] { + { TestedObservableLists.ARRAY_LIST }, + { TestedObservableLists.LINKED_LIST }, + { TestedObservableLists.VETOABLE_LIST }, + { TestedObservableLists.CHECKED_OBSERVABLE_ARRAY_LIST }, + { TestedObservableLists.SYNCHRONIZED_OBSERVABLE_ARRAY_LIST } + }; + return Arrays.asList(data); + } + + @Before + public void setup() throws Exception { + list = listFactory.call(); + list.addAll(Arrays.asList("a", "b", "c", "d", "e", "f")); + iter = list.listIterator(); + } + + // ========== Utility Functions ========== + + List copyOut(Iterator itr) { + List out = new ArrayList(); + while (itr.hasNext()) { + out.add(itr.next()); + } + return out; + } + + void advance(Iterator itr, int count) { + for (int i = 0; i < count; i += 1) { + itr.next(); + } + } + + void toEnd(Iterator itr) { + while (itr.hasNext()) { + itr.next(); + } + } + + void rewind(ListIterator itr) { + while (itr.hasPrevious()) { + itr.previous(); + } + } + + List contents(ListIterator itr) { + rewind(itr); + return copyOut(itr); + } + + // ========== Basic Tests ========== + + @Test + public void testCompleteIteration() { + assertEquals("[a, b, c, d, e, f]", copyOut(iter).toString()); + } + + @Test + public void testBeginningState() { + assertTrue(iter.hasNext()); + assertFalse(iter.hasPrevious()); + assertEquals(-1, iter.previousIndex()); + assertEquals(0, iter.nextIndex()); + } + + @Test + public void testMiddleState() { + advance(iter, 3); + assertTrue(iter.hasNext()); + assertTrue(iter.hasPrevious()); + assertEquals(2, iter.previousIndex()); + assertEquals(3, iter.nextIndex()); + } + + @Test + public void testEndState() { + toEnd(iter); + assertFalse(iter.hasNext()); + assertTrue(iter.hasPrevious()); + assertEquals(5, iter.previousIndex()); + assertEquals(6, iter.nextIndex()); + } + + @Test + public void testSwitchDirections() { + advance(iter, 2); + assertEquals("c", iter.next()); + assertEquals("d", iter.next()); + assertEquals("d", iter.previous()); + assertEquals("c", iter.previous()); + assertEquals("c", iter.next()); + } + + @Test(expected = NoSuchElementException.class) + public void testBoundaryStart() { + iter.previous(); + } + + @Test(expected = NoSuchElementException.class) + public void testBoundaryEnd() { + advance(iter, 6); + iter.next(); + } + + @Test + public void testForEachLoop() { + List output = new ArrayList(); + for (String s : list) { + output.add(s); + } + assertEquals(list.toString(), output.toString()); + } + + // ========== Add Tests ========== + + @Test + public void testAddBeginning() { + iter.add("X"); + + assertEquals(0, iter.previousIndex()); + assertEquals(1, iter.nextIndex()); + assertEquals("a", iter.next()); + assertEquals("[X, a, b, c, d, e, f]", list.toString()); + } + + @Test + public void testAddMiddle() { + advance(iter, 3); + iter.add("X"); + + assertEquals(3, iter.previousIndex()); + assertEquals(4, iter.nextIndex()); + assertEquals("d", iter.next()); + assertEquals("[a, b, c, X, d, e, f]", list.toString()); + } + + @Test + public void testAddEnd() { + advance(iter, 6); + iter.add("X"); + + assertEquals(6, iter.previousIndex()); + assertEquals(7, iter.nextIndex()); + assertFalse(iter.hasNext()); + assertEquals("[a, b, c, d, e, f, X]", list.toString()); + } + + @Test + public void testPreviousAfterAddBeginning() { + iter.add("X"); + assertEquals("X", iter.previous()); + assertEquals(-1, iter.previousIndex()); + assertEquals(0, iter.nextIndex()); + assertEquals("[X, a, b, c, d, e, f]", list.toString()); + } + + @Test + public void testPreviousAfterAddMiddle() { + advance(iter, 3); + iter.add("X"); + assertEquals("X", iter.previous()); + assertEquals(2, iter.previousIndex()); + assertEquals(3, iter.nextIndex()); + assertEquals("[a, b, c, X, d, e, f]", list.toString()); + } + + @Test + public void testPreviousAfterAddEnd() { + advance(iter, 6); + iter.add("X"); + assertEquals("X", iter.previous()); + assertEquals(5, iter.previousIndex()); + assertEquals(6, iter.nextIndex()); + assertEquals("[a, b, c, d, e, f, X]", list.toString()); + } + + @Test + public void testAddMultiple() { + advance(iter, 3); + iter.add("X"); + iter.add("Y"); + iter.add("Z"); + assertEquals(5, iter.previousIndex()); + assertEquals(6, iter.nextIndex()); + assertEquals("d", iter.next()); + assertEquals("d", iter.previous()); + assertEquals("Z", iter.previous()); + assertEquals("[a, b, c, X, Y, Z, d, e, f]", list.toString()); + } + + @Test + public void testAddAfterPrevious() { + advance(iter, 3); + iter.previous(); // c + iter.add("X"); + assertEquals(2, iter.previousIndex()); + assertEquals(3, iter.nextIndex()); + assertEquals("[a, b, X, c, d, e, f]", list.toString()); + } + + @Test + public void testAddAfterRemove() { + advance(iter, 3); + iter.remove(); + iter.add("X"); + assertEquals(2, iter.previousIndex()); + assertEquals(3, iter.nextIndex()); + assertEquals("[a, b, X, d, e, f]", list.toString()); + } + + @Test + public void testAddAfterSet() { + advance(iter, 3); + iter.set("X"); + iter.add("Y"); + assertEquals(3, iter.previousIndex()); + assertEquals(4, iter.nextIndex()); + assertEquals("[a, b, X, Y, d, e, f]", list.toString()); + } + + // ========== Remove Tests ========== + + @Test + public void testRemoveBeginning() { + iter.next(); + iter.remove(); + assertEquals(-1, iter.previousIndex()); + assertEquals(0, iter.nextIndex()); + assertEquals("[b, c, d, e, f]", list.toString()); + } + + @Test + public void testRemoveMiddle() { + advance(iter, 3); + iter.remove(); + assertEquals(1, iter.previousIndex()); + assertEquals(2, iter.nextIndex()); + assertEquals("[a, b, d, e, f]", list.toString()); + } + + @Test + public void testRemoveEnd() { + toEnd(iter); + iter.remove(); + assertEquals(4, iter.previousIndex()); + assertEquals(5, iter.nextIndex()); + assertEquals("[a, b, c, d, e]", list.toString()); + } + + @Test + public void testRemoveAfterPrevious() { + advance(iter, 4); + iter.previous(); // d + iter.previous(); // c + iter.remove(); + assertEquals(1, iter.previousIndex()); + assertEquals(2, iter.nextIndex()); + assertEquals("[a, b, d, e, f]", list.toString()); + } + + @Test + public void testRemoveAfterSet() { + advance(iter, 3); + iter.set("X"); + iter.remove(); + assertEquals(1, iter.previousIndex()); + assertEquals(2, iter.nextIndex()); + assertEquals("[a, b, d, e, f]", list.toString()); + } + + @Test(expected = IllegalStateException.class) + public void testRemoveInitialThrowsException() { + iter.remove(); + } + + @Test + public void testRemoveTwiceThrowsException() { + iter.next(); + iter.remove(); + try { iter.remove(); } catch (IllegalStateException e) {return;} + fail("Expected IllegalStateException"); + } + + @Test + public void testRemoveAfterAddThrowsException() { + iter.next(); + iter.add("X"); + try { iter.remove(); } catch (IllegalStateException e) {return;} + fail("Expected IllegalStateException"); + } + + // ========== Set Tests ========== + + @Test + public void testSetBeginning() { + iter.next(); + iter.set("X"); + assertEquals(0, iter.previousIndex()); + assertEquals(1, iter.nextIndex()); + assertEquals("[X, b, c, d, e, f]", list.toString()); + } + + @Test + public void testSetMiddle() { + advance(iter, 3); + iter.set("X"); + assertEquals(2, iter.previousIndex()); + assertEquals(3, iter.nextIndex()); + assertEquals("[a, b, X, d, e, f]", list.toString()); + } + + @Test + public void testSetEnd() { + toEnd(iter); + iter.set("X"); + assertEquals(5, iter.previousIndex()); + assertEquals(6, iter.nextIndex()); + assertEquals("[a, b, c, d, e, X]", list.toString()); + } + + @Test + public void testSetTwice() { + advance(iter, 3); + iter.set("X"); + assertEquals(2, iter.previousIndex()); + assertEquals(3, iter.nextIndex()); + assertEquals("[a, b, X, d, e, f]", list.toString()); + iter.set("Y"); + assertEquals(2, iter.previousIndex()); + assertEquals(3, iter.nextIndex()); + assertEquals("[a, b, Y, d, e, f]", list.toString()); + } + + @Test + public void testSetAfterPrevious() { + advance(iter, 4); + iter.previous(); // d + iter.previous(); // c + iter.set("X"); + assertEquals(1, iter.previousIndex()); + assertEquals(2, iter.nextIndex()); + assertEquals("[a, b, X, d, e, f]", list.toString()); + } + + @Test + public void testSetInitialThrowsException() { + try { iter.set("X"); } catch (IllegalStateException e) {return;} + fail("Expected IllegalStateException"); + } + + @Test + public void testSetAfterAddThrowsException() { + iter.next(); + iter.add("X"); + try { iter.set("Y"); } catch (IllegalStateException e) {return;} + fail("Expected IllegalStateException"); + } + + @Test + public void testSetAfterRemoveThrowsException() { + iter.next(); + iter.remove(); + try { iter.set("X"); } catch (IllegalStateException e) {return;} + fail("Expected IllegalStateException"); + } + + // ========== Positioned Iterator Tests ========== + + @Test + public void testPosBeginning() { + iter = list.listIterator(0); + assertFalse(iter.hasPrevious()); + assertTrue(iter.hasNext()); + assertEquals(-1, iter.previousIndex()); + assertEquals(0, iter.nextIndex()); + assertEquals("a", iter.next()); + } + + @Test + public void testPosMiddle() { + iter = list.listIterator(3); + assertTrue(iter.hasPrevious()); + assertTrue(iter.hasNext()); + assertEquals(2, iter.previousIndex()); + assertEquals(3, iter.nextIndex()); + assertEquals("d", iter.next()); + } + + @Test + public void testPosEnd() { + iter = list.listIterator(6); + assertTrue(iter.hasPrevious()); + assertFalse(iter.hasNext()); + assertEquals(5, iter.previousIndex()); + assertEquals(6, iter.nextIndex()); + assertEquals("f", iter.previous()); + } + + @Test + public void testPosAdd() { + iter = list.listIterator(3); + iter.add("X"); + assertEquals(3, iter.previousIndex()); + assertEquals(4, iter.nextIndex()); + assertEquals("[a, b, c, X, d, e, f]", list.toString()); + } + + @Test + public void testPosInitialRemoveThrowsException() { + iter = list.listIterator(3); + try { iter.remove(); } catch (IllegalStateException e) {return;} + fail("Expected IllegalStateException"); + } + + @Test + public void testPosInitialSetThrowsException() { + iter = list.listIterator(3); + try { iter.set("X"); } catch (IllegalStateException e) {return;} + fail("Expected IllegalStateException"); + } + + // ========== Concurrency Tests ========== + + @Test + public void testConcurrencyAddIteratorNext() { + iter = list.listIterator(); + list.add("aa"); + try { iter.next(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddIndexedIteratorNext() { + iter = list.listIterator(); + list.add(1, "aa"); + try { iter.next(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyRemoveIteratorNext() { + iter = list.listIterator(); + list.remove("b"); + try { iter.next(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRemoveIndexedIteratorNext() { + iter = list.listIterator(); + list.remove(2); + try { iter.next(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddAllIteratorNext() { + iter = list.listIterator(); + list.addAll(Collections.singleton("f")); + try { iter.next(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddAllIndexedIteratorNext() { + iter = list.listIterator(); + list.addAll(1, Collections.singleton("f")); + try { iter.next(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyGetIteratorNext() { + iter = list.listIterator(); + list.get(2); + iter.next(); + } + + @Test + public void testConcurrencyRemoveAllIteratorNext() { + iter = list.listIterator(); + list.removeAll(Arrays.asList("a", "c")); + try { iter.next(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRetainAllIteratorNext() { + iter = list.listIterator(); + list.retainAll(Arrays.asList("a", "c")); + try { iter.next(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyIteratorIteratorNext() { + iter = list.listIterator(); + final Iterator iterator = list.iterator(); + iterator.next(); + iterator.remove(); + try { iter.next(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddIteratorPrevious() { + iter = list.listIterator(2); + list.add("aa"); + try { iter.previous(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddIndexedIteratorPrevious() { + iter = list.listIterator(2); + list.add(1, "aa"); + try { iter.previous(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyRemoveIteratorPrevious() { + iter = list.listIterator(2); + list.remove("b"); + try { iter.previous(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRemoveIndexedIteratorPrevious() { + iter = list.listIterator(2); + list.remove(2); + try { iter.previous(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddAllIteratorPrevious() { + iter = list.listIterator(2); + list.addAll(Collections.singleton("f")); + try { iter.previous(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddAllIndexedIteratorPrevious() { + iter = list.listIterator(2); + list.addAll(1, Collections.singleton("f")); + try { iter.previous(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyGetIteratorPrevious() { + iter = list.listIterator(2); + list.get(2); + iter.previous(); + } + + @Test + public void testConcurrencyRemoveAllIteratorPrevious() { + iter = list.listIterator(2); + list.removeAll(Arrays.asList("a", "c")); + try { iter.previous(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRetainAllIteratorPrevious() { + iter = list.listIterator(2); + list.retainAll(Arrays.asList("a", "c")); + try { iter.previous(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyIteratorIteratorPrevious() { + iter = list.listIterator(2); + final Iterator iterator = list.iterator(); + iterator.next(); + iterator.remove(); + try { iter.previous(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyAddIteratorRemove() { + iter = list.listIterator(); + iter.next(); + list.add("aa"); + try { iter.remove(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyAddIndexedIteratorRemove() { + iter = list.listIterator(); + iter.next(); + list.add(1, "aa"); + try { iter.remove(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRemoveIteratorRemove() { + iter = list.listIterator(); + iter.next(); + list.remove("b"); + try { iter.remove(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRemoveIndexedIteratorRemove() { + iter = list.listIterator(); + iter.next(); + list.remove(2); + try { iter.remove(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddAllIteratorRemove() { + iter = list.listIterator(); + iter.next(); + list.addAll(Collections.singleton("f")); + try { iter.remove(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddAllIndexedIteratorRemove() { + iter = list.listIterator(); + iter.next(); + list.addAll(1, Collections.singleton("f")); + try { iter.remove(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyGetIteratorRemove() { + iter = list.listIterator(); + iter.next(); + list.get(2); + iter.remove(); + } + + @Test + public void testConcurrencyRemoveAllIteratorRemove() { + iter = list.listIterator(); + iter.next(); + list.removeAll(Arrays.asList("a", "c")); + try { iter.remove(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRetainAllIteratorRemove() { + iter = list.listIterator(); + iter.next(); + list.retainAll(Arrays.asList("a", "c")); + try { iter.remove(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyIteratorIteratorRemove() { + iter = list.listIterator(); + iter.next(); + final Iterator iterator = list.iterator(); + iterator.next(); + iterator.remove(); + try { iter.remove(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyAddIteratorSet() { + iter = list.listIterator(); + iter.next(); + list.add("aa"); + try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyAddIndexedIteratorSet() { + iter = list.listIterator(); + iter.next(); + list.add(1, "aa"); + try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRemoveIteratorSet() { + iter = list.listIterator(); + iter.next(); + list.remove("b"); + try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRemoveIndexedIteratorSet() { + iter = list.listIterator(); + iter.next(); + list.remove(2); + try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddAllIteratorSet() { + iter = list.listIterator(); + iter.next(); + list.addAll(Collections.singleton("f")); + try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddAllIndexedIteratorSet() { + iter = list.listIterator(); + iter.next(); + list.addAll(1, Collections.singleton("f")); + try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyGetIteratorSet() { + iter = list.listIterator(); + iter.next(); + list.get(2); + iter.set("x"); + } + + @Test + public void testConcurrencyRemoveAllIteratorSet() { + iter = list.listIterator(); + iter.next(); + list.removeAll(Arrays.asList("a", "c")); + try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRetainAllIteratorSet() { + iter = list.listIterator(); + iter.next(); + list.retainAll(Arrays.asList("a", "c")); + try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyIteratorIteratorSet() { + iter = list.listIterator(); + iter.next(); + final Iterator iterator = list.iterator(); + iterator.next(); + iterator.remove(); + try { iter.set("x"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } +} --- old/modules/base/src/test/java/javafx/collections/ObservableListTest.java 2015-08-31 10:24:55.025216489 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,295 +0,0 @@ -/* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import static org.junit.Assert.*; -import org.junit.Ignore; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - * Tests for ObservableList. - * - */ -@RunWith(Parameterized.class) -public class ObservableListTest { - - static final List EMPTY = Collections.emptyList(); - final Callable> listFactory; - ObservableList list; - MockListObserver mlo; - - - public ObservableListTest(final Callable> listFactory) { - this.listFactory = listFactory; - } - - @Parameterized.Parameters - public static Collection createParameters() { - Object[][] data = new Object[][] { - { TestedObservableLists.ARRAY_LIST }, - { TestedObservableLists.LINKED_LIST }, - { TestedObservableLists.VETOABLE_LIST }, - { TestedObservableLists.CHECKED_OBSERVABLE_ARRAY_LIST }, - { TestedObservableLists.SYNCHRONIZED_OBSERVABLE_ARRAY_LIST }, - { TestedObservableLists.OBSERVABLE_LIST_PROPERTY } - }; - return Arrays.asList(data); - } - - @Before - public void setUp() throws Exception { - list = listFactory.call(); - mlo = new MockListObserver(); - list.addListener(mlo); - - useListData("one", "two", "three"); - } - - /** - * Modifies the list in the fixture to use the strings passed in instead of - * the default strings, and re-creates the observable list and the observer. - * If no strings are passed in, the result is an empty list. - * - * @param strings the strings to use for the list in the fixture - */ - void useListData(String... strings) { - list.clear(); - list.addAll(Arrays.asList(strings)); - mlo.clear(); - } - - // ========== observer add/remove tests ========== - - @Test - public void testObserverAddRemove() { - MockListObserver mlo2 = new MockListObserver(); - list.addListener(mlo2); - list.removeListener(mlo); - list.add("xyzzy"); - mlo.check0(); - mlo2.check1AddRemove(list, EMPTY, 3, 4); - } - - @Test - @Ignore - public void testObserverAddTwice() { - list.addListener(mlo); // add it a second time - list.add("plugh"); - mlo.check1AddRemove(list, EMPTY, 3, 4); - } - - @Test - public void testObserverRemoveTwice() { - list.removeListener(mlo); - list.removeListener(mlo); - list.add("plugh"); - mlo.check0(); - } - - // ========== list mutation tests ========== - - @Test - public void testAddToEmpty() { - useListData(); - list.add("asdf"); - mlo.check1AddRemove(list, EMPTY, 0, 1); - } - - @Test - public void testAddAtEnd() { - list.add("four"); - mlo.check1AddRemove(list, EMPTY, 3, 4); - } - - @Test - public void testAddInMiddle() { - list.add(1, "xyz"); - mlo.check1AddRemove(list, EMPTY, 1, 2); - } - - @Test - public void testAddSeveralToEmpty() { - useListData(); - list.addAll(Arrays.asList("alpha", "bravo", "charlie")); - mlo.check1AddRemove(list, EMPTY, 0, 3); - } - - @Test - public void testAddSeveralAtEnd() { - list.addAll(Arrays.asList("four", "five")); - mlo.check1AddRemove(list, EMPTY, 3, 5); - } - - @Test - public void testAddSeveralInMiddle() { - list.addAll(1, Arrays.asList("a", "b")); - mlo.check1AddRemove(list, EMPTY, 1, 3); - } - - @Test - public void testClearNonempty() { - list.clear(); - mlo.check1AddRemove(list, Arrays.asList("one", "two", "three"), 0, 0); - } - - @Test - public void testRemoveByIndex() { - String r = list.remove(1); - mlo.check1AddRemove(list, Arrays.asList("two"), 1, 1); - assertEquals("two", r); - } - - @Test - public void testRemoveObject() { - useListData("one", "x", "two", "three"); - boolean b = list.remove("two"); - mlo.check1AddRemove(list, Arrays.asList("two"), 2, 2); - assertTrue(b); - } - - @Test - public void testRemoveNull() { - useListData("one", "two", null, "three"); - boolean b = list.remove(null); - mlo.check1AddRemove(list, Arrays.asList((String)null), 2, 2); - assertTrue(b); - } - - @Test - public void testRemoveAll() { - useListData("one", "two", "three", "four", "five"); - list.removeAll(Arrays.asList("one", "two", "four", "six")); - assertEquals(2, mlo.calls.size()); - mlo.checkAddRemove(0, list, Arrays.asList("one", "two"), 0, 0); - mlo.checkAddRemove(1, list, Arrays.asList("four"), 1, 1); - } - - @Test - public void testRemoveAll_1() { - useListData("a", "c", "d", "c"); - list.removeAll(Arrays.asList("c")); - assertEquals(2, mlo.calls.size()); - mlo.checkAddRemove(0, list, Arrays.asList("c"), 1, 1); - mlo.checkAddRemove(1, list, Arrays.asList("c"), 2, 2); - } - - - @Test - public void testRemoveAll_2() { - useListData("one", "two"); - list.removeAll(Arrays.asList("three", "four")); - mlo.check0(); - } - - @Test - public void testRemoveAll_3() { - useListData("a", "c", "d", "c"); - list.removeAll(Arrays.asList("d")); - assertEquals(1, mlo.calls.size()); - mlo.checkAddRemove(0, list, Arrays.asList("d"), 2, 2); - } - - @Test - public void testRemoveAll_4() { - useListData("a", "c", "d", "c"); - list.removeAll(Arrays.asList("d", "c")); - assertEquals(1, mlo.calls.size()); - mlo.checkAddRemove(0, list, Arrays.asList("c", "d", "c"), 1, 1); - } - - @Test - public void testRetainAll() { - useListData("one", "two", "three", "four", "five"); - list.retainAll(Arrays.asList("two", "five", "six")); - assertEquals(2, mlo.calls.size()); - mlo.checkAddRemove(0, list, Arrays.asList("one"), 0, 0); - mlo.checkAddRemove(1, list, Arrays.asList("three", "four"), 1, 1); - } - - @Test - public void testRemoveNonexistent() { - useListData("one", "two", "x", "three"); - boolean b = list.remove("four"); - mlo.check0(); - assertFalse(b); - } - - @Test - public void testSet() { - String r = list.set(1, "fnord"); - mlo.check1AddRemove(list, Arrays.asList("two"), 1, 2); - assertEquals("two", r); - } - - @Test - public void testObserverCanRemoveObservers() { - final ListChangeListener listObserver = change -> { - change.getList().removeListener(mlo); - }; - list.addListener(listObserver); - list.add("x"); - mlo.clear(); - list.add("y"); - mlo.check0(); - list.removeListener(listObserver); - - - final StringListChangeListener listener = new StringListChangeListener(); - list.addListener(listener); - list.add("z"); - assertEquals(listener.counter, 1); - list.add("zz"); - assertEquals(listener.counter, 1); - } - - @Test - public void testEqualsAndHashCode() { - final List other = Arrays.asList("one", "two", "three"); - assertTrue(list.equals(other)); - assertEquals(list.hashCode(), other.hashCode()); - } - - - private static class StringListChangeListener implements ListChangeListener { - - private int counter; - - @Override - public void onChanged(final Change change) { - change.getList().removeListener(this); - ++counter; - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/ObservableListTest.java 2015-08-31 10:24:54.821216492 -0400 @@ -0,0 +1,297 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; + +import static org.junit.Assert.*; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + * Tests for ObservableList. + * + */ +@RunWith(Parameterized.class) +public class ObservableListTest { + + static final List EMPTY = Collections.emptyList(); + final Callable> listFactory; + ObservableList list; + MockListObserver mlo; + + + public ObservableListTest(final Callable> listFactory) { + this.listFactory = listFactory; + } + + @Parameterized.Parameters + public static Collection createParameters() { + Object[][] data = new Object[][] { + { TestedObservableLists.ARRAY_LIST }, + { TestedObservableLists.LINKED_LIST }, + { TestedObservableLists.VETOABLE_LIST }, + { TestedObservableLists.CHECKED_OBSERVABLE_ARRAY_LIST }, + { TestedObservableLists.SYNCHRONIZED_OBSERVABLE_ARRAY_LIST }, + { TestedObservableLists.OBSERVABLE_LIST_PROPERTY } + }; + return Arrays.asList(data); + } + + @Before + public void setUp() throws Exception { + list = listFactory.call(); + mlo = new MockListObserver(); + list.addListener(mlo); + + useListData("one", "two", "three"); + } + + /** + * Modifies the list in the fixture to use the strings passed in instead of + * the default strings, and re-creates the observable list and the observer. + * If no strings are passed in, the result is an empty list. + * + * @param strings the strings to use for the list in the fixture + */ + void useListData(String... strings) { + list.clear(); + list.addAll(Arrays.asList(strings)); + mlo.clear(); + } + + // ========== observer add/remove tests ========== + + @Test + public void testObserverAddRemove() { + MockListObserver mlo2 = new MockListObserver(); + list.addListener(mlo2); + list.removeListener(mlo); + list.add("xyzzy"); + mlo.check0(); + mlo2.check1AddRemove(list, EMPTY, 3, 4); + } + + @Test + @Ignore + public void testObserverAddTwice() { + list.addListener(mlo); // add it a second time + list.add("plugh"); + mlo.check1AddRemove(list, EMPTY, 3, 4); + } + + @Test + public void testObserverRemoveTwice() { + list.removeListener(mlo); + list.removeListener(mlo); + list.add("plugh"); + mlo.check0(); + } + + // ========== list mutation tests ========== + + @Test + public void testAddToEmpty() { + useListData(); + list.add("asdf"); + mlo.check1AddRemove(list, EMPTY, 0, 1); + } + + @Test + public void testAddAtEnd() { + list.add("four"); + mlo.check1AddRemove(list, EMPTY, 3, 4); + } + + @Test + public void testAddInMiddle() { + list.add(1, "xyz"); + mlo.check1AddRemove(list, EMPTY, 1, 2); + } + + @Test + public void testAddSeveralToEmpty() { + useListData(); + list.addAll(Arrays.asList("alpha", "bravo", "charlie")); + mlo.check1AddRemove(list, EMPTY, 0, 3); + } + + @Test + public void testAddSeveralAtEnd() { + list.addAll(Arrays.asList("four", "five")); + mlo.check1AddRemove(list, EMPTY, 3, 5); + } + + @Test + public void testAddSeveralInMiddle() { + list.addAll(1, Arrays.asList("a", "b")); + mlo.check1AddRemove(list, EMPTY, 1, 3); + } + + @Test + public void testClearNonempty() { + list.clear(); + mlo.check1AddRemove(list, Arrays.asList("one", "two", "three"), 0, 0); + } + + @Test + public void testRemoveByIndex() { + String r = list.remove(1); + mlo.check1AddRemove(list, Arrays.asList("two"), 1, 1); + assertEquals("two", r); + } + + @Test + public void testRemoveObject() { + useListData("one", "x", "two", "three"); + boolean b = list.remove("two"); + mlo.check1AddRemove(list, Arrays.asList("two"), 2, 2); + assertTrue(b); + } + + @Test + public void testRemoveNull() { + useListData("one", "two", null, "three"); + boolean b = list.remove(null); + mlo.check1AddRemove(list, Arrays.asList((String)null), 2, 2); + assertTrue(b); + } + + @Test + public void testRemoveAll() { + useListData("one", "two", "three", "four", "five"); + list.removeAll(Arrays.asList("one", "two", "four", "six")); + assertEquals(2, mlo.calls.size()); + mlo.checkAddRemove(0, list, Arrays.asList("one", "two"), 0, 0); + mlo.checkAddRemove(1, list, Arrays.asList("four"), 1, 1); + } + + @Test + public void testRemoveAll_1() { + useListData("a", "c", "d", "c"); + list.removeAll(Arrays.asList("c")); + assertEquals(2, mlo.calls.size()); + mlo.checkAddRemove(0, list, Arrays.asList("c"), 1, 1); + mlo.checkAddRemove(1, list, Arrays.asList("c"), 2, 2); + } + + + @Test + public void testRemoveAll_2() { + useListData("one", "two"); + list.removeAll(Arrays.asList("three", "four")); + mlo.check0(); + } + + @Test + public void testRemoveAll_3() { + useListData("a", "c", "d", "c"); + list.removeAll(Arrays.asList("d")); + assertEquals(1, mlo.calls.size()); + mlo.checkAddRemove(0, list, Arrays.asList("d"), 2, 2); + } + + @Test + public void testRemoveAll_4() { + useListData("a", "c", "d", "c"); + list.removeAll(Arrays.asList("d", "c")); + assertEquals(1, mlo.calls.size()); + mlo.checkAddRemove(0, list, Arrays.asList("c", "d", "c"), 1, 1); + } + + @Test + public void testRetainAll() { + useListData("one", "two", "three", "four", "five"); + list.retainAll(Arrays.asList("two", "five", "six")); + assertEquals(2, mlo.calls.size()); + mlo.checkAddRemove(0, list, Arrays.asList("one"), 0, 0); + mlo.checkAddRemove(1, list, Arrays.asList("three", "four"), 1, 1); + } + + @Test + public void testRemoveNonexistent() { + useListData("one", "two", "x", "three"); + boolean b = list.remove("four"); + mlo.check0(); + assertFalse(b); + } + + @Test + public void testSet() { + String r = list.set(1, "fnord"); + mlo.check1AddRemove(list, Arrays.asList("two"), 1, 2); + assertEquals("two", r); + } + + @Test + public void testObserverCanRemoveObservers() { + final ListChangeListener listObserver = change -> { + change.getList().removeListener(mlo); + }; + list.addListener(listObserver); + list.add("x"); + mlo.clear(); + list.add("y"); + mlo.check0(); + list.removeListener(listObserver); + + + final StringListChangeListener listener = new StringListChangeListener(); + list.addListener(listener); + list.add("z"); + assertEquals(listener.counter, 1); + list.add("zz"); + assertEquals(listener.counter, 1); + } + + @Test + public void testEqualsAndHashCode() { + final List other = Arrays.asList("one", "two", "three"); + assertTrue(list.equals(other)); + assertEquals(list.hashCode(), other.hashCode()); + } + + + private static class StringListChangeListener implements ListChangeListener { + + private int counter; + + @Override + public void onChanged(final Change change) { + change.getList().removeListener(this); + ++counter; + } + } +} --- old/modules/base/src/test/java/javafx/collections/ObservableListWithExtractor.java 2015-08-31 10:24:55.781216481 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,355 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import com.sun.javafx.collections.ElementObservableListDecorator; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.ListIterator; -import javafx.beans.Observable; -import javafx.util.Callback; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -public class ObservableListWithExtractor { - private final Mode mode; - - public static enum Mode { - OBSERVABLE_LIST_WRAPPER, - DECORATOR - } - - @Parameters - public static Collection data() { - return Arrays.asList(new Object[][]{{Mode.OBSERVABLE_LIST_WRAPPER}, {Mode.DECORATOR}}); - } - - private ObservableList modifiedList; - private ObservableList observedList; - private MockListObserver obs; - private Person p0; - - public ObservableListWithExtractor(Mode mode) { - this.mode = mode; - } - - private void updateP0() { - p0.name.set("bar"); - } - - - @Before - public void setUp() { - p0 = new Person(); - obs = new MockListObserver(); - Callback callback = param -> new Observable[]{param.name}; - if (mode == Mode.OBSERVABLE_LIST_WRAPPER) { - observedList = modifiedList = FXCollections.observableArrayList(callback); - } else { - modifiedList = FXCollections.observableArrayList(); - observedList = new ElementObservableListDecorator(modifiedList, callback); - } - - modifiedList.add(p0); - observedList.addListener(obs); - } - - @Test - public void testUpdate_add() { - updateP0(); - obs.check1Update(modifiedList, 0, 1); - } - - @Test - public void testUpdate_add1() { - modifiedList.clear(); - modifiedList.add(0, p0); - obs.clear(); - updateP0(); - obs.check1Update(observedList, 0, 1); - } - - @Test - public void testUpdate_addAll() { - modifiedList.clear(); - modifiedList.addAll(Arrays.asList(p0, p0)); - obs.clear(); - updateP0(); - obs.check1Update(observedList, 0, 2); - } - - @Test - public void testUpdate_addAll1() { - modifiedList.clear(); - modifiedList.addAll(0, Arrays.asList(p0, p0)); - obs.clear(); - updateP0(); - obs.check1Update(observedList, 0, 2); - } - - @Test - public void testUpdate_addAll2() { - modifiedList.clear(); - modifiedList.addAll(p0, p0); - obs.clear(); - updateP0(); - obs.check1Update(observedList, 0, 2); - } - - @Test - public void testUpdate_set() { - Person p1 = new Person(); - modifiedList.set(0, p1); - obs.clear(); - updateP0(); - obs.check0(); - p1.name.set("bar"); - obs.check1Update(observedList, 0, 1); - } - - @Test - public void testUpdate_setAll() { - Person p1 = new Person(); - modifiedList.setAll(p1); - obs.clear(); - updateP0(); - obs.check0(); - p1.name.set("bar"); - obs.check1Update(observedList, 0, 1); - } - - @Test - public void testUpdate_remove() { - modifiedList.remove(p0); - obs.clear(); - updateP0(); - obs.check0(); - } - - @Test - public void testUpdate_remove1() { - modifiedList.remove(0); - obs.clear(); - updateP0(); - obs.check0(); - } - - @Test - public void testUpdate_removeAll() { - modifiedList.removeAll(p0); - obs.clear(); - updateP0(); - obs.check0(); - } - - @Test - public void testUpdate_retainAll() { - modifiedList.retainAll(); - obs.clear(); - updateP0(); - obs.check0(); - } - - @Test - public void testUpdate_iterator_add() { - modifiedList.clear(); - modifiedList.listIterator().add(p0); - obs.clear(); - updateP0(); - obs.check1Update(observedList, 0, 1); - } - - @Test - public void testUpdate_iterator_set() { - Person p1 = new Person(); - ListIterator listIterator = modifiedList.listIterator(); - listIterator.next(); - listIterator.set(p1); - obs.clear(); - updateP0(); - obs.check0(); - p1.name.set("bar"); - obs.check1Update(observedList, 0, 1); - } - - @Test - public void testUpdate_sublist_add() { - List sublist = modifiedList.subList(0, 1); - sublist.add(p0); - obs.clear(); - updateP0(); - obs.check1Update(observedList, 0, 2); - } - - @Test - public void testUpdate_sublist_add1() { - List sublist = modifiedList.subList(0, 1); - sublist.clear(); - sublist.add(0, p0); - obs.clear(); - updateP0(); - obs.check1Update(observedList, 0, 1); - } - - @Test - public void testUpdate_sublist_addAll() { - List sublist = modifiedList.subList(0, 1); - sublist.clear(); - sublist.addAll(Arrays.asList(p0, p0)); - obs.clear(); - updateP0(); - obs.check1Update(observedList, 0, 2); - } - - @Test - public void testUpdate_sublist_addAll1() { - List sublist = modifiedList.subList(0, 1); - sublist.clear(); - sublist.addAll(0, Arrays.asList(p0, p0)); - obs.clear(); - updateP0(); - obs.check1Update(observedList, 0, 2); - } - - @Test - public void testUpdate_sublist_set() { - List sublist = modifiedList.subList(0, 1); - Person p1 = new Person(); - sublist.set(0, p1); - obs.clear(); - updateP0(); - obs.check0(); - p1.name.set("bar"); - obs.check1Update(observedList, 0, 1); - } - - @Test - public void testUpdate_sublist_remove() { - List sublist = modifiedList.subList(0, 1); - sublist.remove(p0); - obs.clear(); - updateP0(); - obs.check0(); - } - - @Test - public void testUpdate_sublist_remove1() { - List sublist = modifiedList.subList(0, 1); - sublist.remove(0); - obs.clear(); - updateP0(); - obs.check0(); - } - - @Test - public void testUpdate_sublist_removeAll() { - List sublist = modifiedList.subList(0, 1); - sublist.removeAll(Arrays.asList(p0)); - obs.clear(); - updateP0(); - obs.check0(); - } - - @Test - public void testUpdate_sublist_retainAll() { - List sublist = modifiedList.subList(0, 1); - sublist.retainAll(Collections.emptyList()); - obs.clear(); - updateP0(); - obs.check0(); - } - - @Test - public void testUpdate_iterator_sublist_add() { - List sublist = modifiedList.subList(0, 1); - sublist.clear(); - sublist.listIterator().add(p0); - obs.clear(); - updateP0(); - obs.check1Update(observedList, 0, 1); - } - - @Test - public void testUpdate_iterator_sublist_set() { - List sublist = modifiedList.subList(0, 1); - Person p1 = new Person(); - ListIterator listIterator = sublist.listIterator(); - listIterator.next(); - listIterator.set(p1); - obs.clear(); - updateP0(); - obs.check0(); - p1.name.set("bar"); - obs.check1Update(observedList, 0, 1); - } - - @Test - public void testMultipleUpdate() { - - modifiedList.add(new Person()); - modifiedList.addAll(p0, p0); - - obs.clear(); - - updateP0(); - - obs.checkUpdate(0, modifiedList, 0, 1); - obs.checkUpdate(1, modifiedList, 2, 4); - assertEquals(2, obs.calls.size()); - - } - - @Test - public void testPreFilledList() { - ArrayList arrayList = new ArrayList(); - arrayList.add(p0); - obs = new MockListObserver(); - Callback callback = param -> new Observable[]{param.name}; - if (mode == Mode.OBSERVABLE_LIST_WRAPPER) { - observedList = modifiedList = FXCollections.observableList(arrayList, callback); - } else { - modifiedList = FXCollections.observableArrayList(arrayList); - observedList = new ElementObservableListDecorator(modifiedList, callback); - } - - observedList.addListener(obs); - - updateP0(); - - obs.checkUpdate(0, observedList, 0, 1); - assertEquals(1, obs.calls.size()); - } - - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/ObservableListWithExtractor.java 2015-08-31 10:24:55.581216483 -0400 @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import com.sun.javafx.collections.ElementObservableListDecorator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.ListIterator; +import javafx.beans.Observable; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.util.Callback; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class ObservableListWithExtractor { + private final Mode mode; + + public static enum Mode { + OBSERVABLE_LIST_WRAPPER, + DECORATOR + } + + @Parameters + public static Collection data() { + return Arrays.asList(new Object[][]{{Mode.OBSERVABLE_LIST_WRAPPER}, {Mode.DECORATOR}}); + } + + private ObservableList modifiedList; + private ObservableList observedList; + private MockListObserver obs; + private Person p0; + + public ObservableListWithExtractor(Mode mode) { + this.mode = mode; + } + + private void updateP0() { + p0.name.set("bar"); + } + + + @Before + public void setUp() { + p0 = new Person(); + obs = new MockListObserver(); + Callback callback = param -> new Observable[]{param.name}; + if (mode == Mode.OBSERVABLE_LIST_WRAPPER) { + observedList = modifiedList = FXCollections.observableArrayList(callback); + } else { + modifiedList = FXCollections.observableArrayList(); + observedList = new ElementObservableListDecorator(modifiedList, callback); + } + + modifiedList.add(p0); + observedList.addListener(obs); + } + + @Test + public void testUpdate_add() { + updateP0(); + obs.check1Update(modifiedList, 0, 1); + } + + @Test + public void testUpdate_add1() { + modifiedList.clear(); + modifiedList.add(0, p0); + obs.clear(); + updateP0(); + obs.check1Update(observedList, 0, 1); + } + + @Test + public void testUpdate_addAll() { + modifiedList.clear(); + modifiedList.addAll(Arrays.asList(p0, p0)); + obs.clear(); + updateP0(); + obs.check1Update(observedList, 0, 2); + } + + @Test + public void testUpdate_addAll1() { + modifiedList.clear(); + modifiedList.addAll(0, Arrays.asList(p0, p0)); + obs.clear(); + updateP0(); + obs.check1Update(observedList, 0, 2); + } + + @Test + public void testUpdate_addAll2() { + modifiedList.clear(); + modifiedList.addAll(p0, p0); + obs.clear(); + updateP0(); + obs.check1Update(observedList, 0, 2); + } + + @Test + public void testUpdate_set() { + Person p1 = new Person(); + modifiedList.set(0, p1); + obs.clear(); + updateP0(); + obs.check0(); + p1.name.set("bar"); + obs.check1Update(observedList, 0, 1); + } + + @Test + public void testUpdate_setAll() { + Person p1 = new Person(); + modifiedList.setAll(p1); + obs.clear(); + updateP0(); + obs.check0(); + p1.name.set("bar"); + obs.check1Update(observedList, 0, 1); + } + + @Test + public void testUpdate_remove() { + modifiedList.remove(p0); + obs.clear(); + updateP0(); + obs.check0(); + } + + @Test + public void testUpdate_remove1() { + modifiedList.remove(0); + obs.clear(); + updateP0(); + obs.check0(); + } + + @Test + public void testUpdate_removeAll() { + modifiedList.removeAll(p0); + obs.clear(); + updateP0(); + obs.check0(); + } + + @Test + public void testUpdate_retainAll() { + modifiedList.retainAll(); + obs.clear(); + updateP0(); + obs.check0(); + } + + @Test + public void testUpdate_iterator_add() { + modifiedList.clear(); + modifiedList.listIterator().add(p0); + obs.clear(); + updateP0(); + obs.check1Update(observedList, 0, 1); + } + + @Test + public void testUpdate_iterator_set() { + Person p1 = new Person(); + ListIterator listIterator = modifiedList.listIterator(); + listIterator.next(); + listIterator.set(p1); + obs.clear(); + updateP0(); + obs.check0(); + p1.name.set("bar"); + obs.check1Update(observedList, 0, 1); + } + + @Test + public void testUpdate_sublist_add() { + List sublist = modifiedList.subList(0, 1); + sublist.add(p0); + obs.clear(); + updateP0(); + obs.check1Update(observedList, 0, 2); + } + + @Test + public void testUpdate_sublist_add1() { + List sublist = modifiedList.subList(0, 1); + sublist.clear(); + sublist.add(0, p0); + obs.clear(); + updateP0(); + obs.check1Update(observedList, 0, 1); + } + + @Test + public void testUpdate_sublist_addAll() { + List sublist = modifiedList.subList(0, 1); + sublist.clear(); + sublist.addAll(Arrays.asList(p0, p0)); + obs.clear(); + updateP0(); + obs.check1Update(observedList, 0, 2); + } + + @Test + public void testUpdate_sublist_addAll1() { + List sublist = modifiedList.subList(0, 1); + sublist.clear(); + sublist.addAll(0, Arrays.asList(p0, p0)); + obs.clear(); + updateP0(); + obs.check1Update(observedList, 0, 2); + } + + @Test + public void testUpdate_sublist_set() { + List sublist = modifiedList.subList(0, 1); + Person p1 = new Person(); + sublist.set(0, p1); + obs.clear(); + updateP0(); + obs.check0(); + p1.name.set("bar"); + obs.check1Update(observedList, 0, 1); + } + + @Test + public void testUpdate_sublist_remove() { + List sublist = modifiedList.subList(0, 1); + sublist.remove(p0); + obs.clear(); + updateP0(); + obs.check0(); + } + + @Test + public void testUpdate_sublist_remove1() { + List sublist = modifiedList.subList(0, 1); + sublist.remove(0); + obs.clear(); + updateP0(); + obs.check0(); + } + + @Test + public void testUpdate_sublist_removeAll() { + List sublist = modifiedList.subList(0, 1); + sublist.removeAll(Arrays.asList(p0)); + obs.clear(); + updateP0(); + obs.check0(); + } + + @Test + public void testUpdate_sublist_retainAll() { + List sublist = modifiedList.subList(0, 1); + sublist.retainAll(Collections.emptyList()); + obs.clear(); + updateP0(); + obs.check0(); + } + + @Test + public void testUpdate_iterator_sublist_add() { + List sublist = modifiedList.subList(0, 1); + sublist.clear(); + sublist.listIterator().add(p0); + obs.clear(); + updateP0(); + obs.check1Update(observedList, 0, 1); + } + + @Test + public void testUpdate_iterator_sublist_set() { + List sublist = modifiedList.subList(0, 1); + Person p1 = new Person(); + ListIterator listIterator = sublist.listIterator(); + listIterator.next(); + listIterator.set(p1); + obs.clear(); + updateP0(); + obs.check0(); + p1.name.set("bar"); + obs.check1Update(observedList, 0, 1); + } + + @Test + public void testMultipleUpdate() { + + modifiedList.add(new Person()); + modifiedList.addAll(p0, p0); + + obs.clear(); + + updateP0(); + + obs.checkUpdate(0, modifiedList, 0, 1); + obs.checkUpdate(1, modifiedList, 2, 4); + assertEquals(2, obs.calls.size()); + + } + + @Test + public void testPreFilledList() { + ArrayList arrayList = new ArrayList(); + arrayList.add(p0); + obs = new MockListObserver(); + Callback callback = param -> new Observable[]{param.name}; + if (mode == Mode.OBSERVABLE_LIST_WRAPPER) { + observedList = modifiedList = FXCollections.observableList(arrayList, callback); + } else { + modifiedList = FXCollections.observableArrayList(arrayList); + observedList = new ElementObservableListDecorator(modifiedList, callback); + } + + observedList.addListener(obs); + + updateP0(); + + obs.checkUpdate(0, observedList, 0, 1); + assertEquals(1, obs.calls.size()); + } + + +} --- old/modules/base/src/test/java/javafx/collections/ObservableMapTest.java 2015-08-31 10:24:56.453216473 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,474 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import static javafx.collections.MockMapObserver.Call.call; -import static javafx.collections.MockMapObserver.Tuple.tup; -import static org.junit.Assert.*; -import static org.junit.Assert.assertEquals; - -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -@RunWith(Parameterized.class) -public class ObservableMapTest { - - final Callable> mapFactory; - private ObservableMap observableMap; - private MockMapObserver observer; - - - public ObservableMapTest(final Callable> mapFactory) { - this.mapFactory = mapFactory; - } - - @Parameterized.Parameters - public static Collection createParameters() { - Object[][] data = new Object[][] { - { TestedObservableMaps.HASH_MAP }, - { TestedObservableMaps.TREE_MAP }, - { TestedObservableMaps.LINKED_HASH_MAP }, - { TestedObservableMaps.CONCURRENT_HASH_MAP }, - { TestedObservableMaps.CHECKED_OBSERVABLE_HASH_MAP }, - { TestedObservableMaps.SYNCHRONIZED_OBSERVABLE_HASH_MAP }, - { TestedObservableMaps.OBSERVABLE_MAP_PROPERTY } - }; - return Arrays.asList(data); - } - - @Before - public void setUp() throws Exception { - observableMap = mapFactory.call(); - observer = new MockMapObserver(); - observableMap.addListener(observer); - - useMapData(); - } - - /** - * Modifies the map in the fixture to use the strings passed in instead of - * the default strings, and re-creates the observable map and the observer. - * If no strings are passed in, the result is an empty map. - * - * @param strings the strings to use for the list in the fixture - */ - void useMapData(String... strings) { - observableMap.clear(); - observableMap.put("one", "1"); - observableMap.put("two", "2"); - observableMap.put("foo", "bar"); - observer.clear(); - } - - @Test - public void testPutRemove() { - observableMap.put("observedFoo", "barVal"); - observableMap.put("foo", "barfoo"); - assertEquals("barVal", observableMap.get("observedFoo")); - - observableMap.remove("observedFoo"); - observableMap.remove("foo"); - observableMap.remove("bar"); - observableMap.put("one", "1"); - - assertFalse(observableMap.containsKey("foo")); - - observer.assertAdded(0, tup("observedFoo", "barVal")); - observer.assertAdded(1, tup("foo", "barfoo")); - observer.assertRemoved(1, tup("foo", "bar")); - observer.assertRemoved(2, tup("observedFoo", "barVal")); - observer.assertRemoved(3, tup("foo", "barfoo")); - - assertEquals(observer.getCallsNumber(), 4); - } - - @Test - public void testPutRemove_Null() { - if (mapFactory instanceof TestedObservableMaps.CallableConcurrentHashMapImpl) { - return; // Do not perform on ConcurrentHashMap, as it doesn't accept nulls - } - observableMap.clear(); - observer.clear(); - - observableMap.put("bar", null); - observableMap.put("foo", "x"); - observableMap.put("bar", "x"); - observableMap.put("foo", null); - - assertEquals(2, observableMap.size()); - - observableMap.remove("bar"); - observableMap.remove("foo"); - - assertEquals(0, observableMap.size()); - - observer.assertAdded(0, tup("bar", (String)null)); - observer.assertAdded(1, tup("foo", "x")); - observer.assertAdded(2, tup("bar", "x")); - observer.assertRemoved(2, tup("bar", (String)null)); - observer.assertAdded(3, tup("foo", (String)null)); - observer.assertRemoved(3, tup("foo", "x")); - observer.assertRemoved(4, tup("bar", "x")); - observer.assertRemoved(5, tup("foo", (String)null)); - - assertEquals(observer.getCallsNumber(), 6); - } - - @Test - public void testPutRemove_NullKey() { - if (mapFactory instanceof TestedObservableMaps.CallableConcurrentHashMapImpl || - mapFactory instanceof TestedObservableMaps.CallableTreeMapImpl) { - return; // Do not perform on ConcurrentHashMap and TreeMap, as they doesn't accept null keys - } - - observableMap.put(null, "abc"); - - assertEquals(4, observableMap.size()); - - observableMap.remove(null); - - assertEquals(3, observableMap.size()); - - observer.assertAdded(0, tup((String)null, "abc")); - observer.assertRemoved(1, tup((String)null, "abc")); - - assertEquals(observer.getCallsNumber(), 2); - } - - @Test - @SuppressWarnings("unchecked") - public void testPutAll() { - Map map = new HashMap(); - map.put("oFoo", "OFoo"); - map.put("pFoo", "PFoo"); - map.put("foo", "foofoo"); - map.put("one", "1"); - observableMap.putAll(map); - - assertTrue(observableMap.containsKey("oFoo")); - observer.assertMultipleCalls(call("oFoo", null, "OFoo"), call("pFoo", null, "PFoo"), call("foo", "bar", "foofoo")); - } - - @Test - @SuppressWarnings("unchecked") - public void testClear() { - observableMap.clear(); - - assertTrue(observableMap.isEmpty()); - observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2"), tup("foo", "bar")); - - } - - @Test - public void testOther() { - assertEquals(3, observableMap.size()); - assertFalse(observableMap.isEmpty()); - - assertTrue(observableMap.containsKey("foo")); - assertFalse(observableMap.containsKey("bar")); - - assertFalse(observableMap.containsValue("foo")); - assertTrue(observableMap.containsValue("bar")); - } - - @Test - public void testKeySet_Remove() { - observableMap.keySet().remove("one"); - observableMap.keySet().remove("two"); - observableMap.keySet().remove("three"); - - observer.assertRemoved(0, tup("one", "1")); - observer.assertRemoved(1, tup("two", "2")); - assertTrue(observer.getCallsNumber() == 2); - } - - @Test - @SuppressWarnings("unchecked") - public void testKeySet_RemoveAll() { - observableMap.keySet().removeAll(Arrays.asList("one", "two", "three")); - - observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2")); - assertTrue(observableMap.size() == 1); - } - - @Test - public void testKeySet_RetainAll() { - observableMap.keySet().retainAll(Arrays.asList("one", "two", "three")); - - observer.assertRemoved(tup("foo", "bar")); - assertTrue(observableMap.size() == 2); - } - - @Test - @SuppressWarnings("unchecked") - public void testKeySet_Clear() { - observableMap.keySet().clear(); - assertTrue(observableMap.keySet().isEmpty()); - observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2"), tup("foo", "bar")); - } - - @Test - public void testKeySet_Iterator() { - Iterator iterator = observableMap.keySet().iterator(); - assertTrue(iterator.hasNext()); - - String toBeRemoved = iterator.next(); - String toBeRemovedVal = observableMap.get(toBeRemoved); - iterator.remove(); - - assertTrue(observableMap.size() == 2); - observer.assertRemoved(tup(toBeRemoved, toBeRemovedVal)); - } - - @Test - public void testKeySet_Other() { - assertEquals(3, observableMap.keySet().size()); - assertTrue(observableMap.keySet().contains("foo")); - assertFalse(observableMap.keySet().contains("bar")); - - assertTrue(observableMap.keySet().containsAll(Arrays.asList("one", "two"))); - assertFalse(observableMap.keySet().containsAll(Arrays.asList("one", "three"))); - - assertTrue(observableMap.keySet().toArray(new String[0]).length == 3); - assertTrue(observableMap.keySet().toArray().length == 3); - } - - @Test - public void testValues_Remove() { - observableMap.values().remove("1"); - observableMap.values().remove("2"); - observableMap.values().remove("3"); - - observer.assertRemoved(0, tup("one", "1")); - observer.assertRemoved(1, tup("two", "2")); - assertTrue(observer.getCallsNumber() == 2); - } - - @Test - @SuppressWarnings("unchecked") - public void testValues_RemoveAll() { - observableMap.values().removeAll(Arrays.asList("1", "2", "3")); - - observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2")); - assertTrue(observableMap.size() == 1); - } - - @Test - public void testValues_RetainAll() { - observableMap.values().retainAll(Arrays.asList("1", "2", "3")); - - observer.assertRemoved(tup("foo", "bar")); - assertTrue(observableMap.size() == 2); - } - - @Test - @SuppressWarnings("unchecked") - public void testValues_Clear() { - observableMap.values().clear(); - assertTrue(observableMap.values().isEmpty()); - observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2"), tup("foo", "bar")); - } - - @Test - public void testValues_Iterator() { - Iterator iterator = observableMap.values().iterator(); - assertTrue(iterator.hasNext()); - - String toBeRemovedVal = iterator.next(); - iterator.remove(); - - assertTrue(observableMap.size() == 2); - observer.assertRemoved(tup(toBeRemovedVal.equals("1") ? "one" - : toBeRemovedVal.equals("2") ? "two" - : toBeRemovedVal.equals("bar") ? "foo" : null, toBeRemovedVal)); - } - - @Test - public void testValues_Other() { - assertEquals(3, observableMap.values().size()); - assertFalse(observableMap.values().contains("foo")); - assertTrue(observableMap.values().contains("bar")); - - assertTrue(observableMap.values().containsAll(Arrays.asList("1", "2"))); - assertFalse(observableMap.values().containsAll(Arrays.asList("1", "3"))); - - assertTrue(observableMap.values().toArray(new String[0]).length == 3); - assertTrue(observableMap.values().toArray().length == 3); - } - - @Test - public void testEntrySet_Remove() { - observableMap.entrySet().remove(entry("one","1")); - observableMap.entrySet().remove(entry("two","2")); - observableMap.entrySet().remove(entry("three","3")); - - observer.assertRemoved(0, tup("one", "1")); - observer.assertRemoved(1, tup("two", "2")); - assertTrue(observer.getCallsNumber() == 2); - } - - @Test - @SuppressWarnings("unchecked") - public void testEntrySet_RemoveAll() { - observableMap.entrySet().removeAll(Arrays.asList(entry("one","1"), entry("two","2"), entry("three","3"))); - - observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2")); - assertTrue(observableMap.size() == 1); - } - - @Test - @SuppressWarnings("unchecked") - public void testEntrySet_RetainAll() { - observableMap.entrySet().retainAll(Arrays.asList(entry("one","1"), entry("two","2"), entry("three","3"))); - - observer.assertRemoved(tup("foo", "bar")); - assertTrue(observableMap.size() == 2); - } - - @Test - @SuppressWarnings("unchecked") - public void testEntrySet_Clear() { - observableMap.entrySet().clear(); - assertTrue(observableMap.entrySet().isEmpty()); - observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2"), tup("foo", "bar")); - } - - @Test - public void testEntrySet_Iterator() { - Iterator> iterator = observableMap.entrySet().iterator(); - assertTrue(iterator.hasNext()); - - Map.Entry toBeRemoved = iterator.next(); - String toBeRemovedKey = toBeRemoved.getKey(); - String toBeRemovedVal = toBeRemoved.getValue(); - - iterator.remove(); - - assertTrue(observableMap.size() == 2); - observer.assertRemoved(tup(toBeRemovedKey, toBeRemovedVal)); - } - - @Test - @SuppressWarnings("unchecked") - public void testEntrySet_Other() { - assertEquals(3, observableMap.entrySet().size()); - assertTrue(observableMap.entrySet().contains(entry("foo", "bar"))); - assertFalse(observableMap.entrySet().contains(entry("bar", "foo"))); - - assertTrue(observableMap.entrySet().containsAll(Arrays.asList(entry("one","1"), entry("two","2")))); - assertFalse(observableMap.entrySet().containsAll(Arrays.asList(entry("one","1"), entry("three","3")))); - - assertTrue(observableMap.entrySet().toArray(new Map.Entry[0]).length == 3); - assertTrue(observableMap.entrySet().toArray().length == 3); - } - - @Test - public void testObserverCanRemoveObservers() { - final MapChangeListener listObserver = change -> { - change.getMap().removeListener(observer); - }; - observableMap.addListener(listObserver); - observableMap.put("x", "x"); - observer.clear(); - observableMap.put("y", "y"); - observer.check0(); - observableMap.removeListener(listObserver); - - final StringMapChangeListener listener = new StringMapChangeListener(); - observableMap.addListener(listener); - observableMap.put("z", "z"); - assertEquals(listener.counter, 1); - observableMap.put("zz", "zz"); - assertEquals(listener.counter, 1); - } - - - private static class StringMapChangeListener implements MapChangeListener { - - private int counter; - - @Override - public void onChanged(Change change) { - change.getMap().removeListener(this); - ++counter; - } - } - - @Test - public void testEqualsAndHashCode() { - final Map other = new HashMap<>(observableMap); - assertTrue(observableMap.equals(other)); - assertEquals(observableMap.hashCode(), other.hashCode()); - } - - private Map.Entry entry(final K key, final V value) { - return new Map.Entry() { - - @Override - public K getKey() { - return key; - } - - @Override - public V getValue() { - return value; - } - - @Override - public V setValue(V value) { - throw new UnsupportedOperationException("Not supported."); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Map.Entry)) { - return false; - } - Map.Entry entry = (Map.Entry)obj; - return (getKey()==null ? - entry.getKey()==null : getKey().equals(entry.getKey())) && - (getValue()==null ? - entry.getValue()==null : getValue().equals(entry.getValue())); - } - - @Override - public int hashCode() { - return (getKey()==null ? 0 : getKey().hashCode()) ^ - (getValue()==null ? 0 : getValue().hashCode()); - } - - }; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/ObservableMapTest.java 2015-08-31 10:24:56.321216475 -0400 @@ -0,0 +1,476 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import javafx.collections.MapChangeListener; +import javafx.collections.ObservableMap; +import static test.javafx.collections.MockMapObserver.Call.call; +import static test.javafx.collections.MockMapObserver.Tuple.tup; +import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class ObservableMapTest { + + final Callable> mapFactory; + private ObservableMap observableMap; + private MockMapObserver observer; + + + public ObservableMapTest(final Callable> mapFactory) { + this.mapFactory = mapFactory; + } + + @Parameterized.Parameters + public static Collection createParameters() { + Object[][] data = new Object[][] { + { TestedObservableMaps.HASH_MAP }, + { TestedObservableMaps.TREE_MAP }, + { TestedObservableMaps.LINKED_HASH_MAP }, + { TestedObservableMaps.CONCURRENT_HASH_MAP }, + { TestedObservableMaps.CHECKED_OBSERVABLE_HASH_MAP }, + { TestedObservableMaps.SYNCHRONIZED_OBSERVABLE_HASH_MAP }, + { TestedObservableMaps.OBSERVABLE_MAP_PROPERTY } + }; + return Arrays.asList(data); + } + + @Before + public void setUp() throws Exception { + observableMap = mapFactory.call(); + observer = new MockMapObserver(); + observableMap.addListener(observer); + + useMapData(); + } + + /** + * Modifies the map in the fixture to use the strings passed in instead of + * the default strings, and re-creates the observable map and the observer. + * If no strings are passed in, the result is an empty map. + * + * @param strings the strings to use for the list in the fixture + */ + void useMapData(String... strings) { + observableMap.clear(); + observableMap.put("one", "1"); + observableMap.put("two", "2"); + observableMap.put("foo", "bar"); + observer.clear(); + } + + @Test + public void testPutRemove() { + observableMap.put("observedFoo", "barVal"); + observableMap.put("foo", "barfoo"); + assertEquals("barVal", observableMap.get("observedFoo")); + + observableMap.remove("observedFoo"); + observableMap.remove("foo"); + observableMap.remove("bar"); + observableMap.put("one", "1"); + + assertFalse(observableMap.containsKey("foo")); + + observer.assertAdded(0, tup("observedFoo", "barVal")); + observer.assertAdded(1, tup("foo", "barfoo")); + observer.assertRemoved(1, tup("foo", "bar")); + observer.assertRemoved(2, tup("observedFoo", "barVal")); + observer.assertRemoved(3, tup("foo", "barfoo")); + + assertEquals(observer.getCallsNumber(), 4); + } + + @Test + public void testPutRemove_Null() { + if (mapFactory instanceof TestedObservableMaps.CallableConcurrentHashMapImpl) { + return; // Do not perform on ConcurrentHashMap, as it doesn't accept nulls + } + observableMap.clear(); + observer.clear(); + + observableMap.put("bar", null); + observableMap.put("foo", "x"); + observableMap.put("bar", "x"); + observableMap.put("foo", null); + + assertEquals(2, observableMap.size()); + + observableMap.remove("bar"); + observableMap.remove("foo"); + + assertEquals(0, observableMap.size()); + + observer.assertAdded(0, tup("bar", (String)null)); + observer.assertAdded(1, tup("foo", "x")); + observer.assertAdded(2, tup("bar", "x")); + observer.assertRemoved(2, tup("bar", (String)null)); + observer.assertAdded(3, tup("foo", (String)null)); + observer.assertRemoved(3, tup("foo", "x")); + observer.assertRemoved(4, tup("bar", "x")); + observer.assertRemoved(5, tup("foo", (String)null)); + + assertEquals(observer.getCallsNumber(), 6); + } + + @Test + public void testPutRemove_NullKey() { + if (mapFactory instanceof TestedObservableMaps.CallableConcurrentHashMapImpl || + mapFactory instanceof TestedObservableMaps.CallableTreeMapImpl) { + return; // Do not perform on ConcurrentHashMap and TreeMap, as they doesn't accept null keys + } + + observableMap.put(null, "abc"); + + assertEquals(4, observableMap.size()); + + observableMap.remove(null); + + assertEquals(3, observableMap.size()); + + observer.assertAdded(0, tup((String)null, "abc")); + observer.assertRemoved(1, tup((String)null, "abc")); + + assertEquals(observer.getCallsNumber(), 2); + } + + @Test + @SuppressWarnings("unchecked") + public void testPutAll() { + Map map = new HashMap(); + map.put("oFoo", "OFoo"); + map.put("pFoo", "PFoo"); + map.put("foo", "foofoo"); + map.put("one", "1"); + observableMap.putAll(map); + + assertTrue(observableMap.containsKey("oFoo")); + observer.assertMultipleCalls(call("oFoo", null, "OFoo"), call("pFoo", null, "PFoo"), call("foo", "bar", "foofoo")); + } + + @Test + @SuppressWarnings("unchecked") + public void testClear() { + observableMap.clear(); + + assertTrue(observableMap.isEmpty()); + observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2"), tup("foo", "bar")); + + } + + @Test + public void testOther() { + assertEquals(3, observableMap.size()); + assertFalse(observableMap.isEmpty()); + + assertTrue(observableMap.containsKey("foo")); + assertFalse(observableMap.containsKey("bar")); + + assertFalse(observableMap.containsValue("foo")); + assertTrue(observableMap.containsValue("bar")); + } + + @Test + public void testKeySet_Remove() { + observableMap.keySet().remove("one"); + observableMap.keySet().remove("two"); + observableMap.keySet().remove("three"); + + observer.assertRemoved(0, tup("one", "1")); + observer.assertRemoved(1, tup("two", "2")); + assertTrue(observer.getCallsNumber() == 2); + } + + @Test + @SuppressWarnings("unchecked") + public void testKeySet_RemoveAll() { + observableMap.keySet().removeAll(Arrays.asList("one", "two", "three")); + + observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2")); + assertTrue(observableMap.size() == 1); + } + + @Test + public void testKeySet_RetainAll() { + observableMap.keySet().retainAll(Arrays.asList("one", "two", "three")); + + observer.assertRemoved(tup("foo", "bar")); + assertTrue(observableMap.size() == 2); + } + + @Test + @SuppressWarnings("unchecked") + public void testKeySet_Clear() { + observableMap.keySet().clear(); + assertTrue(observableMap.keySet().isEmpty()); + observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2"), tup("foo", "bar")); + } + + @Test + public void testKeySet_Iterator() { + Iterator iterator = observableMap.keySet().iterator(); + assertTrue(iterator.hasNext()); + + String toBeRemoved = iterator.next(); + String toBeRemovedVal = observableMap.get(toBeRemoved); + iterator.remove(); + + assertTrue(observableMap.size() == 2); + observer.assertRemoved(tup(toBeRemoved, toBeRemovedVal)); + } + + @Test + public void testKeySet_Other() { + assertEquals(3, observableMap.keySet().size()); + assertTrue(observableMap.keySet().contains("foo")); + assertFalse(observableMap.keySet().contains("bar")); + + assertTrue(observableMap.keySet().containsAll(Arrays.asList("one", "two"))); + assertFalse(observableMap.keySet().containsAll(Arrays.asList("one", "three"))); + + assertTrue(observableMap.keySet().toArray(new String[0]).length == 3); + assertTrue(observableMap.keySet().toArray().length == 3); + } + + @Test + public void testValues_Remove() { + observableMap.values().remove("1"); + observableMap.values().remove("2"); + observableMap.values().remove("3"); + + observer.assertRemoved(0, tup("one", "1")); + observer.assertRemoved(1, tup("two", "2")); + assertTrue(observer.getCallsNumber() == 2); + } + + @Test + @SuppressWarnings("unchecked") + public void testValues_RemoveAll() { + observableMap.values().removeAll(Arrays.asList("1", "2", "3")); + + observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2")); + assertTrue(observableMap.size() == 1); + } + + @Test + public void testValues_RetainAll() { + observableMap.values().retainAll(Arrays.asList("1", "2", "3")); + + observer.assertRemoved(tup("foo", "bar")); + assertTrue(observableMap.size() == 2); + } + + @Test + @SuppressWarnings("unchecked") + public void testValues_Clear() { + observableMap.values().clear(); + assertTrue(observableMap.values().isEmpty()); + observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2"), tup("foo", "bar")); + } + + @Test + public void testValues_Iterator() { + Iterator iterator = observableMap.values().iterator(); + assertTrue(iterator.hasNext()); + + String toBeRemovedVal = iterator.next(); + iterator.remove(); + + assertTrue(observableMap.size() == 2); + observer.assertRemoved(tup(toBeRemovedVal.equals("1") ? "one" + : toBeRemovedVal.equals("2") ? "two" + : toBeRemovedVal.equals("bar") ? "foo" : null, toBeRemovedVal)); + } + + @Test + public void testValues_Other() { + assertEquals(3, observableMap.values().size()); + assertFalse(observableMap.values().contains("foo")); + assertTrue(observableMap.values().contains("bar")); + + assertTrue(observableMap.values().containsAll(Arrays.asList("1", "2"))); + assertFalse(observableMap.values().containsAll(Arrays.asList("1", "3"))); + + assertTrue(observableMap.values().toArray(new String[0]).length == 3); + assertTrue(observableMap.values().toArray().length == 3); + } + + @Test + public void testEntrySet_Remove() { + observableMap.entrySet().remove(entry("one","1")); + observableMap.entrySet().remove(entry("two","2")); + observableMap.entrySet().remove(entry("three","3")); + + observer.assertRemoved(0, tup("one", "1")); + observer.assertRemoved(1, tup("two", "2")); + assertTrue(observer.getCallsNumber() == 2); + } + + @Test + @SuppressWarnings("unchecked") + public void testEntrySet_RemoveAll() { + observableMap.entrySet().removeAll(Arrays.asList(entry("one","1"), entry("two","2"), entry("three","3"))); + + observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2")); + assertTrue(observableMap.size() == 1); + } + + @Test + @SuppressWarnings("unchecked") + public void testEntrySet_RetainAll() { + observableMap.entrySet().retainAll(Arrays.asList(entry("one","1"), entry("two","2"), entry("three","3"))); + + observer.assertRemoved(tup("foo", "bar")); + assertTrue(observableMap.size() == 2); + } + + @Test + @SuppressWarnings("unchecked") + public void testEntrySet_Clear() { + observableMap.entrySet().clear(); + assertTrue(observableMap.entrySet().isEmpty()); + observer.assertMultipleRemoved(tup("one", "1"), tup("two", "2"), tup("foo", "bar")); + } + + @Test + public void testEntrySet_Iterator() { + Iterator> iterator = observableMap.entrySet().iterator(); + assertTrue(iterator.hasNext()); + + Map.Entry toBeRemoved = iterator.next(); + String toBeRemovedKey = toBeRemoved.getKey(); + String toBeRemovedVal = toBeRemoved.getValue(); + + iterator.remove(); + + assertTrue(observableMap.size() == 2); + observer.assertRemoved(tup(toBeRemovedKey, toBeRemovedVal)); + } + + @Test + @SuppressWarnings("unchecked") + public void testEntrySet_Other() { + assertEquals(3, observableMap.entrySet().size()); + assertTrue(observableMap.entrySet().contains(entry("foo", "bar"))); + assertFalse(observableMap.entrySet().contains(entry("bar", "foo"))); + + assertTrue(observableMap.entrySet().containsAll(Arrays.asList(entry("one","1"), entry("two","2")))); + assertFalse(observableMap.entrySet().containsAll(Arrays.asList(entry("one","1"), entry("three","3")))); + + assertTrue(observableMap.entrySet().toArray(new Map.Entry[0]).length == 3); + assertTrue(observableMap.entrySet().toArray().length == 3); + } + + @Test + public void testObserverCanRemoveObservers() { + final MapChangeListener listObserver = change -> { + change.getMap().removeListener(observer); + }; + observableMap.addListener(listObserver); + observableMap.put("x", "x"); + observer.clear(); + observableMap.put("y", "y"); + observer.check0(); + observableMap.removeListener(listObserver); + + final StringMapChangeListener listener = new StringMapChangeListener(); + observableMap.addListener(listener); + observableMap.put("z", "z"); + assertEquals(listener.counter, 1); + observableMap.put("zz", "zz"); + assertEquals(listener.counter, 1); + } + + + private static class StringMapChangeListener implements MapChangeListener { + + private int counter; + + @Override + public void onChanged(Change change) { + change.getMap().removeListener(this); + ++counter; + } + } + + @Test + public void testEqualsAndHashCode() { + final Map other = new HashMap<>(observableMap); + assertTrue(observableMap.equals(other)); + assertEquals(observableMap.hashCode(), other.hashCode()); + } + + private Map.Entry entry(final K key, final V value) { + return new Map.Entry() { + + @Override + public K getKey() { + return key; + } + + @Override + public V getValue() { + return value; + } + + @Override + public V setValue(V value) { + throw new UnsupportedOperationException("Not supported."); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Map.Entry)) { + return false; + } + Map.Entry entry = (Map.Entry)obj; + return (getKey()==null ? + entry.getKey()==null : getKey().equals(entry.getKey())) && + (getValue()==null ? + entry.getValue()==null : getValue().equals(entry.getValue())); + } + + @Override + public int hashCode() { + return (getKey()==null ? 0 : getKey().hashCode()) ^ + (getValue()==null ? 0 : getValue().hashCode()); + } + + }; + } +} --- old/modules/base/src/test/java/javafx/collections/ObservableSetTest.java 2015-08-31 10:24:57.093216466 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; - -import static javafx.collections.MockSetObserver.Call.*; -import static javafx.collections.MockSetObserver.Tuple.*; -import static org.junit.Assert.*; -import static org.junit.Assert.assertEquals; - -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -@RunWith(Parameterized.class) -public class ObservableSetTest { - - final Callable> setFactory; - private ObservableSet observableSet; - private MockSetObserver observer; - - public ObservableSetTest(final Callable> setFactory) { - this.setFactory = setFactory; - } - - @Parameterized.Parameters - public static Collection createParameters() { - Object[][] data = new Object[][] { - { TestedObservableSets.HASH_SET }, - { TestedObservableSets.TREE_SET }, - { TestedObservableSets.LINKED_HASH_SET }, - { TestedObservableSets.CHECKED_OBSERVABLE_HASH_SET }, - { TestedObservableSets.SYNCHRONIZED_OBSERVABLE_HASH_SET }, - { TestedObservableSets.OBSERVABLE_SET_PROPERTY } - }; - return Arrays.asList(data); - } - - @Before - public void setUp() throws Exception { - observableSet = setFactory.call(); - observer = new MockSetObserver(); - observableSet.addListener(observer); - - useSetData("one", "two", "foo"); - } - - /** - * Modifies the set in the fixture to use the strings passed in instead of - * the default strings, and re-creates the observable set and the observer. - * If no strings are passed in, the result is an empty set. - * - * @param strings the strings to use for the list in the fixture - */ - void useSetData(String... strings) { - observableSet.clear(); - observableSet.addAll(Arrays.asList(strings)); - observer.clear(); - } - - @Test - public void testAddRemove() { - observableSet.add("observedFoo"); - observableSet.add("foo"); - assertTrue(observableSet.contains("observedFoo")); - - observableSet.remove("observedFoo"); - observableSet.remove("foo"); - observableSet.remove("bar"); - observableSet.add("one"); - - assertFalse(observableSet.contains("foo")); - - observer.assertAdded(0, tup("observedFoo")); - observer.assertRemoved(1, tup("observedFoo")); - observer.assertRemoved(2, tup("foo")); - - assertEquals(observer.getCallsNumber(), 3); - } - - @Test - @SuppressWarnings("unchecked") - public void testAddAll() { - Set set = new HashSet(); - set.add("oFoo"); - set.add("pFoo"); - set.add("foo"); - set.add("one"); - observableSet.addAll(set); - - assertTrue(observableSet.contains("oFoo")); - observer.assertMultipleCalls(call(null, "oFoo"), call(null, "pFoo")); - } - - @Test - @SuppressWarnings("unchecked") - public void testRemoveAll() { - observableSet.removeAll(Arrays.asList("one", "two", "three")); - - observer.assertMultipleRemoved(tup("one"), tup("two")); - assertTrue(observableSet.size() == 1); - } - - @Test - @SuppressWarnings("unchecked") - public void testClear() { - observableSet.clear(); - - assertTrue(observableSet.isEmpty()); - observer.assertMultipleRemoved(tup("one"), tup("two"), tup("foo")); - - } - - @Test - public void testRetainAll() { - observableSet.retainAll(Arrays.asList("one", "two", "three")); - - observer.assertRemoved(tup("foo")); - assertTrue(observableSet.size() == 2); - } - - @Test - public void testIterator() { - Iterator iterator = observableSet.iterator(); - assertTrue(iterator.hasNext()); - - String toBeRemoved = iterator.next(); - iterator.remove(); - - assertTrue(observableSet.size() == 2); - observer.assertRemoved(tup(toBeRemoved)); - } - - @Test - public void testOther() { - assertEquals(3, observableSet.size()); - assertFalse(observableSet.isEmpty()); - - assertTrue(observableSet.contains("foo")); - assertFalse(observableSet.contains("bar")); - } - - @Test - public void testNull() { - if (setFactory instanceof TestedObservableSets.CallableTreeSetImpl) { - return; // TreeSet doesn't accept nulls - } - observableSet.add(null); - assertEquals(4, observableSet.size()); - - observer.assertAdded(tup((String)null)); - - observableSet.remove(null); - assertEquals(3, observableSet.size()); - observer.assertRemoved(tup((String)null)); - } - - - @Test - public void testObserverCanRemoveObservers() { - final SetChangeListener listObserver = change -> { - change.getSet().removeListener(observer); - }; - observableSet.addListener(listObserver); - observableSet.add("x"); - observer.clear(); - observableSet.add("y"); - observer.check0(); - observableSet.removeListener(listObserver); - - - final StringSetChangeListener listener = new StringSetChangeListener(); - observableSet.addListener(listener); - observableSet.add("z"); - assertEquals(listener.counter, 1); - observableSet.add("zz"); - assertEquals(listener.counter, 1); - } - - - private static class StringSetChangeListener implements SetChangeListener { - - private int counter; - - @Override - public void onChanged(final Change change) { - change.getSet().removeListener(this); - ++counter; - } - } - - @Test - public void testEqualsAndHashCode() { - final Set other = new HashSet<>(Arrays.asList("one", "two", "foo")); - assertTrue(observableSet.equals(other)); - assertEquals(observableSet.hashCode(), other.hashCode()); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/ObservableSetTest.java 2015-08-31 10:24:56.909216468 -0400 @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import javafx.collections.ObservableSet; +import javafx.collections.SetChangeListener; +import org.junit.Before; +import org.junit.Test; + +import static test.javafx.collections.MockSetObserver.Call.*; +import static test.javafx.collections.MockSetObserver.Tuple.*; +import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class ObservableSetTest { + + final Callable> setFactory; + private ObservableSet observableSet; + private MockSetObserver observer; + + public ObservableSetTest(final Callable> setFactory) { + this.setFactory = setFactory; + } + + @Parameterized.Parameters + public static Collection createParameters() { + Object[][] data = new Object[][] { + { TestedObservableSets.HASH_SET }, + { TestedObservableSets.TREE_SET }, + { TestedObservableSets.LINKED_HASH_SET }, + { TestedObservableSets.CHECKED_OBSERVABLE_HASH_SET }, + { TestedObservableSets.SYNCHRONIZED_OBSERVABLE_HASH_SET }, + { TestedObservableSets.OBSERVABLE_SET_PROPERTY } + }; + return Arrays.asList(data); + } + + @Before + public void setUp() throws Exception { + observableSet = setFactory.call(); + observer = new MockSetObserver(); + observableSet.addListener(observer); + + useSetData("one", "two", "foo"); + } + + /** + * Modifies the set in the fixture to use the strings passed in instead of + * the default strings, and re-creates the observable set and the observer. + * If no strings are passed in, the result is an empty set. + * + * @param strings the strings to use for the list in the fixture + */ + void useSetData(String... strings) { + observableSet.clear(); + observableSet.addAll(Arrays.asList(strings)); + observer.clear(); + } + + @Test + public void testAddRemove() { + observableSet.add("observedFoo"); + observableSet.add("foo"); + assertTrue(observableSet.contains("observedFoo")); + + observableSet.remove("observedFoo"); + observableSet.remove("foo"); + observableSet.remove("bar"); + observableSet.add("one"); + + assertFalse(observableSet.contains("foo")); + + observer.assertAdded(0, tup("observedFoo")); + observer.assertRemoved(1, tup("observedFoo")); + observer.assertRemoved(2, tup("foo")); + + assertEquals(observer.getCallsNumber(), 3); + } + + @Test + @SuppressWarnings("unchecked") + public void testAddAll() { + Set set = new HashSet(); + set.add("oFoo"); + set.add("pFoo"); + set.add("foo"); + set.add("one"); + observableSet.addAll(set); + + assertTrue(observableSet.contains("oFoo")); + observer.assertMultipleCalls(call(null, "oFoo"), call(null, "pFoo")); + } + + @Test + @SuppressWarnings("unchecked") + public void testRemoveAll() { + observableSet.removeAll(Arrays.asList("one", "two", "three")); + + observer.assertMultipleRemoved(tup("one"), tup("two")); + assertTrue(observableSet.size() == 1); + } + + @Test + @SuppressWarnings("unchecked") + public void testClear() { + observableSet.clear(); + + assertTrue(observableSet.isEmpty()); + observer.assertMultipleRemoved(tup("one"), tup("two"), tup("foo")); + + } + + @Test + public void testRetainAll() { + observableSet.retainAll(Arrays.asList("one", "two", "three")); + + observer.assertRemoved(tup("foo")); + assertTrue(observableSet.size() == 2); + } + + @Test + public void testIterator() { + Iterator iterator = observableSet.iterator(); + assertTrue(iterator.hasNext()); + + String toBeRemoved = iterator.next(); + iterator.remove(); + + assertTrue(observableSet.size() == 2); + observer.assertRemoved(tup(toBeRemoved)); + } + + @Test + public void testOther() { + assertEquals(3, observableSet.size()); + assertFalse(observableSet.isEmpty()); + + assertTrue(observableSet.contains("foo")); + assertFalse(observableSet.contains("bar")); + } + + @Test + public void testNull() { + if (setFactory instanceof TestedObservableSets.CallableTreeSetImpl) { + return; // TreeSet doesn't accept nulls + } + observableSet.add(null); + assertEquals(4, observableSet.size()); + + observer.assertAdded(tup((String)null)); + + observableSet.remove(null); + assertEquals(3, observableSet.size()); + observer.assertRemoved(tup((String)null)); + } + + + @Test + public void testObserverCanRemoveObservers() { + final SetChangeListener listObserver = change -> { + change.getSet().removeListener(observer); + }; + observableSet.addListener(listObserver); + observableSet.add("x"); + observer.clear(); + observableSet.add("y"); + observer.check0(); + observableSet.removeListener(listObserver); + + + final StringSetChangeListener listener = new StringSetChangeListener(); + observableSet.addListener(listener); + observableSet.add("z"); + assertEquals(listener.counter, 1); + observableSet.add("zz"); + assertEquals(listener.counter, 1); + } + + + private static class StringSetChangeListener implements SetChangeListener { + + private int counter; + + @Override + public void onChanged(final Change change) { + change.getSet().removeListener(this); + ++counter; + } + } + + @Test + public void testEqualsAndHashCode() { + final Set other = new HashSet<>(Arrays.asList("one", "two", "foo")); + assertTrue(observableSet.equals(other)); + assertEquals(observableSet.hashCode(), other.hashCode()); + } + +} --- old/modules/base/src/test/java/javafx/collections/ObservableSubListIteratorTest.java 2015-08-31 10:24:57.825216458 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - - -/** - * Tests for iterators of sublists of ObservableList. - * Note that this is a subclass of ObservableListIteratorTest. - * As such, it inherits all the tests from that class, but they - * are run using the sublist-based fixture. There are also some - * additional tests that make assertions about the underlying list - * after mutating the sublist via the iterator. - * - */ -@RunWith(Parameterized.class) -public class ObservableSubListIteratorTest extends ObservableListIteratorTest { - - // ========== Test Fixture ========== - - List fullList; - - public ObservableSubListIteratorTest(final Callable> listFactory) { - super(listFactory); - } - - @Parameterized.Parameters - public static Collection createParameters() { - Object[][] data = new Object[][] { - { TestedObservableLists.ARRAY_LIST }, - { TestedObservableLists.LINKED_LIST }, - { TestedObservableLists.VETOABLE_LIST }, - { TestedObservableLists.CHECKED_OBSERVABLE_ARRAY_LIST }, - { TestedObservableLists.SYNCHRONIZED_OBSERVABLE_ARRAY_LIST } - }; - return Arrays.asList(data); - } - - @Before @Override - public void setup() throws Exception { - list = listFactory.call(); - list.addAll( - Arrays.asList("P", "Q", "a", "b", "c", "d", "e", "f", "R", "S")); - fullList = list; - list = fullList.subList(2, 8); - iter = list.listIterator(); - } - - // ========== Sublist Iterator Tests ========== - - @Test - public void testSubAddBeginning() { - iter.add("X"); - assertEquals("[P, Q, X, a, b, c, d, e, f, R, S]", fullList.toString()); - } - - @Test - public void testSubAddMiddle() { - advance(iter, 3); - iter.add("X"); - assertEquals("[P, Q, a, b, c, X, d, e, f, R, S]", fullList.toString()); - } - - @Test - public void testSubAddEnd() { - toEnd(iter); - iter.add("X"); - assertEquals("[P, Q, a, b, c, d, e, f, X, R, S]", fullList.toString()); - } - - @Test - public void testSubRemoveBeginning() { - iter.next(); - iter.remove(); - assertEquals("[P, Q, b, c, d, e, f, R, S]", fullList.toString()); - } - - @Test - public void testSubRemoveMiddle() { - advance(iter, 3); - iter.remove(); - assertEquals("[P, Q, a, b, d, e, f, R, S]", fullList.toString()); - } - - @Test - public void testSubRemoveEnd() { - toEnd(iter); - iter.remove(); - assertEquals("[P, Q, a, b, c, d, e, R, S]", fullList.toString()); - } - - @Test - public void testSubSetBeginning() { - iter.next(); - iter.set("X"); - assertEquals("[P, Q, X, b, c, d, e, f, R, S]", fullList.toString()); - } - - @Test - public void testSubSetMiddle() { - advance(iter, 3); - iter.set("X"); - assertEquals("[P, Q, a, b, X, d, e, f, R, S]", fullList.toString()); - } - - @Test - public void testSubSetEnd() { - toEnd(iter); - iter.set("X"); - assertEquals("[P, Q, a, b, c, d, e, X, R, S]", fullList.toString()); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/ObservableSubListIteratorTest.java 2015-08-31 10:24:57.617216460 -0400 @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + + +/** + * Tests for iterators of sublists of ObservableList. + * Note that this is a subclass of ObservableListIteratorTest. + * As such, it inherits all the tests from that class, but they + * are run using the sublist-based fixture. There are also some + * additional tests that make assertions about the underlying list + * after mutating the sublist via the iterator. + * + */ +@RunWith(Parameterized.class) +public class ObservableSubListIteratorTest extends ObservableListIteratorTest { + + // ========== Test Fixture ========== + + List fullList; + + public ObservableSubListIteratorTest(final Callable> listFactory) { + super(listFactory); + } + + @Parameterized.Parameters + public static Collection createParameters() { + Object[][] data = new Object[][] { + { TestedObservableLists.ARRAY_LIST }, + { TestedObservableLists.LINKED_LIST }, + { TestedObservableLists.VETOABLE_LIST }, + { TestedObservableLists.CHECKED_OBSERVABLE_ARRAY_LIST }, + { TestedObservableLists.SYNCHRONIZED_OBSERVABLE_ARRAY_LIST } + }; + return Arrays.asList(data); + } + + @Before @Override + public void setup() throws Exception { + list = listFactory.call(); + list.addAll( + Arrays.asList("P", "Q", "a", "b", "c", "d", "e", "f", "R", "S")); + fullList = list; + list = fullList.subList(2, 8); + iter = list.listIterator(); + } + + // ========== Sublist Iterator Tests ========== + + @Test + public void testSubAddBeginning() { + iter.add("X"); + assertEquals("[P, Q, X, a, b, c, d, e, f, R, S]", fullList.toString()); + } + + @Test + public void testSubAddMiddle() { + advance(iter, 3); + iter.add("X"); + assertEquals("[P, Q, a, b, c, X, d, e, f, R, S]", fullList.toString()); + } + + @Test + public void testSubAddEnd() { + toEnd(iter); + iter.add("X"); + assertEquals("[P, Q, a, b, c, d, e, f, X, R, S]", fullList.toString()); + } + + @Test + public void testSubRemoveBeginning() { + iter.next(); + iter.remove(); + assertEquals("[P, Q, b, c, d, e, f, R, S]", fullList.toString()); + } + + @Test + public void testSubRemoveMiddle() { + advance(iter, 3); + iter.remove(); + assertEquals("[P, Q, a, b, d, e, f, R, S]", fullList.toString()); + } + + @Test + public void testSubRemoveEnd() { + toEnd(iter); + iter.remove(); + assertEquals("[P, Q, a, b, c, d, e, R, S]", fullList.toString()); + } + + @Test + public void testSubSetBeginning() { + iter.next(); + iter.set("X"); + assertEquals("[P, Q, X, b, c, d, e, f, R, S]", fullList.toString()); + } + + @Test + public void testSubSetMiddle() { + advance(iter, 3); + iter.set("X"); + assertEquals("[P, Q, a, b, X, d, e, f, R, S]", fullList.toString()); + } + + @Test + public void testSubSetEnd() { + toEnd(iter); + iter.set("X"); + assertEquals("[P, Q, a, b, c, d, e, X, R, S]", fullList.toString()); + } +} --- old/modules/base/src/test/java/javafx/collections/ObservableSubListTest.java 2015-08-31 10:24:58.581216449 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,454 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import org.junit.Before; -import org.junit.Test; - -import java.util.*; - -import static org.junit.Assert.*; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - * Tests for sublists of ObservableList. - * - */ -@RunWith(Parameterized.class) -public class ObservableSubListTest { - final Callable> listFactory; - ObservableList list; - List sublist; - private MockListObserver mlo; - - public ObservableSubListTest(final Callable> listFactory) { - this.listFactory = listFactory; - } - - @Parameterized.Parameters - public static Collection createParameters() { - Object[][] data = new Object[][] { - { TestedObservableLists.ARRAY_LIST }, - { TestedObservableLists.LINKED_LIST }, - { TestedObservableLists.VETOABLE_LIST }, - { TestedObservableLists.CHECKED_OBSERVABLE_ARRAY_LIST }, - { TestedObservableLists.SYNCHRONIZED_OBSERVABLE_ARRAY_LIST } - }; - return Arrays.asList(data); - } - - @Before - public void setup() throws Exception { - list = listFactory.call(); - mlo = new MockListObserver(); - list.addListener(mlo); - useListData("a", "b", "c", "d", "e", "f"); - sublist = list.subList(1, 5); - } - - /** - * Modifies the list in the fixture to use the strings passed in instead of - * the default strings, and re-creates the observable list and the observer. - * If no strings are passed in, the result is an empty list. - * - * @param strings the strings to use for the list in the fixture - */ - void useListData(String... strings) { - list.clear(); - list.addAll(Arrays.asList(strings)); - mlo.clear(); - } - - @Test(expected = IllegalArgumentException.class) - public void testBadRange() { - list.subList(3, 2); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void testRangeTooLow() { - list.subList(-2, 4); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void testRangeTooHigh() { - list.subList(3, 7); - } - - @Test - public void testWidestRange() { - List sub = list.subList(0, 6); - assertEquals("[a, b, c, d, e, f]", sub.toString()); - } - - @Test - public void testAdd() { - sublist.add("X"); - assertEquals("[b, c, d, e, X]", sublist.toString()); - assertEquals("[a, b, c, d, e, X, f]", list.toString()); - assertEquals(5, sublist.size()); - mlo.check1AddRemove(list, null, 5, 6); - } - - @Test - public void testAddAll() { - sublist.addAll(1, Arrays.asList("X", "Y", "Z")); - assertEquals("[b, X, Y, Z, c, d, e]", sublist.toString()); - assertEquals("[a, b, X, Y, Z, c, d, e, f]", list.toString()); - assertEquals(7, sublist.size()); - mlo.check1AddRemove(list, null, 2, 5); - } - - @Test - public void testClear() { - sublist.clear(); - assertEquals("[]", sublist.toString()); - assertEquals("[a, f]", list.toString()); - assertEquals(0, sublist.size()); - mlo.check1AddRemove(list, Arrays.asList("b", "c", "d", "e"), 1, 1); - } - - @Test - public void testContains() { - assertTrue(sublist.contains("c")); - assertFalse(sublist.contains("a")); - assertFalse(sublist.contains(null)); - assertFalse(sublist.contains(Integer.valueOf(7))); - } - - @Test - public void testContainsAll() { - assertTrue(sublist.containsAll(Arrays.asList("b", "c"))); - assertFalse(sublist.containsAll(Arrays.asList("a", "b"))); - } - - @Test - public void testContainsNull() { - list.add(3, null); - sublist = list.subList(1, 5); - assertTrue(sublist.contains(null)); - } - - @Test - public void testEqualsOnAnotherType() { - assertFalse(sublist.equals(Integer.valueOf(7))); - } - - @Test - public void testEqualsOnLongerList() { - List other = Arrays.asList("b", "c", "d", "e", "f"); - assertFalse(sublist.equals(other)); - assertTrue(other.hashCode() != sublist.hashCode()); - } - - @Test - public void testEqualsOnShorterList() { - List other = Arrays.asList("b", "c", "d"); - assertFalse(sublist.equals(other)); - assertTrue(other.hashCode() != sublist.hashCode()); - } - - @Test - public void testEquals() { - List other = Arrays.asList("b", "c", "d", "e"); - assertTrue(sublist.equals(other)); - assertEquals(other.hashCode(), sublist.hashCode()); - } - - @Test - public void testEqualsWithNull() { - sublist.add(2, null); - List other = Arrays.asList("b", "c", null, "e"); - assertFalse(sublist.equals(other)); - assertTrue(other.hashCode() != sublist.hashCode()); - } - - @Test - public void testEqualsWithNullOnLongerList() { - sublist.add(2, null); - List other = Arrays.asList("b", "c", null, "d", "e"); - assertTrue(sublist.equals(other)); - assertEquals(other.hashCode(), sublist.hashCode()); - } - - @Test - public void testEqualsWithNullOnShorterList() { - sublist.add(2, null); - List other = Arrays.asList("b", "c", null); - assertFalse(sublist.equals(other)); - assertTrue(other.hashCode() != sublist.hashCode()); - } - - @Test - public void testIndexOf() { - assertEquals(2, sublist.indexOf("d")); - assertEquals(-1, sublist.indexOf("a")); - } - - @Test - public void testIndexOfWithNull() { - sublist.add(2, null); - assertEquals(3, sublist.indexOf("d")); - assertEquals(2, sublist.indexOf(null)); - assertEquals(-1, sublist.indexOf("f")); - } - - @Test - public void testIsEmpty() { - assertFalse(sublist.isEmpty()); - List otherSublist = list.subList(2, 2); - assertTrue(otherSublist.isEmpty()); - } - - @Test - public void testLastIndexOf() { - list = FXCollections.observableList(new ArrayList()); - list.addAll(Arrays.asList("a", null, "a", null, "a", null, "a")); - sublist = list.subList(1, 5); - - assertEquals(3, sublist.lastIndexOf("a")); - assertEquals(2, sublist.lastIndexOf(null)); - } - - @Test - public void testRemoveAll() { - list = FXCollections.observableList(new ArrayList()); - list.addAll(Arrays.asList("a", "b", "c", "a", "b", "c")); - sublist = list.subList(2, 4); - list.addListener(mlo); - sublist.removeAll(Arrays.asList("a", "b", "c")); - - assertEquals("[]", sublist.toString()); - assertEquals(0, sublist.size()); - assertEquals("[a, b, b, c]", list.toString()); - mlo.check1AddRemove(list, Arrays.asList("c", "a"), 2, 2); - } - - @Test - public void testRemoveIndex() { - String s = sublist.remove(2); - assertEquals("d", s); - assertEquals(3, sublist.size()); - assertEquals("[b, c, e]", sublist.toString()); - assertEquals("[a, b, c, e, f]", list.toString()); - mlo.check1AddRemove(list, Collections.singletonList("d"), 3, 3); - } - - @Test - public void testRemoveNull() { - sublist.add(2, null); - assertTrue(sublist.remove(null)); - assertEquals(4, sublist.size()); - assertEquals("[b, c, d, e]", sublist.toString()); - assertEquals("[a, b, c, d, e, f]", list.toString()); - } - - @Test - public void testRemoveObjectExists() { - assertTrue(sublist.remove("b")); - assertEquals(3, sublist.size()); - assertEquals("[c, d, e]", sublist.toString()); - assertEquals("[a, c, d, e, f]", list.toString()); - mlo.check1AddRemove(list, Collections.singletonList("b"), 1, 1); - } - - @Test - public void testRemoveObjectNotExists() { - assertFalse(sublist.remove("f")); - assertEquals(4, sublist.size()); - assertEquals("[b, c, d, e]", sublist.toString()); - assertEquals("[a, b, c, d, e, f]", list.toString()); - mlo.check0(); - } - - @Test - public void testRetainAll() { - list = FXCollections.observableList(new ArrayList()); - list.addAll(Arrays.asList("a", "b", "c", "a", "b", "c")); - list.addListener(mlo); - sublist = list.subList(2, 4); - sublist.retainAll(Arrays.asList("c", "b")); - - assertEquals("[c]", sublist.toString()); - assertEquals(1, sublist.size()); - assertEquals("[a, b, c, b, c]", list.toString()); - mlo.check1AddRemove(list, Collections.singletonList("a"), 3, 3); - } - - @Test - public void testSet() { - String s = sublist.set(2, "X"); - assertEquals("d", s); - assertEquals("[b, c, X, e]", sublist.toString()); - assertEquals("[a, b, c, X, e, f]", list.toString()); - mlo.check1AddRemove(list, Collections.singletonList("d"), 3, 4); - } - - @Test - public void testSize() { - assertEquals(4, sublist.size()); - List otherSublist = list.subList(3, 3); - assertEquals(0, otherSublist.size()); - } - - @Test - public void testSubSubList() { - List subsublist = sublist.subList(1, 3); - assertEquals(2, subsublist.size()); - assertEquals("[c, d]", subsublist.toString()); - } - - @Test - public void testSubSubListAdd() { - List subsublist = sublist.subList(1, 3); - subsublist.add(1, "X"); - // sublist is now invalid - assertEquals("[c, X, d]", subsublist.toString()); - assertEquals("[a, b, c, X, d, e, f]", list.toString()); - } - - @Test - public void testSubSubListRemove() { - List subsublist = sublist.subList(1, 3); - assertEquals("c", subsublist.remove(0)); - // sublist is now invalid - assertEquals("[d]", subsublist.toString()); - assertEquals("[a, b, d, e, f]", list.toString()); - } - - @Test - public void testSubSubListSet() { - List subsublist = sublist.subList(1, 3); - String s = subsublist.set(1, "X"); - assertEquals("d", s); - assertEquals("[c, X]", subsublist.toString()); - assertEquals("[b, c, X, e]", sublist.toString()); - assertEquals("[a, b, c, X, e, f]", list.toString()); - } - - @Test - public void testToString() { - List sub0 = list.subList(3, 3); - List sub1 = list.subList(3, 4); - List sub2 = list.subList(2, 5); - - assertEquals("[]", sub0.toString()); - assertEquals("[d]", sub1.toString()); - assertEquals("[c, d, e]", sub2.toString()); - } - - @Test - public void testConcurrencyGet() { - list.add("x"); - try { sublist.get(0); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAdd() { - list.add("x"); - try { sublist.add("y"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyAddAll() { - list.add("x"); - try { sublist.addAll(Collections.singleton("y")); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyClear() { - list.add("x"); - try { sublist.addAll(Collections.singleton("y")); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyContains() { - list.add("x"); - try { sublist.contains("x"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyContainsAll() { - list.add("x"); - try { sublist.containsAll(Collections.singletonList("x")); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyIsEmpty() { - list.add("x"); - try { sublist.isEmpty(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyIterator() { - list.add("x"); - try { sublist.iterator().next(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRemove() { - list.add("x"); - try { sublist.remove("y"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRemove0() { - list.add("x"); - try { sublist.remove(0); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencySet() { - list.add("x"); - try { sublist.set(0, "y"); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRemoveAll() { - list.add("x"); - try { sublist.removeAll(Arrays.asList("c", "d")); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - - @Test - public void testConcurrencyRetainAll() { - list.add("x"); - try { sublist.retainAll(Arrays.asList("c", "d")); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } - @Test - public void testConcurrencyRetainSize() { - list.add("x"); - try { sublist.size(); } catch (ConcurrentModificationException e) {return;} - fail("Expected ConcurrentModificationException"); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/ObservableSubListTest.java 2015-08-31 10:24:58.445216451 -0400 @@ -0,0 +1,456 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import org.junit.Before; +import org.junit.Test; + +import java.util.*; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import static org.junit.Assert.*; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + * Tests for sublists of ObservableList. + * + */ +@RunWith(Parameterized.class) +public class ObservableSubListTest { + final Callable> listFactory; + ObservableList list; + List sublist; + private MockListObserver mlo; + + public ObservableSubListTest(final Callable> listFactory) { + this.listFactory = listFactory; + } + + @Parameterized.Parameters + public static Collection createParameters() { + Object[][] data = new Object[][] { + { TestedObservableLists.ARRAY_LIST }, + { TestedObservableLists.LINKED_LIST }, + { TestedObservableLists.VETOABLE_LIST }, + { TestedObservableLists.CHECKED_OBSERVABLE_ARRAY_LIST }, + { TestedObservableLists.SYNCHRONIZED_OBSERVABLE_ARRAY_LIST } + }; + return Arrays.asList(data); + } + + @Before + public void setup() throws Exception { + list = listFactory.call(); + mlo = new MockListObserver(); + list.addListener(mlo); + useListData("a", "b", "c", "d", "e", "f"); + sublist = list.subList(1, 5); + } + + /** + * Modifies the list in the fixture to use the strings passed in instead of + * the default strings, and re-creates the observable list and the observer. + * If no strings are passed in, the result is an empty list. + * + * @param strings the strings to use for the list in the fixture + */ + void useListData(String... strings) { + list.clear(); + list.addAll(Arrays.asList(strings)); + mlo.clear(); + } + + @Test(expected = IllegalArgumentException.class) + public void testBadRange() { + list.subList(3, 2); + } + + @Test(expected = IndexOutOfBoundsException.class) + public void testRangeTooLow() { + list.subList(-2, 4); + } + + @Test(expected = IndexOutOfBoundsException.class) + public void testRangeTooHigh() { + list.subList(3, 7); + } + + @Test + public void testWidestRange() { + List sub = list.subList(0, 6); + assertEquals("[a, b, c, d, e, f]", sub.toString()); + } + + @Test + public void testAdd() { + sublist.add("X"); + assertEquals("[b, c, d, e, X]", sublist.toString()); + assertEquals("[a, b, c, d, e, X, f]", list.toString()); + assertEquals(5, sublist.size()); + mlo.check1AddRemove(list, null, 5, 6); + } + + @Test + public void testAddAll() { + sublist.addAll(1, Arrays.asList("X", "Y", "Z")); + assertEquals("[b, X, Y, Z, c, d, e]", sublist.toString()); + assertEquals("[a, b, X, Y, Z, c, d, e, f]", list.toString()); + assertEquals(7, sublist.size()); + mlo.check1AddRemove(list, null, 2, 5); + } + + @Test + public void testClear() { + sublist.clear(); + assertEquals("[]", sublist.toString()); + assertEquals("[a, f]", list.toString()); + assertEquals(0, sublist.size()); + mlo.check1AddRemove(list, Arrays.asList("b", "c", "d", "e"), 1, 1); + } + + @Test + public void testContains() { + assertTrue(sublist.contains("c")); + assertFalse(sublist.contains("a")); + assertFalse(sublist.contains(null)); + assertFalse(sublist.contains(Integer.valueOf(7))); + } + + @Test + public void testContainsAll() { + assertTrue(sublist.containsAll(Arrays.asList("b", "c"))); + assertFalse(sublist.containsAll(Arrays.asList("a", "b"))); + } + + @Test + public void testContainsNull() { + list.add(3, null); + sublist = list.subList(1, 5); + assertTrue(sublist.contains(null)); + } + + @Test + public void testEqualsOnAnotherType() { + assertFalse(sublist.equals(Integer.valueOf(7))); + } + + @Test + public void testEqualsOnLongerList() { + List other = Arrays.asList("b", "c", "d", "e", "f"); + assertFalse(sublist.equals(other)); + assertTrue(other.hashCode() != sublist.hashCode()); + } + + @Test + public void testEqualsOnShorterList() { + List other = Arrays.asList("b", "c", "d"); + assertFalse(sublist.equals(other)); + assertTrue(other.hashCode() != sublist.hashCode()); + } + + @Test + public void testEquals() { + List other = Arrays.asList("b", "c", "d", "e"); + assertTrue(sublist.equals(other)); + assertEquals(other.hashCode(), sublist.hashCode()); + } + + @Test + public void testEqualsWithNull() { + sublist.add(2, null); + List other = Arrays.asList("b", "c", null, "e"); + assertFalse(sublist.equals(other)); + assertTrue(other.hashCode() != sublist.hashCode()); + } + + @Test + public void testEqualsWithNullOnLongerList() { + sublist.add(2, null); + List other = Arrays.asList("b", "c", null, "d", "e"); + assertTrue(sublist.equals(other)); + assertEquals(other.hashCode(), sublist.hashCode()); + } + + @Test + public void testEqualsWithNullOnShorterList() { + sublist.add(2, null); + List other = Arrays.asList("b", "c", null); + assertFalse(sublist.equals(other)); + assertTrue(other.hashCode() != sublist.hashCode()); + } + + @Test + public void testIndexOf() { + assertEquals(2, sublist.indexOf("d")); + assertEquals(-1, sublist.indexOf("a")); + } + + @Test + public void testIndexOfWithNull() { + sublist.add(2, null); + assertEquals(3, sublist.indexOf("d")); + assertEquals(2, sublist.indexOf(null)); + assertEquals(-1, sublist.indexOf("f")); + } + + @Test + public void testIsEmpty() { + assertFalse(sublist.isEmpty()); + List otherSublist = list.subList(2, 2); + assertTrue(otherSublist.isEmpty()); + } + + @Test + public void testLastIndexOf() { + list = FXCollections.observableList(new ArrayList()); + list.addAll(Arrays.asList("a", null, "a", null, "a", null, "a")); + sublist = list.subList(1, 5); + + assertEquals(3, sublist.lastIndexOf("a")); + assertEquals(2, sublist.lastIndexOf(null)); + } + + @Test + public void testRemoveAll() { + list = FXCollections.observableList(new ArrayList()); + list.addAll(Arrays.asList("a", "b", "c", "a", "b", "c")); + sublist = list.subList(2, 4); + list.addListener(mlo); + sublist.removeAll(Arrays.asList("a", "b", "c")); + + assertEquals("[]", sublist.toString()); + assertEquals(0, sublist.size()); + assertEquals("[a, b, b, c]", list.toString()); + mlo.check1AddRemove(list, Arrays.asList("c", "a"), 2, 2); + } + + @Test + public void testRemoveIndex() { + String s = sublist.remove(2); + assertEquals("d", s); + assertEquals(3, sublist.size()); + assertEquals("[b, c, e]", sublist.toString()); + assertEquals("[a, b, c, e, f]", list.toString()); + mlo.check1AddRemove(list, Collections.singletonList("d"), 3, 3); + } + + @Test + public void testRemoveNull() { + sublist.add(2, null); + assertTrue(sublist.remove(null)); + assertEquals(4, sublist.size()); + assertEquals("[b, c, d, e]", sublist.toString()); + assertEquals("[a, b, c, d, e, f]", list.toString()); + } + + @Test + public void testRemoveObjectExists() { + assertTrue(sublist.remove("b")); + assertEquals(3, sublist.size()); + assertEquals("[c, d, e]", sublist.toString()); + assertEquals("[a, c, d, e, f]", list.toString()); + mlo.check1AddRemove(list, Collections.singletonList("b"), 1, 1); + } + + @Test + public void testRemoveObjectNotExists() { + assertFalse(sublist.remove("f")); + assertEquals(4, sublist.size()); + assertEquals("[b, c, d, e]", sublist.toString()); + assertEquals("[a, b, c, d, e, f]", list.toString()); + mlo.check0(); + } + + @Test + public void testRetainAll() { + list = FXCollections.observableList(new ArrayList()); + list.addAll(Arrays.asList("a", "b", "c", "a", "b", "c")); + list.addListener(mlo); + sublist = list.subList(2, 4); + sublist.retainAll(Arrays.asList("c", "b")); + + assertEquals("[c]", sublist.toString()); + assertEquals(1, sublist.size()); + assertEquals("[a, b, c, b, c]", list.toString()); + mlo.check1AddRemove(list, Collections.singletonList("a"), 3, 3); + } + + @Test + public void testSet() { + String s = sublist.set(2, "X"); + assertEquals("d", s); + assertEquals("[b, c, X, e]", sublist.toString()); + assertEquals("[a, b, c, X, e, f]", list.toString()); + mlo.check1AddRemove(list, Collections.singletonList("d"), 3, 4); + } + + @Test + public void testSize() { + assertEquals(4, sublist.size()); + List otherSublist = list.subList(3, 3); + assertEquals(0, otherSublist.size()); + } + + @Test + public void testSubSubList() { + List subsublist = sublist.subList(1, 3); + assertEquals(2, subsublist.size()); + assertEquals("[c, d]", subsublist.toString()); + } + + @Test + public void testSubSubListAdd() { + List subsublist = sublist.subList(1, 3); + subsublist.add(1, "X"); + // sublist is now invalid + assertEquals("[c, X, d]", subsublist.toString()); + assertEquals("[a, b, c, X, d, e, f]", list.toString()); + } + + @Test + public void testSubSubListRemove() { + List subsublist = sublist.subList(1, 3); + assertEquals("c", subsublist.remove(0)); + // sublist is now invalid + assertEquals("[d]", subsublist.toString()); + assertEquals("[a, b, d, e, f]", list.toString()); + } + + @Test + public void testSubSubListSet() { + List subsublist = sublist.subList(1, 3); + String s = subsublist.set(1, "X"); + assertEquals("d", s); + assertEquals("[c, X]", subsublist.toString()); + assertEquals("[b, c, X, e]", sublist.toString()); + assertEquals("[a, b, c, X, e, f]", list.toString()); + } + + @Test + public void testToString() { + List sub0 = list.subList(3, 3); + List sub1 = list.subList(3, 4); + List sub2 = list.subList(2, 5); + + assertEquals("[]", sub0.toString()); + assertEquals("[d]", sub1.toString()); + assertEquals("[c, d, e]", sub2.toString()); + } + + @Test + public void testConcurrencyGet() { + list.add("x"); + try { sublist.get(0); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAdd() { + list.add("x"); + try { sublist.add("y"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyAddAll() { + list.add("x"); + try { sublist.addAll(Collections.singleton("y")); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyClear() { + list.add("x"); + try { sublist.addAll(Collections.singleton("y")); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyContains() { + list.add("x"); + try { sublist.contains("x"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyContainsAll() { + list.add("x"); + try { sublist.containsAll(Collections.singletonList("x")); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyIsEmpty() { + list.add("x"); + try { sublist.isEmpty(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyIterator() { + list.add("x"); + try { sublist.iterator().next(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRemove() { + list.add("x"); + try { sublist.remove("y"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRemove0() { + list.add("x"); + try { sublist.remove(0); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencySet() { + list.add("x"); + try { sublist.set(0, "y"); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRemoveAll() { + list.add("x"); + try { sublist.removeAll(Arrays.asList("c", "d")); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + + @Test + public void testConcurrencyRetainAll() { + list.add("x"); + try { sublist.retainAll(Arrays.asList("c", "d")); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } + @Test + public void testConcurrencyRetainSize() { + list.add("x"); + try { sublist.size(); } catch (ConcurrentModificationException e) {return;} + fail("Expected ConcurrentModificationException"); + } +} --- old/modules/base/src/test/java/javafx/collections/Person.java 2015-08-31 10:24:59.393216440 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; -import javafx.beans.Observable; -import javafx.beans.property.StringProperty; -import javafx.beans.property.StringPropertyBase; - -public class Person implements Comparable { - public StringProperty name = new StringPropertyBase("foo") { - - @Override - public Object getBean() { - return Person.this; - } - - @Override - public String getName() { - return "name"; - } - }; - - public Person(String name) { - this.name.set(name); - } - - public Person() { - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final Person other = (Person) obj; - if (this.name.get() != other.name.get() && (this.name.get() == null || !this.name.get().equals(other.name.get()))) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int hash = 7; - hash = 59 * hash + (this.name.get() != null ? this.name.get().hashCode() : 0); - return hash; - } - - @Override - public String toString() { - return "Person[" + name.get() + "]"; - } - - @Override - public int compareTo(Person o) { - return this.name.get().compareTo(o.name.get()); - } - - public static ObservableList createPersonsList(Person... persons) { - ObservableList list = FXCollections.observableArrayList( - (Person p) -> new Observable[]{p.name}); - list.addAll(persons); - return list; - } - - public static List createPersonsFromNames(String... names) { - return Arrays.asList(names).stream(). - map(name -> new Person(name)).collect(Collectors.toList()); - } - - public static ObservableList createPersonsList(String... names) { - ObservableList list = FXCollections.observableArrayList( - (Person p) -> new Observable[]{p.name}); - list.addAll(createPersonsFromNames(names)); - return list; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/Person.java 2015-08-31 10:24:59.181216443 -0400 @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import javafx.beans.Observable; +import javafx.beans.property.StringProperty; +import javafx.beans.property.StringPropertyBase; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +public class Person implements Comparable { + public StringProperty name = new StringPropertyBase("foo") { + + @Override + public Object getBean() { + return Person.this; + } + + @Override + public String getName() { + return "name"; + } + }; + + public Person(String name) { + this.name.set(name); + } + + public Person() { + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Person other = (Person) obj; + if (this.name.get() != other.name.get() && (this.name.get() == null || !this.name.get().equals(other.name.get()))) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 59 * hash + (this.name.get() != null ? this.name.get().hashCode() : 0); + return hash; + } + + @Override + public String toString() { + return "Person[" + name.get() + "]"; + } + + @Override + public int compareTo(Person o) { + return this.name.get().compareTo(o.name.get()); + } + + public static ObservableList createPersonsList(Person... persons) { + ObservableList list = FXCollections.observableArrayList( + (Person p) -> new Observable[]{p.name}); + list.addAll(persons); + return list; + } + + public static List createPersonsFromNames(String... names) { + return Arrays.asList(names).stream(). + map(name -> new Person(name)).collect(Collectors.toList()); + } + + public static ObservableList createPersonsList(String... names) { + ObservableList list = FXCollections.observableArrayList( + (Person p) -> new Observable[]{p.name}); + list.addAll(createPersonsFromNames(names)); + return list; + } +} --- old/modules/base/src/test/java/javafx/collections/SortedListTest.java 2015-08-31 10:25:00.189216431 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,483 +0,0 @@ -/* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import com.sun.javafx.collections.NonIterableChange.SimplePermutationChange; -import com.sun.javafx.collections.ObservableListWrapper; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Collections; -import java.util.Arrays; -import java.util.Comparator; -import java.util.Map; - -import javafx.beans.Observable; -import javafx.beans.property.SimpleObjectProperty; -import javafx.collections.transformation.SortedList; -import javafx.collections.transformation.TransformationList; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.* ; -import static org.junit.Assert.assertEquals; - -/** - * - */ -public class SortedListTest { - - private ObservableList list; - private MockListObserver mockListObserver; - private SortedList sortedList; - - @Before - public void setUp() { - list = FXCollections.observableArrayList(); - list.addAll("a", "c", "d", "c"); - sortedList = list.sorted(); - mockListObserver = new MockListObserver(); - sortedList.addListener(mockListObserver); - } - @Test - public void testNoChange() { - assertEquals(Arrays.asList("a", "c", "c", "d"), sortedList); - mockListObserver.check0(); - } - - @Test - public void testAdd() { - list.clear(); - mockListObserver.clear(); - assertEquals(Collections.emptyList(), sortedList); - list.addAll("a", "c", "d", "c"); - assertEquals(Arrays.asList("a", "c", "c", "d"), sortedList); - mockListObserver.check1AddRemove(sortedList, Collections.emptyList(), 0, 4); - assertEquals(0, sortedList.getSourceIndex(0)); - assertEquals(2, sortedList.getSourceIndex(3)); - } - - @Test - public void testAddSingle() { - list.add("b"); - assertEquals(Arrays.asList("a", "b", "c", "c", "d"), sortedList); - mockListObserver.check1AddRemove(sortedList, Collections.emptyList(), 1, 2); - assertEquals(0, sortedList.getSourceIndex(0)); - assertEquals(4, sortedList.getSourceIndex(1)); - assertEquals(1, sortedList.getSourceIndex(2)); - assertEquals(3, sortedList.getSourceIndex(3)); - assertEquals(2, sortedList.getSourceIndex(4)); - } - - @Test - public void testRemove() { - list.removeAll(Arrays.asList("c")); // removes "c", "d", "c", adds "d" - assertEquals(Arrays.asList("a", "d"), sortedList); - mockListObserver.check1AddRemove(sortedList, Arrays.asList("c", "c"), 1, 1); - assertEquals(0, sortedList.getSourceIndex(0)); - assertEquals(1, sortedList.getSourceIndex(1)); - mockListObserver.clear(); - list.removeAll(Arrays.asList("a", "d")); - mockListObserver.check1AddRemove(sortedList, Arrays.asList("a", "d"), 0, 0); - } - - @Test - public void testRemoveSingle() { - list.remove("a"); - assertEquals(Arrays.asList("c", "c", "d"), sortedList); - mockListObserver.check1AddRemove(sortedList, Arrays.asList("a"), 0, 0); - assertEquals(0, sortedList.getSourceIndex(0)); - assertEquals(2, sortedList.getSourceIndex(1)); - assertEquals(1, sortedList.getSourceIndex(2)); - } - - @Test - public void testMultipleOperations() { - list.remove(2); - assertEquals(Arrays.asList("a", "c", "c"), sortedList); - mockListObserver.check1AddRemove(sortedList, Arrays.asList("d"), 3, 3); - mockListObserver.clear(); - list.add("b"); - assertEquals(Arrays.asList("a", "b", "c", "c"), sortedList); - mockListObserver.check1AddRemove(sortedList, Collections.emptyList(), 1, 2); - } - - @Test - public void testPureRemove() { - list.removeAll(Arrays.asList("c", "d")); - mockListObserver.check1AddRemove(sortedList, Arrays.asList("c", "c", "d"), 1, 1); - assertEquals(0, sortedList.getSourceIndex(0)); - } - - @Test - public void testChangeComparator() { - SimpleObjectProperty> op = - new SimpleObjectProperty<>(Comparator.naturalOrder()); - - sortedList = new SortedList<>(list); - assertEquals(Arrays.asList("a", "c", "d", "c"), sortedList); - sortedList.comparatorProperty().bind(op); - assertEquals(Arrays.asList("a", "c", "c", "d"), sortedList); - sortedList.addListener(mockListObserver); - - op.set((Comparator) (String o1, String o2) -> -o1.compareTo(o2)); - assertEquals(Arrays.asList("d", "c", "c", "a"), sortedList); - mockListObserver.check1Permutation(sortedList, new int[] {3, 1, 2, 0}); // could be also 3, 2, 1, 0, but the algorithm goes this way - } - - - /** - * A slightly updated test provided by "Kleopatra" (http://javafx-jira.kenai.com/browse/RT-14400) - */ - @Test - public void testSourceIndex() { - final ObservableList sourceList = FXCollections.observableArrayList( - 1300., 400., 600. - ); - // the list to be removed again, note that its highest value is greater - // then the highest in the base list before adding - List other = Arrays.asList( - 50., -300., 4000. - ); - sourceList.addAll(other); - // wrap into a sorted list and add a listener to the sorted - final SortedList sorted = sourceList.sorted(); - ListChangeListener listener = c -> { - assertEquals(Arrays.asList(400.0, 600.0, 1300.0), c.getList()); - - c.next(); - assertEquals(Arrays.asList(-300.0, 50.0), c.getRemoved()); - assertEquals(0, c.getFrom()); - assertEquals(0, c.getTo()); - assertTrue(c.next()); - assertEquals(Arrays.asList(4000.), c.getRemoved()); - assertEquals(3, c.getFrom()); - assertEquals(3, c.getTo()); - assertFalse(c.next()); - - - // grab sourceIndex of last (aka: highest) value in sorted list - int sourceIndex = sorted.getSourceIndex(sorted.size() - 1); - assertEquals(0, sourceIndex); - }; - sorted.addListener(listener); - sourceList.removeAll(other); - } - - @Test - public void testMutableElement() { - ObservableList list = createPersonsList(); - - SortedList sorted = list.sorted(); - assertEquals(Arrays.asList( - new Person("five"), new Person("four"), new Person("one"), - new Person("three"), new Person("two")), - sorted); - MockListObserver listener = new MockListObserver<>(); - sorted.addListener(listener); - list.get(3).name.set("zero"); // four -> zero - ObservableList expected = FXCollections.observableArrayList( - new Person("five"), new Person("one"), new Person("three"), - new Person("two"), new Person("zero")); - listener.checkPermutation(0, expected, 0, list.size(), new int[]{0, 4, 1, 2, 3}); - listener.checkUpdate(1, expected, 4, 5); - assertEquals(expected, sorted); - } - - @Test - public void testMutableElementUnsorted_rt39541() { - ObservableList list = createPersonsList(); - SortedList unsorted = new SortedList<>(list); - MockListObserver listener = new MockListObserver<>(); - unsorted.addListener(listener); - list.get(3).name.set("zero"); // four -> zero - ObservableList expected = FXCollections.observableArrayList( - new Person("one"), new Person("two"), new Person("three"), - new Person("zero"), new Person("five")); - listener.check1Update(expected, 3, 4); - } - - @Test - public void testMutableElementUnsortedChain_rt39541() { - ObservableList items = createPersonsList(); - - SortedList sorted = items.sorted(); - SortedList unsorted = new SortedList<>(sorted); - - assertEquals(sorted, unsorted); - - MockListObserver listener = new MockListObserver<>(); - unsorted.addListener(listener); - items.get(3).name.set("zero"); // "four" -> "zero" - ObservableList expected = FXCollections.observableArrayList( - new Person("five"), new Person("one"), new Person("three"), - new Person("two"), new Person("zero")); - listener.checkPermutation(0, expected, 0, expected.size(), new int[] {0, 4, 1, 2, 3}); - listener.checkUpdate(1, expected, 4, 5); - assertEquals(expected, sorted); - assertEquals(expected, unsorted); - } - - private ObservableList createPersonsList() { - ObservableList list = FXCollections.observableArrayList( - (Person p) -> new Observable[]{p.name}); - list.addAll( - new Person("one"), new Person("two"), new Person("three"), - new Person("four"), new Person("five")); - return list; - } - - @Test - public void testNotComparable() { - final Object o1 = new Object() { - - @Override - public String toString() { - return "c"; - } - }; - final Object o2 = new Object() { - - @Override - public String toString() { - return "a"; - } - }; - final Object o3 = new Object() { - - @Override - public String toString() { - return "d"; - } - }; - ObservableList list = FXCollections.observableArrayList(o1, o2, o3); - - SortedList sorted = list.sorted(); - assertEquals(Arrays.asList(o2, o1, o3), sorted); - } - - @Test - public void testCompareNulls() { - ObservableList list = FXCollections.observableArrayList( "g", "a", null, "z"); - - TransformationList sorted = list.sorted(); - assertEquals(Arrays.asList(null, "a", "g", "z"), sorted); - } - - - private static class Permutator extends ObservableListWrapper { - private List backingList; - public Permutator(List list) { - super(list); - this.backingList = list; - } - - public void swap() { - E first = get(0); - backingList.set(0, get(size() - 1)); - backingList.set(size() -1, first); - fireChange(new SimplePermutationChange(0, size(), new int[] {2, 1, 0}, this)); - } - - } - /** - * SortedList cant cope with permutations. - */ - @Test - public void testPermutate() { - List list = new ArrayList(); - for (int i = 0; i < 3; i++) { - list.add(i); - } - Permutator permutator = new Permutator(list); - SortedList sorted = new SortedList(permutator); - permutator.swap(); - assertEquals(0, sorted.getSourceIndex(sorted.size() - 1)); - } - - @Test - public void testUnsorted() { - SortedList sorted = new SortedList<>(list); - assertEquals(sorted, list); - assertEquals(list, sorted); - - list.removeAll("a", "d"); - - assertEquals(sorted, list); - - list.addAll(0, Arrays.asList("a", "b", "c")); - - assertEquals(sorted, list); - - FXCollections.sort(list); - - assertEquals(sorted, list); - - } - - @Test - public void testSortedNaturalOrder() { - assertEquals(Arrays.asList("a", "c", "c", "d"), list.sorted()); - } - - @Test - public void testRemoveFromDuplicates() { - String toRemove = new String("A"); - String other = new String("A"); - list = FXCollections.observableArrayList(other, toRemove); - Comparator c = Comparator.naturalOrder(); - SortedList sorted = list.sorted(c); - - list.remove(1); - - assertEquals(1, sorted.size()); - assertTrue(sorted.get(0) == other); - } - - @Test - public void testAddAllOnEmpty() { - list = FXCollections.observableArrayList(); - SortedList sl = list.sorted(String.CASE_INSENSITIVE_ORDER); - list.addAll("B", "A"); - - assertEquals(Arrays.asList("A", "B"), sl); - } - - @Test - public void test_rt36353_sortedList() { - ObservableList data = FXCollections.observableArrayList("2", "1", "3"); - SortedList sortedList = new SortedList(data); - - HashMap pMap = new HashMap<>(); - sortedList.addListener((ListChangeListener) c -> { - while (c.next()) { - if (c.wasPermutated()) { - for (int i = c.getFrom(); i < c.getTo(); i++) { - pMap.put(i, c.getPermutation(i)); - } - } - } - }); - - Map expected = new HashMap<>(); - - // comparator that will create list of [1,2,3]. Sort indices based on - // previous order [2,1,3]. - sortedList.setComparator((s1,s2) -> s1.compareTo(s2)); - assertEquals(FXCollections.observableArrayList("1","2","3"), sortedList); - expected.put(0, 1); // item "2" has moved from index 0 to index 1 - expected.put(1, 0); // item "1" has moved from index 1 to index 0 - expected.put(2, 2); // item "3" has remained in index 2 - assertEquals(expected, pMap); - - // comparator that will create list of [3,2,1]. Sort indices based on - // previous order [1,2,3]. - sortedList.setComparator((s1,s2) -> s2.compareTo(s1)); - assertEquals(FXCollections.observableArrayList("3","2","1"), sortedList); - expected.clear(); - expected.put(0, 2); // item "1" has moved from index 0 to index 2 - expected.put(1, 1); // item "2" has remained in index 1 - expected.put(2, 0); // item "3" has moved from index 2 to index 0 - assertEquals(expected, pMap); - - // null comparator so sort order should return to [2,1,3]. Sort indices based on - // previous order [3,2,1]. - sortedList.setComparator(null); - assertEquals(FXCollections.observableArrayList("2","1","3"), sortedList); - expected.clear(); - expected.put(0, 2); // item "3" has moved from index 0 to index 2 - expected.put(1, 0); // item "2" has moved from index 1 to index 0 - expected.put(2, 1); // item "1" has moved from index 2 to index 1 - assertEquals(expected, pMap); - } - - - @Test - public void testAddWhenUnsorted() { - sortedList.setComparator(null); - mockListObserver.clear(); - list.add(2, "b"); - assertEquals(5, sortedList.size()); - assertEquals(Arrays.asList("a", "c", "b", "d", "c"), sortedList); - mockListObserver.check1AddRemove(sortedList, Collections.emptyList(), 2, 3); - - mockListObserver.clear(); - sortedList.setComparator(Comparator.naturalOrder()); - mockListObserver.check1Permutation(sortedList, new int[] {0, 2, 1, 4, 3}); - assertEquals(5, sortedList.size()); - assertEquals(Arrays.asList("a", "b", "c", "c", "d"), sortedList); - - mockListObserver.clear(); - sortedList.setComparator(null); - assertEquals(5, sortedList.size()); - assertEquals(Arrays.asList("a", "c", "b", "d", "c"), sortedList); - mockListObserver.check1Permutation(sortedList, new int[] {0, 2, 1, 4, 3}); - - } - - @Test - public void testRemoveWhenUnsorted() { - sortedList.setComparator(null); - mockListObserver.clear(); - list.remove(1); - assertEquals(3, sortedList.size()); - assertEquals(Arrays.asList("a", "d", "c"), sortedList); - mockListObserver.check1AddRemove(sortedList, Arrays.asList("c"), 1, 1); - - mockListObserver.clear(); - sortedList.setComparator(Comparator.naturalOrder()); - mockListObserver.check1Permutation(sortedList, new int[] {0, 2, 1}); - assertEquals(3, sortedList.size()); - assertEquals(Arrays.asList("a", "c", "d"), sortedList); - - mockListObserver.clear(); - sortedList.setComparator(null); - assertEquals(3, sortedList.size()); - assertEquals(Arrays.asList("a", "d", "c"), sortedList); - mockListObserver.check1Permutation(sortedList, new int[] {0, 2, 1}); - } - - @Test - public void testSetWhenUnsorted() { - sortedList.setComparator(null); - mockListObserver.clear(); - list.set(1, "e"); - assertEquals(4, sortedList.size()); - assertEquals(Arrays.asList("a", "e", "d", "c"), sortedList); - mockListObserver.check1AddRemove(sortedList, Arrays.asList("c"), 1, 2); - - mockListObserver.clear(); - sortedList.setComparator(Comparator.naturalOrder()); - mockListObserver.check1Permutation(sortedList, new int[] {0, 3, 2, 1}); - assertEquals(4, sortedList.size()); - assertEquals(Arrays.asList("a", "c", "d", "e"), sortedList); - - mockListObserver.clear(); - sortedList.setComparator(null); - assertEquals(4, sortedList.size()); - assertEquals(Arrays.asList("a", "e", "d", "c"), sortedList); - mockListObserver.check1Permutation(sortedList, new int[] {0, 3, 2, 1}); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/SortedListTest.java 2015-08-31 10:24:59.981216434 -0400 @@ -0,0 +1,490 @@ +/* + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import test.javafx.collections.Person; +import test.javafx.collections.MockListObserver; +import com.sun.javafx.collections.NonIterableChange.SimplePermutationChange; +import com.sun.javafx.collections.ObservableListWrapper; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Collections; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Map; + +import javafx.beans.Observable; +import javafx.beans.property.SimpleObjectProperty; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import javafx.collections.ObservableListWrapperShim; +import javafx.collections.transformation.SortedList; +import javafx.collections.transformation.TransformationList; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.* ; +import static org.junit.Assert.assertEquals; + +/** + * + */ +public class SortedListTest { + + private ObservableList list; + private MockListObserver mockListObserver; + private SortedList sortedList; + + @Before + public void setUp() { + list = FXCollections.observableArrayList(); + list.addAll("a", "c", "d", "c"); + sortedList = list.sorted(); + mockListObserver = new MockListObserver(); + sortedList.addListener(mockListObserver); + } + @Test + public void testNoChange() { + assertEquals(Arrays.asList("a", "c", "c", "d"), sortedList); + mockListObserver.check0(); + } + + @Test + public void testAdd() { + list.clear(); + mockListObserver.clear(); + assertEquals(Collections.emptyList(), sortedList); + list.addAll("a", "c", "d", "c"); + assertEquals(Arrays.asList("a", "c", "c", "d"), sortedList); + mockListObserver.check1AddRemove(sortedList, Collections.emptyList(), 0, 4); + assertEquals(0, sortedList.getSourceIndex(0)); + assertEquals(2, sortedList.getSourceIndex(3)); + } + + @Test + public void testAddSingle() { + list.add("b"); + assertEquals(Arrays.asList("a", "b", "c", "c", "d"), sortedList); + mockListObserver.check1AddRemove(sortedList, Collections.emptyList(), 1, 2); + assertEquals(0, sortedList.getSourceIndex(0)); + assertEquals(4, sortedList.getSourceIndex(1)); + assertEquals(1, sortedList.getSourceIndex(2)); + assertEquals(3, sortedList.getSourceIndex(3)); + assertEquals(2, sortedList.getSourceIndex(4)); + } + + @Test + public void testRemove() { + list.removeAll(Arrays.asList("c")); // removes "c", "d", "c", adds "d" + assertEquals(Arrays.asList("a", "d"), sortedList); + mockListObserver.check1AddRemove(sortedList, Arrays.asList("c", "c"), 1, 1); + assertEquals(0, sortedList.getSourceIndex(0)); + assertEquals(1, sortedList.getSourceIndex(1)); + mockListObserver.clear(); + list.removeAll(Arrays.asList("a", "d")); + mockListObserver.check1AddRemove(sortedList, Arrays.asList("a", "d"), 0, 0); + } + + @Test + public void testRemoveSingle() { + list.remove("a"); + assertEquals(Arrays.asList("c", "c", "d"), sortedList); + mockListObserver.check1AddRemove(sortedList, Arrays.asList("a"), 0, 0); + assertEquals(0, sortedList.getSourceIndex(0)); + assertEquals(2, sortedList.getSourceIndex(1)); + assertEquals(1, sortedList.getSourceIndex(2)); + } + + @Test + public void testMultipleOperations() { + list.remove(2); + assertEquals(Arrays.asList("a", "c", "c"), sortedList); + mockListObserver.check1AddRemove(sortedList, Arrays.asList("d"), 3, 3); + mockListObserver.clear(); + list.add("b"); + assertEquals(Arrays.asList("a", "b", "c", "c"), sortedList); + mockListObserver.check1AddRemove(sortedList, Collections.emptyList(), 1, 2); + } + + @Test + public void testPureRemove() { + list.removeAll(Arrays.asList("c", "d")); + mockListObserver.check1AddRemove(sortedList, Arrays.asList("c", "c", "d"), 1, 1); + assertEquals(0, sortedList.getSourceIndex(0)); + } + + @Test + public void testChangeComparator() { + SimpleObjectProperty> op = + new SimpleObjectProperty<>(Comparator.naturalOrder()); + + sortedList = new SortedList<>(list); + assertEquals(Arrays.asList("a", "c", "d", "c"), sortedList); + sortedList.comparatorProperty().bind(op); + assertEquals(Arrays.asList("a", "c", "c", "d"), sortedList); + sortedList.addListener(mockListObserver); + + op.set((Comparator) (String o1, String o2) -> -o1.compareTo(o2)); + assertEquals(Arrays.asList("d", "c", "c", "a"), sortedList); + mockListObserver.check1Permutation(sortedList, new int[] {3, 1, 2, 0}); // could be also 3, 2, 1, 0, but the algorithm goes this way + } + + + /** + * A slightly updated test provided by "Kleopatra" (http://javafx-jira.kenai.com/browse/RT-14400) + */ + @Test + public void testSourceIndex() { + final ObservableList sourceList = FXCollections.observableArrayList( + 1300., 400., 600. + ); + // the list to be removed again, note that its highest value is greater + // then the highest in the base list before adding + List other = Arrays.asList( + 50., -300., 4000. + ); + sourceList.addAll(other); + // wrap into a sorted list and add a listener to the sorted + final SortedList sorted = sourceList.sorted(); + ListChangeListener listener = c -> { + assertEquals(Arrays.asList(400.0, 600.0, 1300.0), c.getList()); + + c.next(); + assertEquals(Arrays.asList(-300.0, 50.0), c.getRemoved()); + assertEquals(0, c.getFrom()); + assertEquals(0, c.getTo()); + assertTrue(c.next()); + assertEquals(Arrays.asList(4000.), c.getRemoved()); + assertEquals(3, c.getFrom()); + assertEquals(3, c.getTo()); + assertFalse(c.next()); + + + // grab sourceIndex of last (aka: highest) value in sorted list + int sourceIndex = sorted.getSourceIndex(sorted.size() - 1); + assertEquals(0, sourceIndex); + }; + sorted.addListener(listener); + sourceList.removeAll(other); + } + + @Test + public void testMutableElement() { + ObservableList list = createPersonsList(); + + SortedList sorted = list.sorted(); + assertEquals(Arrays.asList( + new Person("five"), new Person("four"), new Person("one"), + new Person("three"), new Person("two")), + sorted); + MockListObserver listener = new MockListObserver<>(); + sorted.addListener(listener); + list.get(3).name.set("zero"); // four -> zero + ObservableList expected = FXCollections.observableArrayList( + new Person("five"), new Person("one"), new Person("three"), + new Person("two"), new Person("zero")); + listener.checkPermutation(0, expected, 0, list.size(), new int[]{0, 4, 1, 2, 3}); + listener.checkUpdate(1, expected, 4, 5); + assertEquals(expected, sorted); + } + + @Test + public void testMutableElementUnsorted_rt39541() { + ObservableList list = createPersonsList(); + SortedList unsorted = new SortedList<>(list); + MockListObserver listener = new MockListObserver<>(); + unsorted.addListener(listener); + list.get(3).name.set("zero"); // four -> zero + ObservableList expected = FXCollections.observableArrayList( + new Person("one"), new Person("two"), new Person("three"), + new Person("zero"), new Person("five")); + listener.check1Update(expected, 3, 4); + } + + @Test + public void testMutableElementUnsortedChain_rt39541() { + ObservableList items = createPersonsList(); + + SortedList sorted = items.sorted(); + SortedList unsorted = new SortedList<>(sorted); + + assertEquals(sorted, unsorted); + + MockListObserver listener = new MockListObserver<>(); + unsorted.addListener(listener); + items.get(3).name.set("zero"); // "four" -> "zero" + ObservableList expected = FXCollections.observableArrayList( + new Person("five"), new Person("one"), new Person("three"), + new Person("two"), new Person("zero")); + listener.checkPermutation(0, expected, 0, expected.size(), new int[] {0, 4, 1, 2, 3}); + listener.checkUpdate(1, expected, 4, 5); + assertEquals(expected, sorted); + assertEquals(expected, unsorted); + } + + private ObservableList createPersonsList() { + ObservableList list = FXCollections.observableArrayList( + (Person p) -> new Observable[]{p.name}); + list.addAll( + new Person("one"), new Person("two"), new Person("three"), + new Person("four"), new Person("five")); + return list; + } + + @Test + public void testNotComparable() { + final Object o1 = new Object() { + + @Override + public String toString() { + return "c"; + } + }; + final Object o2 = new Object() { + + @Override + public String toString() { + return "a"; + } + }; + final Object o3 = new Object() { + + @Override + public String toString() { + return "d"; + } + }; + ObservableList list = FXCollections.observableArrayList(o1, o2, o3); + + SortedList sorted = list.sorted(); + assertEquals(Arrays.asList(o2, o1, o3), sorted); + } + + @Test + public void testCompareNulls() { + ObservableList list = FXCollections.observableArrayList( "g", "a", null, "z"); + + TransformationList sorted = list.sorted(); + assertEquals(Arrays.asList(null, "a", "g", "z"), sorted); + } + + + private static class Permutator extends ObservableListWrapper { + private List backingList; + public Permutator(List list) { + super(list); + this.backingList = list; + } + + public void swap() { + E first = get(0); + backingList.set(0, get(size() - 1)); + backingList.set(size() -1, first); + ObservableListWrapperShim.fireChange(this, + new SimplePermutationChange(0, size(), new int[] {2, 1, 0}, this)); + } + + } + /** + * SortedList cant cope with permutations. + */ + @Test + public void testPermutate() { + List list = new ArrayList(); + for (int i = 0; i < 3; i++) { + list.add(i); + } + Permutator permutator = new Permutator(list); + SortedList sorted = new SortedList(permutator); + permutator.swap(); + assertEquals(0, sorted.getSourceIndex(sorted.size() - 1)); + } + + @Test + public void testUnsorted() { + SortedList sorted = new SortedList<>(list); + assertEquals(sorted, list); + assertEquals(list, sorted); + + list.removeAll("a", "d"); + + assertEquals(sorted, list); + + list.addAll(0, Arrays.asList("a", "b", "c")); + + assertEquals(sorted, list); + + FXCollections.sort(list); + + assertEquals(sorted, list); + + } + + @Test + public void testSortedNaturalOrder() { + assertEquals(Arrays.asList("a", "c", "c", "d"), list.sorted()); + } + + @Test + public void testRemoveFromDuplicates() { + String toRemove = new String("A"); + String other = new String("A"); + list = FXCollections.observableArrayList(other, toRemove); + Comparator c = Comparator.naturalOrder(); + SortedList sorted = list.sorted(c); + + list.remove(1); + + assertEquals(1, sorted.size()); + assertTrue(sorted.get(0) == other); + } + + @Test + public void testAddAllOnEmpty() { + list = FXCollections.observableArrayList(); + SortedList sl = list.sorted(String.CASE_INSENSITIVE_ORDER); + list.addAll("B", "A"); + + assertEquals(Arrays.asList("A", "B"), sl); + } + + @Test + public void test_rt36353_sortedList() { + ObservableList data = FXCollections.observableArrayList("2", "1", "3"); + SortedList sortedList = new SortedList(data); + + HashMap pMap = new HashMap<>(); + sortedList.addListener((ListChangeListener) c -> { + while (c.next()) { + if (c.wasPermutated()) { + for (int i = c.getFrom(); i < c.getTo(); i++) { + pMap.put(i, c.getPermutation(i)); + } + } + } + }); + + Map expected = new HashMap<>(); + + // comparator that will create list of [1,2,3]. Sort indices based on + // previous order [2,1,3]. + sortedList.setComparator((s1,s2) -> s1.compareTo(s2)); + assertEquals(FXCollections.observableArrayList("1","2","3"), sortedList); + expected.put(0, 1); // item "2" has moved from index 0 to index 1 + expected.put(1, 0); // item "1" has moved from index 1 to index 0 + expected.put(2, 2); // item "3" has remained in index 2 + assertEquals(expected, pMap); + + // comparator that will create list of [3,2,1]. Sort indices based on + // previous order [1,2,3]. + sortedList.setComparator((s1,s2) -> s2.compareTo(s1)); + assertEquals(FXCollections.observableArrayList("3","2","1"), sortedList); + expected.clear(); + expected.put(0, 2); // item "1" has moved from index 0 to index 2 + expected.put(1, 1); // item "2" has remained in index 1 + expected.put(2, 0); // item "3" has moved from index 2 to index 0 + assertEquals(expected, pMap); + + // null comparator so sort order should return to [2,1,3]. Sort indices based on + // previous order [3,2,1]. + sortedList.setComparator(null); + assertEquals(FXCollections.observableArrayList("2","1","3"), sortedList); + expected.clear(); + expected.put(0, 2); // item "3" has moved from index 0 to index 2 + expected.put(1, 0); // item "2" has moved from index 1 to index 0 + expected.put(2, 1); // item "1" has moved from index 2 to index 1 + assertEquals(expected, pMap); + } + + + @Test + public void testAddWhenUnsorted() { + sortedList.setComparator(null); + mockListObserver.clear(); + list.add(2, "b"); + assertEquals(5, sortedList.size()); + assertEquals(Arrays.asList("a", "c", "b", "d", "c"), sortedList); + mockListObserver.check1AddRemove(sortedList, Collections.emptyList(), 2, 3); + + mockListObserver.clear(); + sortedList.setComparator(Comparator.naturalOrder()); + mockListObserver.check1Permutation(sortedList, new int[] {0, 2, 1, 4, 3}); + assertEquals(5, sortedList.size()); + assertEquals(Arrays.asList("a", "b", "c", "c", "d"), sortedList); + + mockListObserver.clear(); + sortedList.setComparator(null); + assertEquals(5, sortedList.size()); + assertEquals(Arrays.asList("a", "c", "b", "d", "c"), sortedList); + mockListObserver.check1Permutation(sortedList, new int[] {0, 2, 1, 4, 3}); + + } + + @Test + public void testRemoveWhenUnsorted() { + sortedList.setComparator(null); + mockListObserver.clear(); + list.remove(1); + assertEquals(3, sortedList.size()); + assertEquals(Arrays.asList("a", "d", "c"), sortedList); + mockListObserver.check1AddRemove(sortedList, Arrays.asList("c"), 1, 1); + + mockListObserver.clear(); + sortedList.setComparator(Comparator.naturalOrder()); + mockListObserver.check1Permutation(sortedList, new int[] {0, 2, 1}); + assertEquals(3, sortedList.size()); + assertEquals(Arrays.asList("a", "c", "d"), sortedList); + + mockListObserver.clear(); + sortedList.setComparator(null); + assertEquals(3, sortedList.size()); + assertEquals(Arrays.asList("a", "d", "c"), sortedList); + mockListObserver.check1Permutation(sortedList, new int[] {0, 2, 1}); + } + + @Test + public void testSetWhenUnsorted() { + sortedList.setComparator(null); + mockListObserver.clear(); + list.set(1, "e"); + assertEquals(4, sortedList.size()); + assertEquals(Arrays.asList("a", "e", "d", "c"), sortedList); + mockListObserver.check1AddRemove(sortedList, Arrays.asList("c"), 1, 2); + + mockListObserver.clear(); + sortedList.setComparator(Comparator.naturalOrder()); + mockListObserver.check1Permutation(sortedList, new int[] {0, 3, 2, 1}); + assertEquals(4, sortedList.size()); + assertEquals(Arrays.asList("a", "c", "d", "e"), sortedList); + + mockListObserver.clear(); + sortedList.setComparator(null); + assertEquals(4, sortedList.size()); + assertEquals(Arrays.asList("a", "e", "d", "c"), sortedList); + mockListObserver.check1Permutation(sortedList, new int[] {0, 3, 2, 1}); + } +} --- old/modules/base/src/test/java/javafx/collections/SourceAdapterChangeTest.java 2015-08-31 10:25:00.821216424 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import com.sun.javafx.collections.VetoableListDecorator; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import javafx.beans.Observable; -import javafx.collections.transformation.SortedList; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -@RunWith(Parameterized.class) -public class SourceAdapterChangeTest { - - @FunctionalInterface - public interface ListFactory { - public ObservableList createList(ObservableList items); - } - - private static final ListFactory unmodifiableObservableList = - items -> FXCollections.unmodifiableObservableList(items); - private static final ListFactory checkedObservableList = - items -> FXCollections.checkedObservableList(items, Person.class); - private static final ListFactory synchronizedObservableList = - items -> FXCollections.synchronizedObservableList(items); - private static final ListFactory vetoableListDecorator = - items -> new VetoableListDecorator(items) { - - @Override - protected void onProposedChange(List added, int[] removed) { - } - }; - - @Parameterized.Parameters - public static Collection createParameters() { - Object[][] data = new Object[][] { - { unmodifiableObservableList }, - { checkedObservableList }, - { synchronizedObservableList }, - { vetoableListDecorator }, - }; - return Arrays.asList(data); - } - - final ListFactory listFactory; - ObservableList items; - ObservableList list; - MockListObserver mlo; - - public SourceAdapterChangeTest(ListFactory listFactory) { - this.listFactory = listFactory; - } - - @Before - public void setUp() throws Exception { - items = FXCollections.observableArrayList( - (Person p) -> new Observable[]{p.name}); - items.addAll( - new Person("one"), new Person("two"), new Person("three"), - new Person("four"), new Person("five")); - list = listFactory.createList(items); - mlo = new MockListObserver<>(); - list.addListener(mlo); - } - - @Test - public void testUpdate() { - items.get(3).name.set("zero"); // four -> zero - ObservableList expected = FXCollections.observableArrayList( - new Person("one"), new Person("two"), new Person("three"), - new Person("zero"), new Person("five")); - mlo.check1Update(expected, 3, 4); - } - - @Test - public void testPermutation() { - FXCollections.sort(items); - ObservableList expected = FXCollections.observableArrayList( - new Person("five"), new Person("four"), new Person("one"), - new Person("three"), new Person("two")); - mlo.check1Permutation(expected, new int[]{2, 4, 3, 1, 0}); - } - - @Test - public void testPermutationUpdate() { - SortedList sorted = items.sorted((o1, o2) -> o1.compareTo(o2)); - list.removeListener(mlo); - list = listFactory.createList(sorted); - list.addListener(mlo); - items.get(3).name.set("zero"); // four -> zero - ObservableList expected = FXCollections.observableArrayList( - new Person("five"), new Person("one"), new Person("three"), - new Person("two"), new Person("zero")); - mlo.checkPermutation(0, expected, 0, expected.size(), new int[] {0, 4, 1, 2, 3}); - mlo.checkUpdate(1, expected, 4, 5); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/SourceAdapterChangeTest.java 2015-08-31 10:25:00.685216426 -0400 @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import com.sun.javafx.collections.VetoableListDecorator; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import javafx.beans.Observable; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.collections.transformation.SortedList; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class SourceAdapterChangeTest { + + @FunctionalInterface + public interface ListFactory { + public ObservableList createList(ObservableList items); + } + + private static final ListFactory unmodifiableObservableList = + items -> FXCollections.unmodifiableObservableList(items); + private static final ListFactory checkedObservableList = + items -> FXCollections.checkedObservableList(items, Person.class); + private static final ListFactory synchronizedObservableList = + items -> FXCollections.synchronizedObservableList(items); + private static final ListFactory vetoableListDecorator = + items -> new VetoableListDecorator(items) { + + @Override + protected void onProposedChange(List added, int[] removed) { + } + }; + + @Parameterized.Parameters + public static Collection createParameters() { + Object[][] data = new Object[][] { + { unmodifiableObservableList }, + { checkedObservableList }, + { synchronizedObservableList }, + { vetoableListDecorator }, + }; + return Arrays.asList(data); + } + + final ListFactory listFactory; + ObservableList items; + ObservableList list; + MockListObserver mlo; + + public SourceAdapterChangeTest(ListFactory listFactory) { + this.listFactory = listFactory; + } + + @Before + public void setUp() throws Exception { + items = FXCollections.observableArrayList( + (Person p) -> new Observable[]{p.name}); + items.addAll( + new Person("one"), new Person("two"), new Person("three"), + new Person("four"), new Person("five")); + list = listFactory.createList(items); + mlo = new MockListObserver<>(); + list.addListener(mlo); + } + + @Test + public void testUpdate() { + items.get(3).name.set("zero"); // four -> zero + ObservableList expected = FXCollections.observableArrayList( + new Person("one"), new Person("two"), new Person("three"), + new Person("zero"), new Person("five")); + mlo.check1Update(expected, 3, 4); + } + + @Test + public void testPermutation() { + FXCollections.sort(items); + ObservableList expected = FXCollections.observableArrayList( + new Person("five"), new Person("four"), new Person("one"), + new Person("three"), new Person("two")); + mlo.check1Permutation(expected, new int[]{2, 4, 3, 1, 0}); + } + + @Test + public void testPermutationUpdate() { + SortedList sorted = items.sorted((o1, o2) -> o1.compareTo(o2)); + list.removeListener(mlo); + list = listFactory.createList(sorted); + list.addListener(mlo); + items.get(3).name.set("zero"); // four -> zero + ObservableList expected = FXCollections.observableArrayList( + new Person("five"), new Person("one"), new Person("three"), + new Person("two"), new Person("zero")); + mlo.checkPermutation(0, expected, 0, expected.size(), new int[] {0, 4, 1, 2, 3}); + mlo.checkUpdate(1, expected, 4, 5); + } +} --- old/modules/base/src/test/java/javafx/collections/TestedObservableLists.java 2015-08-31 10:25:01.557216416 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import com.sun.javafx.collections.VetoableListDecorator; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import javafx.beans.property.SimpleListProperty; - -public interface TestedObservableLists { - - Callable> ARRAY_LIST = () -> FXCollections.observableList(new ArrayList()); - - Callable> LINKED_LIST = () -> FXCollections.observableList(new LinkedList()); - - Callable> VETOABLE_LIST = () -> new VetoableListDecorator(FXCollections.observableArrayList()) { - - @Override - protected void onProposedChange(List list, int[] idx) { } - }; - - Callable> CHECKED_OBSERVABLE_ARRAY_LIST = () -> FXCollections.checkedObservableList(FXCollections.observableList(new ArrayList()), String.class); - - Callable> SYNCHRONIZED_OBSERVABLE_ARRAY_LIST = () -> FXCollections.synchronizedObservableList(FXCollections.observableList(new ArrayList())); - - Callable> OBSERVABLE_LIST_PROPERTY = () -> new SimpleListProperty<>(FXCollections.observableList(new ArrayList())); - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/TestedObservableLists.java 2015-08-31 10:25:01.393216418 -0400 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import com.sun.javafx.collections.VetoableListDecorator; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import javafx.beans.property.SimpleListProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +public interface TestedObservableLists { + + Callable> ARRAY_LIST = () -> FXCollections.observableList(new ArrayList()); + + Callable> LINKED_LIST = () -> FXCollections.observableList(new LinkedList()); + + Callable> VETOABLE_LIST = () -> new VetoableListDecorator(FXCollections.observableArrayList()) { + + @Override + protected void onProposedChange(List list, int[] idx) { } + }; + + Callable> CHECKED_OBSERVABLE_ARRAY_LIST = () -> FXCollections.checkedObservableList(FXCollections.observableList(new ArrayList()), String.class); + + Callable> SYNCHRONIZED_OBSERVABLE_ARRAY_LIST = () -> FXCollections.synchronizedObservableList(FXCollections.observableList(new ArrayList())); + + Callable> OBSERVABLE_LIST_PROPERTY = () -> new SimpleListProperty<>(FXCollections.observableList(new ArrayList())); + +} --- old/modules/base/src/test/java/javafx/collections/TestedObservableMaps.java 2015-08-31 10:25:02.233216408 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.TreeMap; -import java.util.concurrent.ConcurrentHashMap; -import javafx.beans.property.SimpleMapProperty; - -public interface TestedObservableMaps { - - Callable> HASH_MAP = () -> FXCollections.observableMap(new HashMap()); - - Callable> TREE_MAP = new CallableTreeMapImpl(); - - Callable> LINKED_HASH_MAP = () -> FXCollections.observableMap(new LinkedHashMap()); - - Callable> CONCURRENT_HASH_MAP = new CallableConcurrentHashMapImpl(); - - Callable> CHECKED_OBSERVABLE_HASH_MAP = () -> FXCollections.checkedObservableMap(FXCollections.observableMap(new HashMap()), String.class, String.class); - - Callable> SYNCHRONIZED_OBSERVABLE_HASH_MAP = () -> FXCollections.synchronizedObservableMap(FXCollections.observableMap(new HashMap())); - - Callable> OBSERVABLE_MAP_PROPERTY = () -> new SimpleMapProperty<>(FXCollections.observableMap(new HashMap())); - - static class CallableTreeMapImpl implements Callable> { - public CallableTreeMapImpl() { - } - - @Override - public ObservableMap call() throws Exception { - return FXCollections.observableMap(new TreeMap()); - } - } - - static class CallableConcurrentHashMapImpl implements Callable> { - public CallableConcurrentHashMapImpl() { - } - - @Override - public ObservableMap call() throws Exception { - return FXCollections.observableMap(new ConcurrentHashMap()); - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/TestedObservableMaps.java 2015-08-31 10:25:02.101216410 -0400 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; +import javafx.beans.property.SimpleMapProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableMap; + +public interface TestedObservableMaps { + + Callable> HASH_MAP = () -> FXCollections.observableMap(new HashMap()); + + Callable> TREE_MAP = new CallableTreeMapImpl(); + + Callable> LINKED_HASH_MAP = () -> FXCollections.observableMap(new LinkedHashMap()); + + Callable> CONCURRENT_HASH_MAP = new CallableConcurrentHashMapImpl(); + + Callable> CHECKED_OBSERVABLE_HASH_MAP = () -> FXCollections.checkedObservableMap(FXCollections.observableMap(new HashMap()), String.class, String.class); + + Callable> SYNCHRONIZED_OBSERVABLE_HASH_MAP = () -> FXCollections.synchronizedObservableMap(FXCollections.observableMap(new HashMap())); + + Callable> OBSERVABLE_MAP_PROPERTY = () -> new SimpleMapProperty<>(FXCollections.observableMap(new HashMap())); + + static class CallableTreeMapImpl implements Callable> { + public CallableTreeMapImpl() { + } + + @Override + public ObservableMap call() throws Exception { + return FXCollections.observableMap(new TreeMap()); + } + } + + static class CallableConcurrentHashMapImpl implements Callable> { + public CallableConcurrentHashMapImpl() { + } + + @Override + public ObservableMap call() throws Exception { + return FXCollections.observableMap(new ConcurrentHashMap()); + } + } + +} --- old/modules/base/src/test/java/javafx/collections/TestedObservableSets.java 2015-08-31 10:25:02.933216401 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.TreeSet; -import javafx.beans.property.SimpleSetProperty; - -public interface TestedObservableSets { - - Callable> HASH_SET = () -> FXCollections.observableSet(new HashSet()); - - Callable> TREE_SET = new CallableTreeSetImpl(); - - Callable> LINKED_HASH_SET = () -> FXCollections.observableSet(new LinkedHashSet()); - - Callable> CHECKED_OBSERVABLE_HASH_SET = () -> FXCollections.checkedObservableSet(FXCollections.observableSet(new HashSet()), String.class); - - Callable> SYNCHRONIZED_OBSERVABLE_HASH_SET = () -> FXCollections.synchronizedObservableSet(FXCollections.observableSet(new HashSet())); - - Callable> OBSERVABLE_SET_PROPERTY = () -> new SimpleSetProperty<>(FXCollections.observableSet(new HashSet())); - - static class CallableTreeSetImpl implements Callable> { - public CallableTreeSetImpl() { - } - - @Override - public ObservableSet call() throws Exception { - return FXCollections.observableSet(new TreeSet()); - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/TestedObservableSets.java 2015-08-31 10:25:02.801216402 -0400 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.TreeSet; +import javafx.beans.property.SimpleSetProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableSet; + +public interface TestedObservableSets { + + Callable> HASH_SET = () -> FXCollections.observableSet(new HashSet()); + + Callable> TREE_SET = new CallableTreeSetImpl(); + + Callable> LINKED_HASH_SET = () -> FXCollections.observableSet(new LinkedHashSet()); + + Callable> CHECKED_OBSERVABLE_HASH_SET = () -> FXCollections.checkedObservableSet(FXCollections.observableSet(new HashSet()), String.class); + + Callable> SYNCHRONIZED_OBSERVABLE_HASH_SET = () -> FXCollections.synchronizedObservableSet(FXCollections.observableSet(new HashSet())); + + Callable> OBSERVABLE_SET_PROPERTY = () -> new SimpleSetProperty<>(FXCollections.observableSet(new HashSet())); + + static class CallableTreeSetImpl implements Callable> { + public CallableTreeSetImpl() { + } + + @Override + public ObservableSet call() throws Exception { + return FXCollections.observableSet(new TreeSet()); + } + } +} --- old/modules/base/src/test/java/javafx/collections/TransformationListTest.java 2015-08-31 10:25:03.557216394 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import javafx.collections.ListChangeListener.Change; -import javafx.collections.transformation.TransformationList; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import static org.junit.Assert.* ; - -/** - * - */ -@Ignore -public class TransformationListTest { - - private static class TransformationListImpl extends TransformationList { - - public TransformationListImpl(ObservableList list) { - super(list); - } - - @Override - protected void sourceChanged(Change change) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public String get(int index) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public int size() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean addAll(String... es) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean setAll(String... es) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean setAll(Collection clctn) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public int getSourceIndex(int i) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean removeAll(String... es) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean retainAll(String... es) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void remove(int i, int i1) { - throw new UnsupportedOperationException("Not supported yet."); - } - - } - - private TransformationList list1, list2; - private ObservableList list3; - - @Before - public void setUp() { - list3 = FXCollections.observableArrayList(); - list2 = new TransformationListImpl(list3); - list1 = new TransformationListImpl(list2); - } - - @Test - public void testDirect() { - assertEquals(list2, list1.getSource()); - assertEquals(list3, list2.getSource()); - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/TransformationListTest.java 2015-08-31 10:25:03.425216395 -0400 @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener.Change; +import javafx.collections.ObservableList; +import javafx.collections.transformation.TransformationList; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import static org.junit.Assert.* ; + +/** + * + */ +@Ignore +public class TransformationListTest { + + private static class TransformationListImpl extends TransformationList { + + public TransformationListImpl(ObservableList list) { + super(list); + } + + @Override + protected void sourceChanged(Change change) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String get(int index) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int size() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean addAll(String... es) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean setAll(String... es) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean setAll(Collection clctn) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int getSourceIndex(int i) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean removeAll(String... es) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean retainAll(String... es) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void remove(int i, int i1) { + throw new UnsupportedOperationException("Not supported yet."); + } + + } + + private TransformationList list1, list2; + private ObservableList list3; + + @Before + public void setUp() { + list3 = FXCollections.observableArrayList(); + list2 = new TransformationListImpl(list3); + list1 = new TransformationListImpl(list2); + } + + @Test + public void testDirect() { + assertEquals(list2, list1.getSource()); + assertEquals(list3, list2.getSource()); + } + +} --- old/modules/base/src/test/java/javafx/collections/UnmodifiableObservableMapTest.java 2015-08-31 10:25:04.177216387 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,252 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import static javafx.collections.MockMapObserver.Tuple.tup; -import static org.junit.Assert.*; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -@RunWith(Parameterized.class) -public class UnmodifiableObservableMapTest { - - final Callable> mapFactory; - private ObservableMap observableMap; - private ObservableMap unmodifiableMap; - private MockMapObserver observer; - - - public UnmodifiableObservableMapTest(final Callable> mapFactory) { - this.mapFactory = mapFactory; - } - - @Parameterized.Parameters - public static Collection createParameters() { - Object[][] data = new Object[][] { - { TestedObservableMaps.HASH_MAP }, - { TestedObservableMaps.TREE_MAP }, - { TestedObservableMaps.LINKED_HASH_MAP }, - { TestedObservableMaps.CONCURRENT_HASH_MAP }, - { TestedObservableMaps.CHECKED_OBSERVABLE_HASH_MAP }, - { TestedObservableMaps.SYNCHRONIZED_OBSERVABLE_HASH_MAP } - }; - return Arrays.asList(data); - } - - @Before - @SuppressWarnings("unchecked") - public void setUp() throws Exception { - observableMap = mapFactory.call(); - unmodifiableMap = FXCollections.unmodifiableObservableMap(observableMap); - observer = new MockMapObserver(); - unmodifiableMap.addListener(observer); - - useMapData(); - } - - /** - * Modifies the map in the fixture to use the strings passed in instead of - * the default strings, and re-creates the observable map and the observer. - * If no strings are passed in, the result is an empty map. - * - * @param strings the strings to use for the list in the fixture - */ - void useMapData(String... strings) { - observableMap.clear(); - observableMap.put("one", "1"); - observableMap.put("two", "2"); - observableMap.put("foo", "bar"); - observer.clear(); - } - - @Test - public void testObservability() { - /* - * Since unmodifiable ObservableMap wraps an ObservableMap, we need to test - * Observability of changes to the underlying Map, we won't test the full - * ObservableMap API since that is already done. - */ - observableMap.put("observedFoo", "barVal"); - observableMap.put("foo", "barfoo"); - assertEquals("barVal", unmodifiableMap.get("observedFoo")); - - observableMap.remove("observedFoo"); - observableMap.remove("foo"); - observableMap.remove("bar"); - observableMap.put("one", "1"); // dup, no change - assertFalse(unmodifiableMap.containsKey("foo")); - - observer.assertAdded(0, tup("observedFoo", "barVal")); - observer.assertAdded(1, tup("foo", "barfoo")); - observer.assertRemoved(1, tup("foo", "bar")); - observer.assertRemoved(2, tup("observedFoo", "barVal")); - observer.assertRemoved(3, tup("foo", "barfoo")); - assertEquals(observer.getCallsNumber(), 4); - } - - @Test - public void testPutAll() { - Map map = new HashMap(); - map.put("oFoo", "OFoo"); - map.put("pFoo", "PFoo"); - map.put("foo", "foofoo"); - map.put("one", "1"); - try { - unmodifiableMap.putAll(map); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - } - - @Test - public void testClear() { - try { - unmodifiableMap.clear(); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - } - - @Test - public void testKeySet() { - try { - unmodifiableMap.keySet().remove("one"); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - try { - unmodifiableMap.keySet().removeAll(Arrays.asList("one", "two", "three")); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - try { - unmodifiableMap.keySet().retainAll(Arrays.asList("one", "two", "three")); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - try { - unmodifiableMap.keySet().clear(); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - } - - @Test - public void testKeySet_Iterator() { - // iterators should not be removable - Iterator iterator = unmodifiableMap.keySet().iterator(); - assertTrue("Test error, underlying Map should not be empty!", iterator.hasNext()); - try { - iterator.remove(); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - } - - @Test - public void testValues() { - try { - unmodifiableMap.values().remove("1"); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - try { - unmodifiableMap.values().removeAll(Arrays.asList("1", "2", "3")); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - try { - unmodifiableMap.values().retainAll(Arrays.asList("1", "2", "3")); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - try { - unmodifiableMap.values().clear(); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - } - - @Test - public void testValues_Iterator() { - Iterator iterator = unmodifiableMap.values().iterator(); - assertTrue("Test error, underlying Map should not be empty!", iterator.hasNext()); - try { - iterator.remove(); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - } - - @Test - @SuppressWarnings("unchecked") - public void testEntrySet() { - try { - unmodifiableMap.entrySet().remove(entry("one","1")); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - try { - unmodifiableMap.entrySet().removeAll(Arrays.asList(entry("one","1"), entry("two","2"), entry("three","3"))); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - try { - unmodifiableMap.entrySet().retainAll(Arrays.asList(entry("one","1"), entry("two","2"), entry("three","3"))); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - try { - unmodifiableMap.entrySet().clear(); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - } - - @Test - public void testEntrySet_Iterator() { - Iterator> iterator = unmodifiableMap.entrySet().iterator(); - assertTrue("Test error, underlying Map should not be empty!", iterator.hasNext()); - try { - iterator.remove(); - fail("Expected UnsupportedOperationException"); - } catch(UnsupportedOperationException e) {} - } - - private Map.Entry entry(final K key, final V value) { - return new Map.Entry() { - - @Override - public K getKey() { - return key; - } - - @Override - public V getValue() { - return value; - } - - @Override - public V setValue(V value) { - throw new UnsupportedOperationException("Not supported."); - } - - }; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/UnmodifiableObservableMapTest.java 2015-08-31 10:25:04.041216388 -0400 @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableMap; +import static test.javafx.collections.MockMapObserver.Tuple.tup; +import static org.junit.Assert.*; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class UnmodifiableObservableMapTest { + + final Callable> mapFactory; + private ObservableMap observableMap; + private ObservableMap unmodifiableMap; + private MockMapObserver observer; + + + public UnmodifiableObservableMapTest(final Callable> mapFactory) { + this.mapFactory = mapFactory; + } + + @Parameterized.Parameters + public static Collection createParameters() { + Object[][] data = new Object[][] { + { TestedObservableMaps.HASH_MAP }, + { TestedObservableMaps.TREE_MAP }, + { TestedObservableMaps.LINKED_HASH_MAP }, + { TestedObservableMaps.CONCURRENT_HASH_MAP }, + { TestedObservableMaps.CHECKED_OBSERVABLE_HASH_MAP }, + { TestedObservableMaps.SYNCHRONIZED_OBSERVABLE_HASH_MAP } + }; + return Arrays.asList(data); + } + + @Before + @SuppressWarnings("unchecked") + public void setUp() throws Exception { + observableMap = mapFactory.call(); + unmodifiableMap = FXCollections.unmodifiableObservableMap(observableMap); + observer = new MockMapObserver(); + unmodifiableMap.addListener(observer); + + useMapData(); + } + + /** + * Modifies the map in the fixture to use the strings passed in instead of + * the default strings, and re-creates the observable map and the observer. + * If no strings are passed in, the result is an empty map. + * + * @param strings the strings to use for the list in the fixture + */ + void useMapData(String... strings) { + observableMap.clear(); + observableMap.put("one", "1"); + observableMap.put("two", "2"); + observableMap.put("foo", "bar"); + observer.clear(); + } + + @Test + public void testObservability() { + /* + * Since unmodifiable ObservableMap wraps an ObservableMap, we need to test + * Observability of changes to the underlying Map, we won't test the full + * ObservableMap API since that is already done. + */ + observableMap.put("observedFoo", "barVal"); + observableMap.put("foo", "barfoo"); + assertEquals("barVal", unmodifiableMap.get("observedFoo")); + + observableMap.remove("observedFoo"); + observableMap.remove("foo"); + observableMap.remove("bar"); + observableMap.put("one", "1"); // dup, no change + assertFalse(unmodifiableMap.containsKey("foo")); + + observer.assertAdded(0, tup("observedFoo", "barVal")); + observer.assertAdded(1, tup("foo", "barfoo")); + observer.assertRemoved(1, tup("foo", "bar")); + observer.assertRemoved(2, tup("observedFoo", "barVal")); + observer.assertRemoved(3, tup("foo", "barfoo")); + assertEquals(observer.getCallsNumber(), 4); + } + + @Test + public void testPutAll() { + Map map = new HashMap(); + map.put("oFoo", "OFoo"); + map.put("pFoo", "PFoo"); + map.put("foo", "foofoo"); + map.put("one", "1"); + try { + unmodifiableMap.putAll(map); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + } + + @Test + public void testClear() { + try { + unmodifiableMap.clear(); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + } + + @Test + public void testKeySet() { + try { + unmodifiableMap.keySet().remove("one"); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + try { + unmodifiableMap.keySet().removeAll(Arrays.asList("one", "two", "three")); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + try { + unmodifiableMap.keySet().retainAll(Arrays.asList("one", "two", "three")); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + try { + unmodifiableMap.keySet().clear(); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + } + + @Test + public void testKeySet_Iterator() { + // iterators should not be removable + Iterator iterator = unmodifiableMap.keySet().iterator(); + assertTrue("Test error, underlying Map should not be empty!", iterator.hasNext()); + try { + iterator.remove(); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + } + + @Test + public void testValues() { + try { + unmodifiableMap.values().remove("1"); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + try { + unmodifiableMap.values().removeAll(Arrays.asList("1", "2", "3")); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + try { + unmodifiableMap.values().retainAll(Arrays.asList("1", "2", "3")); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + try { + unmodifiableMap.values().clear(); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + } + + @Test + public void testValues_Iterator() { + Iterator iterator = unmodifiableMap.values().iterator(); + assertTrue("Test error, underlying Map should not be empty!", iterator.hasNext()); + try { + iterator.remove(); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + } + + @Test + @SuppressWarnings("unchecked") + public void testEntrySet() { + try { + unmodifiableMap.entrySet().remove(entry("one","1")); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + try { + unmodifiableMap.entrySet().removeAll(Arrays.asList(entry("one","1"), entry("two","2"), entry("three","3"))); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + try { + unmodifiableMap.entrySet().retainAll(Arrays.asList(entry("one","1"), entry("two","2"), entry("three","3"))); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + try { + unmodifiableMap.entrySet().clear(); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + } + + @Test + public void testEntrySet_Iterator() { + Iterator> iterator = unmodifiableMap.entrySet().iterator(); + assertTrue("Test error, underlying Map should not be empty!", iterator.hasNext()); + try { + iterator.remove(); + fail("Expected UnsupportedOperationException"); + } catch(UnsupportedOperationException e) {} + } + + private Map.Entry entry(final K key, final V value) { + return new Map.Entry() { + + @Override + public K getKey() { + return key; + } + + @Override + public V getValue() { + return value; + } + + @Override + public V setValue(V value) { + throw new UnsupportedOperationException("Not supported."); + } + + }; + } +} --- old/modules/base/src/test/java/javafx/collections/VetoableObservableListTest.java 2015-08-31 10:25:04.929216378 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,570 +0,0 @@ -/* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; -import com.sun.javafx.collections.VetoableListDecorator; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - */ -public class VetoableObservableListTest { - - private static class Call { - - public Call(List added, int[] removed) { - this.added = added; - this.removed = removed; - } - - int[] removed; - List added; - } - - ObservableList list; - List calls; - - private void assertCallCount(int count) { - assertEquals(count, calls.size()); - } - - private void assertCall(int number, String[] added, int[] removed) { - Call c = calls.get(number); - assertArrayEquals(removed, c.removed); - assertArrayEquals(added, c.added.toArray(new String[0])); - } - - private void assertSingleCall(String[] added, int[] removed) { - assertCallCount(1); - assertCall(0, added, removed); - } - - @Before - public void setUp() { - calls = new ArrayList(); - list = new VetoableListDecorator(FXCollections.observableArrayList()) { - - @Override - protected void onProposedChange(List added, int[] removed) { - calls.add(new Call(added, removed)); - } - }; - list.addAll("foo", "bar", "ham", "eggs"); - calls.clear(); - } - - - @Test(expected=NullPointerException.class) - @Ignore - public void testNull_add() { - list.add(null); - - } - - @Test(expected=NullPointerException.class) - @Ignore - public void testNull_add_indexed() { - list.add( 1, null); - - } - - @Test(expected=NullPointerException.class) - @Ignore - public void testNull_addAll_collection() { - list.addAll(Arrays.asList("a", null, "b")); - - } - - @Test(expected=NullPointerException.class) - @Ignore - public void testNull_addAll() { - list.addAll("a", null, "b"); - - } - - @Test(expected=NullPointerException.class) - @Ignore - public void testNull_addAll_collection_indexed() { - list.addAll(1, Arrays.asList("a", null, "b")); - - } - - @Test(expected=NullPointerException.class) - @Ignore - public void testNull_set() { - list.set(1, null); - - } - - @Test(expected=NullPointerException.class) - @Ignore - public void testNull_setAll() { - list.setAll("a", null); - - } - - @Test(expected=NullPointerException.class) - @Ignore - public void testNull_setAll_collection() { - list.setAll(Arrays.asList("a", null, "b")); - } - - @Test(expected=NullPointerException.class) - @Ignore - public void testNull_listIterator_add() { - list.listIterator().add(null); - - } - @Test(expected=NullPointerException.class) - @Ignore - public void testNull_listIterator_set() { - ListIterator it = list.listIterator(); - it.next(); - it.set(null); - } - - @Test(expected=NullPointerException.class) - @Ignore - public void testNull_subList_add() { - list.subList(0, 1).add(null); - } - - @Test(expected = NullPointerException.class) - @Ignore - public void testNull_subList_add_indexed() { - list.subList(0, 1).add(0, null); - } - - @Test(expected = NullPointerException.class) - @Ignore - public void testNull_subList_addAll() { - list.subList(0, 1).addAll(Collections.singleton(null)); - } - - @Test(expected = NullPointerException.class) - @Ignore - public void testNull_subList_addAll_indexed() { - list.subList(0, 1).addAll(0, Collections.singleton(null)); - } - - @Test(expected = NullPointerException.class) - @Ignore - public void testNull_subList_set() { - list.subList(0, 1).set(0, null); - } - - @Test(expected = NullPointerException.class) - @Ignore - public void testNull_subList_listIterator() { - list.subList(0, 1).listIterator().add(null); - } - - @Test - public void testAdd() { - list.add("a"); - assertSingleCall(new String[] {"a"}, new int[] {4,4}); - } - - @Test - public void testAdd_indexed() { - list.add(1, "a"); - assertSingleCall(new String[] {"a"}, new int[] {1,1}); - } - - @Test - public void testAddAll() { - list.addAll("a", "b"); - assertSingleCall(new String[] {"a", "b"}, new int[] {4,4}); - } - - @Test - public void testAddAll_indexed() { - list.addAll(1, Arrays.asList("a", "b")); - assertSingleCall(new String[] {"a", "b"}, new int[] {1,1}); - } - - @Test - public void testClear() { - list.clear(); - assertSingleCall(new String[0], new int[] {0,4}); - } - - @Test - public void testRemove() { - list.remove("bar"); - assertSingleCall(new String[0], new int[] {1,2}); - } - - @Test - public void testRemove_indexed() { - list.remove(0); - assertSingleCall(new String[0], new int[] {0,1}); - } - - @Test - public void testRemoveAll() { - list.removeAll(Arrays.asList("bar", "eggs", "foobar")); - assertSingleCall(new String[0], new int[] {1,2,3,4}); - } - - @Test - public void testRetainAll() { - list.retainAll(Arrays.asList("foo", "barfoo", "ham")); - assertSingleCall(new String[0], new int[] {1,2,3,4}); - } - - @Test - public void testSet() { - list.set(1, "foobar"); - assertSingleCall(new String[] {"foobar"}, new int[] {1,2}); - } - - @Test - public void testSetAll() { - list.setAll("a", "b"); - assertSingleCall(new String[] {"a", "b"}, new int[] {0, 4}); - } - - @Test - public void testIterator_remove() { - final Iterator iterator = list.iterator(); - iterator.next(); - iterator.remove(); - assertSingleCall(new String[0], new int[] {0,1}); - } - - @Test - public void testListIterator_add() { - list.listIterator().add("a"); - assertSingleCall(new String[] {"a"}, new int[] {0,0}); - } - - @Test - public void testListIterator_set() { - final ListIterator listIterator = list.listIterator(); - listIterator.next(); - listIterator.set("a"); - assertSingleCall(new String[] {"a"}, new int[] {0,1}); - } - - @Test - public void testSubList_add() { - list.subList(0, 1).add("b"); - assertSingleCall(new String[] {"b"}, new int[] {1,1}); - } - - @Test - public void testSubList_addAll() { - list.subList(0, 1).addAll(Arrays.asList("a", "b")); - assertSingleCall(new String[] {"a", "b"}, new int[] {1,1}); - } - - @Test - public void testSubList_clear() { - list.subList(0, 1).clear(); - assertSingleCall(new String[0], new int[] {0, 1}); - } - - @Test - public void testSubList_remove() { - list.subList(0, 1).remove(0); - assertSingleCall(new String[0], new int[] {0, 1}); - } - - @Test - public void testSubList_removeAll() { - list.subList(0, 1).removeAll(Arrays.asList("foo", "bar")); - assertSingleCall(new String[0], new int[] {0, 1}); - } - - @Test - public void testSubList_retainAll() { - list.subList(0, 1).retainAll(Arrays.asList("foo", "bar")); - assert(calls.isEmpty()); - } - - @Test - public void testSubList_set() { - list.subList(0, 1).set(0, "a"); - assertSingleCall(new String[] {"a"}, new int[] {0,1}); - } - - @Test - public void testSubList_iterator_quicktest() { - final ListIterator iterator = list.subList(0, 1).listIterator(); - iterator.next(); - iterator.remove(); - iterator.add("a"); - iterator.previous(); - iterator.set("b"); - assertCallCount(3); - assertCall(0, new String[0], new int[] {0, 1}); - assertCall(1, new String[] {"a"}, new int[] {0, 0}); - assertCall(2, new String[] {"b"}, new int[] {0, 1}); - } - - @Test - public void testConcurrencyAdd() { - boolean exception = false; - List sub = list.subList(0, 1); - list.add("x"); - assertCallCount(1); - try { - sub.add("y"); - fail(); - } catch (ConcurrentModificationException e) { - } - assertCallCount(1); - } - @Test - public void testConcurrencyAddAll() { - boolean exception = false; - List sub = list.subList(0, 1); - list.add("x"); - assertCallCount(1); - try { - sub.addAll(Arrays.asList("y", "z")); - fail(); - } catch (ConcurrentModificationException e) { - } - assertCallCount(1); - } - @Test - public void testConcurrencyClear() { - boolean exception = false; - List sub = list.subList(0, 1); - list.add("x"); - assertCallCount(1); - try { - sub.clear(); - fail(); - } catch (ConcurrentModificationException e) { - } - assertCallCount(1); - } - @Test - public void testConcurrencyRemove() { - boolean exception = false; - List sub = list.subList(0, 1); - list.add("x"); - assertCallCount(1); - try { - sub.remove("foo"); - fail(); - } catch (ConcurrentModificationException e) { - } - assertCallCount(1); - } - @Test - public void testConcurrencyRemoveAll() { - boolean exception = false; - List sub = list.subList(0, 1); - list.add("x"); - assertCallCount(1); - try { - sub.removeAll(Arrays.asList("x")); - fail(); - } catch (ConcurrentModificationException e) { - } - assertCallCount(1); - } - @Test - public void testConcurrencyRetainAll() { - boolean exception = false; - List sub = list.subList(0, 1); - list.add("x"); - assertCallCount(1); - try { - sub.retainAll(Arrays.asList("x")); - fail(); - } catch (ConcurrentModificationException e) { - } - assertCallCount(1); - } - @Test - public void testConcurrencySet() { - boolean exception = false; - List sub = list.subList(0, 1); - list.add("x"); - assertCallCount(1); - try { - sub.set(0, "z"); - fail(); - } catch (ConcurrentModificationException e) { - } - assertCallCount(1); - } - - @Test - public void testConcurrencyIteratorRemove() { - boolean exception = false; - ListIterator it = list.listIterator(); - it.next(); - list.add("x"); - assertCallCount(1); - try { - it.remove(); - } catch (ConcurrentModificationException e) { - } - assertCallCount(1); - } - @Test - public void testConcurrencyIteratorAdd() { - boolean exception = false; - ListIterator it = list.listIterator(); - it.next(); - list.add("x"); - assertCallCount(1); - try { - it.add("g"); - } catch (ConcurrentModificationException e) { - } - assertCallCount(1); - } - @Test - public void testConcurrencyIteratorSet() { - boolean exception = false; - ListIterator it = list.listIterator(); - it.next(); - list.add("x"); - assertCallCount(1); - try { - it.set("p"); - } catch (ConcurrentModificationException e) { - } - assertCallCount(1); - } - - @Test(expected=ConcurrentModificationException.class) - public void testConcurrencyIteratorIterator() { - ListIterator it1 = list.listIterator(); - ListIterator it2 = list.listIterator(); - it1.next(); - it2.next(); - it1.remove(); - it2.remove(); - } - - - @Test - public void testNonConcurrency() { - ListIterator it = list.listIterator(); - it.next(); - it.remove(); - it.next(); - it.remove(); - it.add("foo"); - it.add("bar"); - it.previous(); - it.set("foobar"); - } - - @Test - public void testSubListCreatedOnChangeValid() { - final List> subLists = new ArrayList<>(); - - list.addListener((ListChangeListener) c -> { - subLists.add(c.getList().subList(0, 1)); - }); - - list.add("abc"); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - list.add(0, "abc"); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - list.addAll(0, Arrays.asList("abc", "bcd")); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - list.addAll(Arrays.asList("abc", "bcd")); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - list.remove(0); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - list.remove("abc"); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - list.removeAll("abc"); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - list.retainAll("bcd"); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - - list.setAll("foo", "bar", "ham", "eggs"); - subLists.clear(); - - list.subList(0, 2).add("a"); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - list.subList(0, 2).remove(0); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - Iterator it = list.iterator(); - it.next(); - it.remove(); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - list.listIterator().add("abc"); - assertEquals(1, subLists.size()); - subLists.get(0).size(); // Assert not throwing Exception - subLists.clear(); - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/VetoableObservableListTest.java 2015-08-31 10:25:04.725216380 -0400 @@ -0,0 +1,573 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; +import com.sun.javafx.collections.VetoableListDecorator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.ConcurrentModificationException; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public class VetoableObservableListTest { + + private static class Call { + + public Call(List added, int[] removed) { + this.added = added; + this.removed = removed; + } + + int[] removed; + List added; + } + + ObservableList list; + List calls; + + private void assertCallCount(int count) { + assertEquals(count, calls.size()); + } + + private void assertCall(int number, String[] added, int[] removed) { + Call c = calls.get(number); + assertArrayEquals(removed, c.removed); + assertArrayEquals(added, c.added.toArray(new String[0])); + } + + private void assertSingleCall(String[] added, int[] removed) { + assertCallCount(1); + assertCall(0, added, removed); + } + + @Before + public void setUp() { + calls = new ArrayList(); + list = new VetoableListDecorator(FXCollections.observableArrayList()) { + + @Override + protected void onProposedChange(List added, int[] removed) { + calls.add(new Call(added, removed)); + } + }; + list.addAll("foo", "bar", "ham", "eggs"); + calls.clear(); + } + + + @Test(expected=NullPointerException.class) + @Ignore + public void testNull_add() { + list.add(null); + + } + + @Test(expected=NullPointerException.class) + @Ignore + public void testNull_add_indexed() { + list.add( 1, null); + + } + + @Test(expected=NullPointerException.class) + @Ignore + public void testNull_addAll_collection() { + list.addAll(Arrays.asList("a", null, "b")); + + } + + @Test(expected=NullPointerException.class) + @Ignore + public void testNull_addAll() { + list.addAll("a", null, "b"); + + } + + @Test(expected=NullPointerException.class) + @Ignore + public void testNull_addAll_collection_indexed() { + list.addAll(1, Arrays.asList("a", null, "b")); + + } + + @Test(expected=NullPointerException.class) + @Ignore + public void testNull_set() { + list.set(1, null); + + } + + @Test(expected=NullPointerException.class) + @Ignore + public void testNull_setAll() { + list.setAll("a", null); + + } + + @Test(expected=NullPointerException.class) + @Ignore + public void testNull_setAll_collection() { + list.setAll(Arrays.asList("a", null, "b")); + } + + @Test(expected=NullPointerException.class) + @Ignore + public void testNull_listIterator_add() { + list.listIterator().add(null); + + } + @Test(expected=NullPointerException.class) + @Ignore + public void testNull_listIterator_set() { + ListIterator it = list.listIterator(); + it.next(); + it.set(null); + } + + @Test(expected=NullPointerException.class) + @Ignore + public void testNull_subList_add() { + list.subList(0, 1).add(null); + } + + @Test(expected = NullPointerException.class) + @Ignore + public void testNull_subList_add_indexed() { + list.subList(0, 1).add(0, null); + } + + @Test(expected = NullPointerException.class) + @Ignore + public void testNull_subList_addAll() { + list.subList(0, 1).addAll(Collections.singleton(null)); + } + + @Test(expected = NullPointerException.class) + @Ignore + public void testNull_subList_addAll_indexed() { + list.subList(0, 1).addAll(0, Collections.singleton(null)); + } + + @Test(expected = NullPointerException.class) + @Ignore + public void testNull_subList_set() { + list.subList(0, 1).set(0, null); + } + + @Test(expected = NullPointerException.class) + @Ignore + public void testNull_subList_listIterator() { + list.subList(0, 1).listIterator().add(null); + } + + @Test + public void testAdd() { + list.add("a"); + assertSingleCall(new String[] {"a"}, new int[] {4,4}); + } + + @Test + public void testAdd_indexed() { + list.add(1, "a"); + assertSingleCall(new String[] {"a"}, new int[] {1,1}); + } + + @Test + public void testAddAll() { + list.addAll("a", "b"); + assertSingleCall(new String[] {"a", "b"}, new int[] {4,4}); + } + + @Test + public void testAddAll_indexed() { + list.addAll(1, Arrays.asList("a", "b")); + assertSingleCall(new String[] {"a", "b"}, new int[] {1,1}); + } + + @Test + public void testClear() { + list.clear(); + assertSingleCall(new String[0], new int[] {0,4}); + } + + @Test + public void testRemove() { + list.remove("bar"); + assertSingleCall(new String[0], new int[] {1,2}); + } + + @Test + public void testRemove_indexed() { + list.remove(0); + assertSingleCall(new String[0], new int[] {0,1}); + } + + @Test + public void testRemoveAll() { + list.removeAll(Arrays.asList("bar", "eggs", "foobar")); + assertSingleCall(new String[0], new int[] {1,2,3,4}); + } + + @Test + public void testRetainAll() { + list.retainAll(Arrays.asList("foo", "barfoo", "ham")); + assertSingleCall(new String[0], new int[] {1,2,3,4}); + } + + @Test + public void testSet() { + list.set(1, "foobar"); + assertSingleCall(new String[] {"foobar"}, new int[] {1,2}); + } + + @Test + public void testSetAll() { + list.setAll("a", "b"); + assertSingleCall(new String[] {"a", "b"}, new int[] {0, 4}); + } + + @Test + public void testIterator_remove() { + final Iterator iterator = list.iterator(); + iterator.next(); + iterator.remove(); + assertSingleCall(new String[0], new int[] {0,1}); + } + + @Test + public void testListIterator_add() { + list.listIterator().add("a"); + assertSingleCall(new String[] {"a"}, new int[] {0,0}); + } + + @Test + public void testListIterator_set() { + final ListIterator listIterator = list.listIterator(); + listIterator.next(); + listIterator.set("a"); + assertSingleCall(new String[] {"a"}, new int[] {0,1}); + } + + @Test + public void testSubList_add() { + list.subList(0, 1).add("b"); + assertSingleCall(new String[] {"b"}, new int[] {1,1}); + } + + @Test + public void testSubList_addAll() { + list.subList(0, 1).addAll(Arrays.asList("a", "b")); + assertSingleCall(new String[] {"a", "b"}, new int[] {1,1}); + } + + @Test + public void testSubList_clear() { + list.subList(0, 1).clear(); + assertSingleCall(new String[0], new int[] {0, 1}); + } + + @Test + public void testSubList_remove() { + list.subList(0, 1).remove(0); + assertSingleCall(new String[0], new int[] {0, 1}); + } + + @Test + public void testSubList_removeAll() { + list.subList(0, 1).removeAll(Arrays.asList("foo", "bar")); + assertSingleCall(new String[0], new int[] {0, 1}); + } + + @Test + public void testSubList_retainAll() { + list.subList(0, 1).retainAll(Arrays.asList("foo", "bar")); + assert(calls.isEmpty()); + } + + @Test + public void testSubList_set() { + list.subList(0, 1).set(0, "a"); + assertSingleCall(new String[] {"a"}, new int[] {0,1}); + } + + @Test + public void testSubList_iterator_quicktest() { + final ListIterator iterator = list.subList(0, 1).listIterator(); + iterator.next(); + iterator.remove(); + iterator.add("a"); + iterator.previous(); + iterator.set("b"); + assertCallCount(3); + assertCall(0, new String[0], new int[] {0, 1}); + assertCall(1, new String[] {"a"}, new int[] {0, 0}); + assertCall(2, new String[] {"b"}, new int[] {0, 1}); + } + + @Test + public void testConcurrencyAdd() { + boolean exception = false; + List sub = list.subList(0, 1); + list.add("x"); + assertCallCount(1); + try { + sub.add("y"); + fail(); + } catch (ConcurrentModificationException e) { + } + assertCallCount(1); + } + @Test + public void testConcurrencyAddAll() { + boolean exception = false; + List sub = list.subList(0, 1); + list.add("x"); + assertCallCount(1); + try { + sub.addAll(Arrays.asList("y", "z")); + fail(); + } catch (ConcurrentModificationException e) { + } + assertCallCount(1); + } + @Test + public void testConcurrencyClear() { + boolean exception = false; + List sub = list.subList(0, 1); + list.add("x"); + assertCallCount(1); + try { + sub.clear(); + fail(); + } catch (ConcurrentModificationException e) { + } + assertCallCount(1); + } + @Test + public void testConcurrencyRemove() { + boolean exception = false; + List sub = list.subList(0, 1); + list.add("x"); + assertCallCount(1); + try { + sub.remove("foo"); + fail(); + } catch (ConcurrentModificationException e) { + } + assertCallCount(1); + } + @Test + public void testConcurrencyRemoveAll() { + boolean exception = false; + List sub = list.subList(0, 1); + list.add("x"); + assertCallCount(1); + try { + sub.removeAll(Arrays.asList("x")); + fail(); + } catch (ConcurrentModificationException e) { + } + assertCallCount(1); + } + @Test + public void testConcurrencyRetainAll() { + boolean exception = false; + List sub = list.subList(0, 1); + list.add("x"); + assertCallCount(1); + try { + sub.retainAll(Arrays.asList("x")); + fail(); + } catch (ConcurrentModificationException e) { + } + assertCallCount(1); + } + @Test + public void testConcurrencySet() { + boolean exception = false; + List sub = list.subList(0, 1); + list.add("x"); + assertCallCount(1); + try { + sub.set(0, "z"); + fail(); + } catch (ConcurrentModificationException e) { + } + assertCallCount(1); + } + + @Test + public void testConcurrencyIteratorRemove() { + boolean exception = false; + ListIterator it = list.listIterator(); + it.next(); + list.add("x"); + assertCallCount(1); + try { + it.remove(); + } catch (ConcurrentModificationException e) { + } + assertCallCount(1); + } + @Test + public void testConcurrencyIteratorAdd() { + boolean exception = false; + ListIterator it = list.listIterator(); + it.next(); + list.add("x"); + assertCallCount(1); + try { + it.add("g"); + } catch (ConcurrentModificationException e) { + } + assertCallCount(1); + } + @Test + public void testConcurrencyIteratorSet() { + boolean exception = false; + ListIterator it = list.listIterator(); + it.next(); + list.add("x"); + assertCallCount(1); + try { + it.set("p"); + } catch (ConcurrentModificationException e) { + } + assertCallCount(1); + } + + @Test(expected=ConcurrentModificationException.class) + public void testConcurrencyIteratorIterator() { + ListIterator it1 = list.listIterator(); + ListIterator it2 = list.listIterator(); + it1.next(); + it2.next(); + it1.remove(); + it2.remove(); + } + + + @Test + public void testNonConcurrency() { + ListIterator it = list.listIterator(); + it.next(); + it.remove(); + it.next(); + it.remove(); + it.add("foo"); + it.add("bar"); + it.previous(); + it.set("foobar"); + } + + @Test + public void testSubListCreatedOnChangeValid() { + final List> subLists = new ArrayList<>(); + + list.addListener((ListChangeListener) c -> { + subLists.add(c.getList().subList(0, 1)); + }); + + list.add("abc"); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + list.add(0, "abc"); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + list.addAll(0, Arrays.asList("abc", "bcd")); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + list.addAll(Arrays.asList("abc", "bcd")); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + list.remove(0); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + list.remove("abc"); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + list.removeAll("abc"); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + list.retainAll("bcd"); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + + list.setAll("foo", "bar", "ham", "eggs"); + subLists.clear(); + + list.subList(0, 2).add("a"); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + list.subList(0, 2).remove(0); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + Iterator it = list.iterator(); + it.next(); + it.remove(); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + list.listIterator().add("abc"); + assertEquals(1, subLists.size()); + subLists.get(0).size(); // Assert not throwing Exception + subLists.clear(); + + } + +} --- old/modules/base/src/test/java/javafx/collections/WeakListChangeListenerMock.java 2015-08-31 10:25:05.553216371 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import javafx.beans.WeakListener; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; - -public class WeakListChangeListenerMock implements ChangeListener, WeakListener { - @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { } - - @Override public boolean wasGarbageCollected() { - return true; - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/WeakListChangeListenerMock.java 2015-08-31 10:25:05.417216373 -0400 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import javafx.beans.WeakListener; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; + +public class WeakListChangeListenerMock implements ChangeListener, WeakListener { + @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { } + + @Override public boolean wasGarbageCollected() { + return true; + } +} --- old/modules/base/src/test/java/javafx/collections/WeakListChangeListenerTest.java 2015-08-31 10:25:06.173216364 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import com.sun.javafx.collections.NonIterableChange; -import com.sun.javafx.collections.ObservableListWrapper; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Collections; - -import static org.junit.Assert.*; - -public class WeakListChangeListenerTest { - - @Test(expected=NullPointerException.class) - public void testConstructWithNull() { - new WeakListChangeListener(null); - } - - @Test - public void testHandle() { - MockListObserver listener = new MockListObserver(); - final WeakListChangeListener weakListener = new WeakListChangeListener(listener); - final ObservableListWrapper list = new ObservableListWrapper(new ArrayList()); - final Object removedElement = new Object(); - final ListChangeListener.Change change = new NonIterableChange.SimpleRemovedChange(0, 1, removedElement, list); - - // regular call - weakListener.onChanged(change); - listener.check1AddRemove(list, Collections.singletonList(removedElement), 0, 1); - assertFalse(weakListener.wasGarbageCollected()); - - // GC-ed call - listener = null; - System.gc(); - assertTrue(weakListener.wasGarbageCollected()); - weakListener.onChanged(change); - - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/WeakListChangeListenerTest.java 2015-08-31 10:25:06.041216366 -0400 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import com.sun.javafx.collections.NonIterableChange; +import com.sun.javafx.collections.ObservableListWrapper; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; +import javafx.collections.ListChangeListener; +import javafx.collections.WeakListChangeListener; + +import static org.junit.Assert.*; + +public class WeakListChangeListenerTest { + + @Test(expected=NullPointerException.class) + public void testConstructWithNull() { + new WeakListChangeListener(null); + } + + @Test + public void testHandle() { + MockListObserver listener = new MockListObserver(); + final WeakListChangeListener weakListener = new WeakListChangeListener(listener); + final ObservableListWrapper list = new ObservableListWrapper(new ArrayList()); + final Object removedElement = new Object(); + final ListChangeListener.Change change = new NonIterableChange.SimpleRemovedChange(0, 1, removedElement, list); + + // regular call + weakListener.onChanged(change); + listener.check1AddRemove(list, Collections.singletonList(removedElement), 0, 1); + assertFalse(weakListener.wasGarbageCollected()); + + // GC-ed call + listener = null; + System.gc(); + assertTrue(weakListener.wasGarbageCollected()); + weakListener.onChanged(change); + + } + +} --- old/modules/base/src/test/java/javafx/collections/WeakMapChangeListenerTest.java 2015-08-31 10:25:06.921216356 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import com.sun.javafx.binding.MapExpressionHelper; -import com.sun.javafx.collections.ObservableMapWrapper; -import org.junit.Test; - -import java.util.HashMap; - -import static org.junit.Assert.*; - -public class WeakMapChangeListenerTest { - - @Test(expected=NullPointerException.class) - public void testConstructWithNull() { - new WeakMapChangeListener(null); - } - - @Test - public void testHandle() { - MockMapObserver listener = new MockMapObserver(); - final WeakMapChangeListener weakListener = new WeakMapChangeListener(listener); - final ObservableMapMock map = new ObservableMapMock(); - final Object key = new Object(); - final Object value = new Object(); - final MapChangeListener.Change change = new MapExpressionHelper.SimpleChange(map).setRemoved(key, value); - - // regular call - weakListener.onChanged(change); - listener.assertRemoved(MockMapObserver.Tuple.tup(key, value)); - assertFalse(weakListener.wasGarbageCollected()); - - // GC-ed call - map.reset(); - listener = null; - System.gc(); - assertTrue(weakListener.wasGarbageCollected()); - weakListener.onChanged(change); - assertEquals(1, map.removeCounter); - } - - private static class ObservableMapMock extends ObservableMapWrapper { - private int removeCounter; - - public ObservableMapMock() { - super(new HashMap()); - } - - private void reset() { - removeCounter = 0; - } - - @Override - public void removeListener(MapChangeListener listener) { - removeCounter++; - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/WeakMapChangeListenerTest.java 2015-08-31 10:25:06.709216358 -0400 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import com.sun.javafx.binding.MapExpressionHelper; +import com.sun.javafx.collections.ObservableMapWrapper; +import org.junit.Test; + +import java.util.HashMap; +import javafx.collections.MapChangeListener; +import javafx.collections.WeakMapChangeListener; + +import static org.junit.Assert.*; + +public class WeakMapChangeListenerTest { + + @Test(expected=NullPointerException.class) + public void testConstructWithNull() { + new WeakMapChangeListener(null); + } + + @Test + public void testHandle() { + MockMapObserver listener = new MockMapObserver(); + final WeakMapChangeListener weakListener = new WeakMapChangeListener(listener); + final ObservableMapMock map = new ObservableMapMock(); + final Object key = new Object(); + final Object value = new Object(); + final MapChangeListener.Change change = new MapExpressionHelper.SimpleChange(map).setRemoved(key, value); + + // regular call + weakListener.onChanged(change); + listener.assertRemoved(MockMapObserver.Tuple.tup(key, value)); + assertFalse(weakListener.wasGarbageCollected()); + + // GC-ed call + map.reset(); + listener = null; + System.gc(); + assertTrue(weakListener.wasGarbageCollected()); + weakListener.onChanged(change); + assertEquals(1, map.removeCounter); + } + + private static class ObservableMapMock extends ObservableMapWrapper { + private int removeCounter; + + public ObservableMapMock() { + super(new HashMap()); + } + + private void reset() { + removeCounter = 0; + } + + @Override + public void removeListener(MapChangeListener listener) { + removeCounter++; + } + } + +} --- old/modules/base/src/test/java/javafx/collections/WeakSetChangeListenerTest.java 2015-08-31 10:25:07.601216348 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.collections; - -import com.sun.javafx.binding.SetExpressionHelper; -import com.sun.javafx.collections.ObservableSetWrapper; -import org.junit.Test; - -import java.util.HashSet; - -import static org.junit.Assert.*; - -public class WeakSetChangeListenerTest { - - @Test(expected=NullPointerException.class) - public void testConstructWithNull() { - new WeakSetChangeListener(null); - } - - @Test - public void testHandle() { - MockSetObserver listener = new MockSetObserver(); - final WeakSetChangeListener weakListener = new WeakSetChangeListener(listener); - final ObservableSetMock set = new ObservableSetMock(); - final Object removedElement = new Object(); - final SetChangeListener.Change change = new SetExpressionHelper.SimpleChange(set).setRemoved(removedElement); - - // regular call - weakListener.onChanged(change); - listener.assertRemoved(MockSetObserver.Tuple.tup(removedElement)); - assertFalse(weakListener.wasGarbageCollected()); - - // GC-ed call - set.reset(); - listener = null; - System.gc(); - assertTrue(weakListener.wasGarbageCollected()); - weakListener.onChanged(change); - assertEquals(1, set.removeCounter); - } - - private static class ObservableSetMock extends ObservableSetWrapper { - private int removeCounter; - - public ObservableSetMock() { - super(new HashSet()); - } - - private void reset() { - removeCounter = 0; - } - - @Override - public void removeListener(SetChangeListener listener) { - removeCounter++; - } - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/collections/WeakSetChangeListenerTest.java 2015-08-31 10:25:07.469216350 -0400 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.collections; + +import com.sun.javafx.binding.SetExpressionHelper; +import com.sun.javafx.collections.ObservableSetWrapper; +import org.junit.Test; + +import java.util.HashSet; +import javafx.collections.SetChangeListener; +import javafx.collections.WeakSetChangeListener; + +import static org.junit.Assert.*; + +public class WeakSetChangeListenerTest { + + @Test(expected=NullPointerException.class) + public void testConstructWithNull() { + new WeakSetChangeListener(null); + } + + @Test + public void testHandle() { + MockSetObserver listener = new MockSetObserver(); + final WeakSetChangeListener weakListener = new WeakSetChangeListener(listener); + final ObservableSetMock set = new ObservableSetMock(); + final Object removedElement = new Object(); + final SetChangeListener.Change change = new SetExpressionHelper.SimpleChange(set).setRemoved(removedElement); + + // regular call + weakListener.onChanged(change); + listener.assertRemoved(MockSetObserver.Tuple.tup(removedElement)); + assertFalse(weakListener.wasGarbageCollected()); + + // GC-ed call + set.reset(); + listener = null; + System.gc(); + assertTrue(weakListener.wasGarbageCollected()); + weakListener.onChanged(change); + assertEquals(1, set.removeCounter); + } + + private static class ObservableSetMock extends ObservableSetWrapper { + private int removeCounter; + + public ObservableSetMock() { + super(new HashSet()); + } + + private void reset() { + removeCounter = 0; + } + + @Override + public void removeListener(SetChangeListener listener) { + removeCounter++; + } + } + +} --- old/modules/base/src/test/java/javafx/event/EventSerializationEventExists.java 2015-08-31 10:25:08.293216340 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.event; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.ArrayList; -import java.util.List; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import static org.junit.Assert.*; - -public class EventSerializationEventExists { - - private ByteArrayOutputStream byteArrayOutputStream; - private ObjectOutputStream objectOutputStream; - private ObjectInputStream objectInputStream; - - @Before - public void setUp() throws IOException { - byteArrayOutputStream = new ByteArrayOutputStream(); - objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); - } - - public void turnToInput() throws IOException { - objectInputStream = new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); - } - - @Test - @Ignore - public void testSerializationEventExists() throws IOException, ClassNotFoundException { - EventType ev = null; - try { - ev = new EventType(Event.ANY, "ACTION"); - } catch (IllegalArgumentException e) { - fail("Test error: Event type already registered before the test"); - } - - List l = new ArrayList(); - l.add("ACTION"); - EventType.EventTypeSerialization e = new EventType.EventTypeSerialization(l); - - objectOutputStream.writeObject(e); - turnToInput(); - - //Normally, the DummyEvent class would be loaded during the event deserialization. - Class.forName("javafx.event.ActionEvent"); - - EventType eType = (EventType) objectInputStream.readObject(); - assertNotSame(ev, eType); - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/event/EventSerializationEventExists.java 2015-08-31 10:25:08.101216342 -0400 @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.event; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.List; +import javafx.event.Event; +import javafx.event.EventType; +import javafx.event.EventTypeShim; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import static org.junit.Assert.*; + +public class EventSerializationEventExists { + + private ByteArrayOutputStream byteArrayOutputStream; + private ObjectOutputStream objectOutputStream; + private ObjectInputStream objectInputStream; + + @Before + public void setUp() throws IOException { + byteArrayOutputStream = new ByteArrayOutputStream(); + objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); + } + + public void turnToInput() throws IOException { + objectInputStream = new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); + } + + @Test + @Ignore + public void testSerializationEventExists() throws IOException, ClassNotFoundException { + EventType ev = null; + try { + ev = new EventType(Event.ANY, "ACTION"); + } catch (IllegalArgumentException e) { + fail("Test error: Event type already registered before the test"); + } + + List l = new ArrayList(); + l.add("ACTION"); + EventTypeShim.EventTypeSerializationShim e = new EventTypeShim.EventTypeSerializationShim(l); + + objectOutputStream.writeObject(e); + turnToInput(); + + //Normally, the DummyEvent class would be loaded during the event deserialization. + Class.forName("javafx.event.ActionEvent"); + + EventType eType = (EventType) objectInputStream.readObject(); + assertNotSame(ev, eType); + + } +} --- old/modules/base/src/test/java/javafx/event/EventSerializationTest.java 2015-08-31 10:25:08.901216333 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.event; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.ArrayList; -import java.util.List; -import javafx.event.EventType.EventTypeSerialization; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.*; -import org.junit.Ignore; - -/** - * - */ -public class EventSerializationTest { - private ByteArrayOutputStream byteArrayOutputStream; - private ObjectOutputStream objectOutputStream; - private ObjectInputStream objectInputStream; - - @Before - public void setUp() throws IOException { - byteArrayOutputStream = new ByteArrayOutputStream(); - objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); - } - - public void turnToInput() throws IOException { - objectInputStream = new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); - } - - @Test - public void testPreDefinedEventSerialization() throws IOException, ClassNotFoundException { - ActionEvent a = new ActionEvent(); - - objectOutputStream.writeObject(a); - turnToInput(); - - ActionEvent ra = (ActionEvent) objectInputStream.readObject(); - assertEquals(a.getEventType(), ra.getEventType()); - assertEquals(a.isConsumed(), ra.isConsumed()); - assertEquals(Event.NULL_SOURCE_TARGET, ra.getSource()); - assertEquals(Event.NULL_SOURCE_TARGET, ra.getTarget()); - } - - @Test - public void testNewEventTypeSerialization() throws IOException, ClassNotFoundException { - EventType eventType = new EventType(Event.ANY, "MY_TYPE"); - Event e = new Event(eventType); - - objectOutputStream.writeObject(e); - turnToInput(); - Event re = (Event) objectInputStream.readObject(); - assertEquals(e.getEventType(), re.getEventType()); - assertEquals(e.isConsumed(), re.isConsumed()); - assertEquals(Event.NULL_SOURCE_TARGET, re.getSource()); - assertEquals(Event.NULL_SOURCE_TARGET, re.getTarget()); - - } - - @Test(expected=InvalidObjectException.class) - public void testUnknownEventTypeSerialization() throws IOException, ClassNotFoundException { - List l = new ArrayList(); - l.add("UNKNOWN"); - EventTypeSerialization e = new EventTypeSerialization(l); - - objectOutputStream.writeObject(e); - turnToInput(); - EventType eType = (EventType) objectInputStream.readObject(); - - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/event/EventSerializationTest.java 2015-08-31 10:25:08.769216335 -0400 @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.event; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.List; +import javafx.event.ActionEvent; +import javafx.event.Event; +import javafx.event.EventType; +import javafx.event.EventTypeShim; +import javafx.event.EventTypeShim.EventTypeSerializationShim; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * + */ +public class EventSerializationTest { + private ByteArrayOutputStream byteArrayOutputStream; + private ObjectOutputStream objectOutputStream; + private ObjectInputStream objectInputStream; + + @Before + public void setUp() throws IOException { + byteArrayOutputStream = new ByteArrayOutputStream(); + objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); + } + + public void turnToInput() throws IOException { + objectInputStream = new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); + } + + @Test + public void testPreDefinedEventSerialization() throws IOException, ClassNotFoundException { + ActionEvent a = new ActionEvent(); + + objectOutputStream.writeObject(a); + turnToInput(); + + ActionEvent ra = (ActionEvent) objectInputStream.readObject(); + assertEquals(a.getEventType(), ra.getEventType()); + assertEquals(a.isConsumed(), ra.isConsumed()); + assertEquals(Event.NULL_SOURCE_TARGET, ra.getSource()); + assertEquals(Event.NULL_SOURCE_TARGET, ra.getTarget()); + } + + @Test + public void testNewEventTypeSerialization() throws IOException, ClassNotFoundException { + EventType eventType = new EventType(Event.ANY, "MY_TYPE"); + Event e = new Event(eventType); + + objectOutputStream.writeObject(e); + turnToInput(); + Event re = (Event) objectInputStream.readObject(); + assertEquals(e.getEventType(), re.getEventType()); + assertEquals(e.isConsumed(), re.isConsumed()); + assertEquals(Event.NULL_SOURCE_TARGET, re.getSource()); + assertEquals(Event.NULL_SOURCE_TARGET, re.getTarget()); + + } + + @Test(expected=InvalidObjectException.class) + public void testUnknownEventTypeSerialization() throws IOException, ClassNotFoundException { + List l = new ArrayList(); + l.add("UNKNOWN"); + Object e = EventTypeShim.getEventTypeSerialization(l); + + objectOutputStream.writeObject(e); + turnToInput(); + EventType eType = (EventType) objectInputStream.readObject(); + } +} --- old/modules/base/src/test/java/javafx/event/EventTest.java 2015-08-31 10:25:09.505216327 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.event; - -import org.junit.Test; - -/** - * - */ -public class EventTest { - - @Test(expected=IllegalArgumentException.class) - public void testTypeConflict() { - new EventType(Event.ANY, ActionEvent.ACTION.getName()); - } - - @Test - public void testTypeNew() { - new EventType(Event.ANY, "TEST"); // should pass without exception - } - -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/event/EventTest.java 2015-08-31 10:25:09.373216328 -0400 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.event; + +import javafx.event.ActionEvent; +import javafx.event.Event; +import javafx.event.EventType; +import org.junit.Test; + +/** + * + */ +public class EventTest { + + @Test(expected=IllegalArgumentException.class) + public void testTypeConflict() { + new EventType(Event.ANY, ActionEvent.ACTION.getName()); + } + + @Test + public void testTypeNew() { + new EventType(Event.ANY, "TEST"); // should pass without exception + } + +} --- old/modules/base/src/test/java/javafx/util/DurationTest.java 2015-08-31 10:25:10.221216319 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,905 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util; - -import org.junit.Test; -import static org.junit.Assert.*; - -/** - */ -public class DurationTest { - - /************************************************************************************ - * - * Tests for the static millis() method - * - ***********************************************************************************/ - - @Test public void millis_withZeroResultsIn_ZERO() { - assertSame(Duration.ZERO, Duration.millis(0)); - } - - @Test public void millis_withOneResultsIn_ONE() { - assertSame(Duration.ONE, Duration.millis(1)); - } - - @Test public void millis_withPositiveInfinityResultsIn_INDEFINITE() { - assertSame(Duration.INDEFINITE, Duration.millis(Double.POSITIVE_INFINITY)); - } - - @Test public void millis_withNaNResultsIn_UNKNOWN() { - assertSame(Duration.UNKNOWN, Duration.millis(Double.NaN)); - } - - @Test public void millis_withPositiveResultsInNewDuration() { - final Duration result = Duration.millis(9); - assertEquals(result.toMillis(), 9, 0); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - /************************************************************************************ - * - * Tests for the static seconds() method - * - ***********************************************************************************/ - - @Test public void seconds_withZeroResultsIn_ZERO() { - assertSame(Duration.ZERO, Duration.seconds(0)); - } - - @Test public void seconds_withPositiveInfinityResultsIn_INDEFINITE() { - assertSame(Duration.INDEFINITE, Duration.seconds(Double.POSITIVE_INFINITY)); - } - - @Test public void seconds_withNaNResultsIn_UNKNOWN() { - assertSame(Duration.UNKNOWN, Duration.seconds(Double.NaN)); - } - - @Test public void seconds_withPositiveResultsInNewDuration() { - final Duration result = Duration.seconds(9); - assertEquals(result.toSeconds(), 9, 0); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - /************************************************************************************ - * - * Tests for the static minutes() method - * - ***********************************************************************************/ - - @Test public void minutes_withZeroResultsIn_ZERO() { - assertSame(Duration.ZERO, Duration.minutes(0)); - } - - @Test public void minutes_withPositiveInfinityResultsIn_INDEFINITE() { - assertSame(Duration.INDEFINITE, Duration.minutes(Double.POSITIVE_INFINITY)); - } - - @Test public void minutes_withNaNResultsIn_UNKNOWN() { - assertSame(Duration.UNKNOWN, Duration.minutes(Double.NaN)); - } - - @Test public void minutes_withPositiveResultsInNewDuration() { - final Duration result = Duration.minutes(9); - assertEquals(result.toMinutes(), 9, 0); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - /************************************************************************************ - * - * Tests for the static hours() method - * - ***********************************************************************************/ - - @Test public void hours_withZeroResultsIn_ZERO() { - assertSame(Duration.ZERO, Duration.hours(0)); - } - - @Test public void hours_withPositiveInfinityResultsIn_INDEFINITE() { - assertSame(Duration.INDEFINITE, Duration.hours(Double.POSITIVE_INFINITY)); - } - - @Test public void hours_withNaNResultsIn_UNKNOWN() { - assertSame(Duration.UNKNOWN, Duration.hours(Double.NaN)); - } - - @Test public void hours_withPositiveResultsInNewDuration() { - final Duration result = Duration.hours(9); - assertEquals(result.toHours(), 9, 0); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - /************************************************************************************ - * - * Tests for the one-arg constructor - * - ***********************************************************************************/ - - @Test public void constructor_withZeroEquals_ZERO() { - assertEquals(Duration.ZERO, new Duration(0)); - } - - @Test public void constructor_withOneEquals_ONE() { - assertEquals(Duration.ONE, new Duration(1)); - } - - @Test public void constructor_withPositiveInfinityEquals_INDEFINITE() { - assertTrue(Duration.INDEFINITE.equals(new Duration(Double.POSITIVE_INFINITY))); - } - - @Test public void constructor_withNaNDoesNotEqual_UNKNOWN() { - assertFalse(Duration.UNKNOWN.equals(new Duration(Double.NaN))); - } - - @Test public void constructor_withPositiveResultsInNewDuration() { - final Duration result = new Duration(9); - assertEquals(result.toMillis(), 9, 0); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - /************************************************************************************ - * - * Tests for the toMillis method - * - ***********************************************************************************/ - - @Test public void toMillis_when_ZERO_resultsInZero() { - assertEquals(0, Duration.ZERO.toMillis(), 0); - } - - @Test public void toMillis_when_ONE_resultsInOne() { - assertEquals(1, Duration.ONE.toMillis(), 0); - } - - @Test public void toMillis_when_INDEFINITE_resultsInPositiveInfinity() { - assertTrue(Double.isInfinite(Duration.INDEFINITE.toMillis())); - } - - @Test public void toMillis_whenNegativeInfinityResultsInNegativeInfinity() { - assertTrue(Double.isInfinite(new Duration(Double.NEGATIVE_INFINITY).toMillis())); - } - - @Test public void toMillis_when_UNKNOWN_ResultsInNaN() { - assertTrue(Double.isNaN(Duration.UNKNOWN.toMillis())); - } - - @Test public void toMillis_whenPositiveNumberResultsInTheSameNumber() { - assertEquals(87, new Duration(87).toMillis(), 0); - } - - @Test public void toMillis_whenNegativeNumberResultsInTheSameNumber() { - assertEquals(-7, new Duration(-7).toMillis(), 0); - } - - /************************************************************************************ - * - * Tests for the toSeconds method - * - ***********************************************************************************/ - - @Test public void toSeconds_when_ZERO_resultsInZero() { - assertEquals(0, Duration.ZERO.toSeconds(), 0); - } - - @Test public void toSeconds_when_ONE_resultsInPointZeroZeroOne() { - assertEquals(.001, Duration.ONE.toSeconds(), 0); - } - - @Test public void toSeconds_when_INDEFINITE_resultsInPositiveInfinity() { - assertTrue(Double.isInfinite(Duration.INDEFINITE.toSeconds())); - } - - @Test public void toSeconds_whenNegativeInfinityResultsInNegativeInfinity() { - assertTrue(Double.isInfinite(new Duration(Double.NEGATIVE_INFINITY).toSeconds())); - } - - @Test public void toSeconds_when_UNKNOWN_ResultsInNaN() { - assertTrue(Double.isNaN(Duration.UNKNOWN.toSeconds())); - } - - @Test public void toSeconds_whenPositiveNumberResultsInTheSameNumber() { - assertEquals(.087, new Duration(87).toSeconds(), 0); - } - - @Test public void toSeconds_whenNegativeNumberResultsInTheSameNumber() { - assertEquals(-.007, new Duration(-7).toSeconds(), 0); - } - - // toMinutes - // 0, +infinity, -infinity, Nan, positive value, negative value - // toHours - // 0, +infinity, -infinity, Nan, positive value, negative value - - - /************************************************************************************ - * - * Tests for adding two Durations. For the most part I just test millis, - * because I know the implementation stores just millis, but for completeness - * and to avoid regressions should we change the storage format, I'll also - * throw in a few tests which work on seconds, minutes, and a mixture of - * seconds and minutes. - * - ***********************************************************************************/ - - @Test public void add_doesNotModifyTheInputArguments() { - Duration a = new Duration(10); - Duration b = new Duration(20); - final Duration result = a.add(b); - assertEquals(new Duration(30), result); - assertEquals(10, a.toMillis(), 0); - assertEquals(20, b.toMillis(), 0); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - @Test public void add_ZERO_and_ZERO_ResultsIn_ZERO() { - assertSame(Duration.ZERO, Duration.ZERO.add(Duration.ZERO)); - } - - @Test public void add_ZERO_and_ONE_ResultsIn_ONE() { - assertSame(Duration.ONE, Duration.ZERO.add(Duration.ONE)); - assertSame(Duration.ONE, Duration.ONE.add(Duration.ZERO)); - } - - @Test public void add_ONE_and_ONE_ResultsInTwo() { - final Duration result = Duration.ONE.add(Duration.ONE); - assertEquals(new Duration(2), result); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - @Test public void add_ONE_Second_and_ONE_Milli_ResultsInOneThousandOneMillis() { - final Duration result = Duration.seconds(1).add(Duration.ONE); - assertEquals(new Duration(1001), result); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - @Test public void add_ZERO_and_INDEFINITE_ResultsInIndefinite() { - //assertTrue(0.0 + Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY); // sanity check - assertEquals(new Double(Double.POSITIVE_INFINITY), new Double(0.0 + Double.POSITIVE_INFINITY)); // sanity check - - assertTrue(Duration.ZERO.add(Duration.INDEFINITE).isIndefinite()); - assertFalse(Duration.ZERO.add(Duration.INDEFINITE).isUnknown()); - } - - @Test public void add_ONE_and_INDEFINITE_ResultsInIndefinite() { - //assertTrue(1.0 + Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY); // sanity check - assertEquals(new Double(Double.POSITIVE_INFINITY), new Double(1.0 + Double.POSITIVE_INFINITY)); // sanity check - - assertTrue(Duration.ONE.add(Duration.INDEFINITE).isIndefinite()); - assertFalse(Duration.ONE.add(Duration.INDEFINITE).isUnknown()); - } - - @Test public void add_INDEFINITE_and_INDEFINITE_ResultsInIndefinite() { - //assertTrue(Double.POSITIVE_INFINITY + Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY); // sanity check - assertEquals(new Double(Double.POSITIVE_INFINITY), new Double(Double.POSITIVE_INFINITY + Double.POSITIVE_INFINITY)); // sanity check - - assertTrue(Duration.INDEFINITE.add(Duration.INDEFINITE).isIndefinite()); - assertFalse(Duration.INDEFINITE.add(Duration.INDEFINITE).isUnknown()); - } - - @Test public void add_UNKNOWN_and_INDEFINITE_ResultsInUnknown() { - assertTrue(Double.isNaN(Double.NaN + Double.POSITIVE_INFINITY)); // sanity check - assertEquals(new Double(Double.NaN), new Double(Double.NaN + Double.POSITIVE_INFINITY)); // sanity check - - assertFalse(Duration.UNKNOWN.add(Duration.INDEFINITE).isIndefinite()); - assertTrue(Duration.UNKNOWN.add(Duration.INDEFINITE).isUnknown()); - } - - @Test public void add_ZERO_and_UNKNOWN_ResultsInUnknown() { - assertTrue(Double.isNaN(0.0 + Double.NaN)); // sanity check - assertEquals(new Double(Double.NaN), new Double(0.0 + Double.NaN)); // sanity check - - assertFalse(Duration.ZERO.add(Duration.UNKNOWN).isIndefinite()); - assertTrue(Duration.ZERO.add(Duration.UNKNOWN).isUnknown()); - } - - @Test public void add_ONE_and_UNKNOWN_ResultsInUnknown() { - assertTrue(Double.isNaN(1.0 + Double.NaN)); // sanity check - assertEquals(new Double(Double.NaN), new Double(1.0 + Double.NaN)); // sanity check - - assertFalse(Duration.ONE.add(Duration.UNKNOWN).isIndefinite()); - assertTrue(Duration.ONE.add(Duration.UNKNOWN).isUnknown()); - } - - @Test public void testAddUsingMixedUnits() { - Duration a = Duration.seconds(30); - Duration b = Duration.minutes(10); - Duration result = a.add(b); - Duration expected = Duration.millis((1000 * 30) + (10 * 60 * 1000)); - assertEquals(expected, result); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - /************************************************************************************ - * - * Tests for subtracting two Durations - * - ***********************************************************************************/ - - @Test public void subtract_doesNotModifyTheInputArguments() { - Duration a = new Duration(30); - Duration b = new Duration(20); - Duration result = a.subtract(b); - assertEquals(new Duration(10), result); - assertEquals(30, a.toMillis(), 0); - assertEquals(20, b.toMillis(), 0); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - @Test public void subtract_ZERO_and_ZERO_ResultsIn_ZERO() { - assertSame(Duration.ZERO, Duration.ZERO.subtract(Duration.ZERO)); - } - - @Test public void subtract_ZERO_and_ONE_ResultsIn_NegativeOne() { - assertEquals(new Duration(-1), Duration.ZERO.subtract(Duration.ONE)); - } - - @Test public void subtract_ONE_and_ZERO_ResultsIn_ONE() { - assertSame(Duration.ONE, Duration.ONE.subtract(Duration.ZERO)); - } - - @Test public void subtract_ONE_and_ONE_ResultsInZERO() { - assertEquals(Duration.ZERO, Duration.ONE.subtract(Duration.ONE)); - } - - @Test public void subtract_ONE_Second_and_ONE_Milli_ResultsInNineHundredNinetyNineMillis() { - assertEquals(new Duration(999), Duration.seconds(1).subtract(Duration.ONE)); - } - - @Test public void subtract_ZERO_and_INDEFINITE_ResultsInNegativeInfinity() { - //assertTrue(0.0 - Double.POSITIVE_INFINITY == Double.NEGATIVE_INFINITY); // sanity check - assertEquals(new Double(Double.NEGATIVE_INFINITY), new Double(0.0 - Double.POSITIVE_INFINITY)); // sanity check - - final Duration result = Duration.ZERO.subtract(Duration.INDEFINITE); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - assertEquals(new Duration(Double.NEGATIVE_INFINITY), result); - } - - @Test public void subtract_ONE_and_INDEFINITE_ResultsInNegativeInfinity() { - //assertTrue(1.0 - Double.POSITIVE_INFINITY == Double.NEGATIVE_INFINITY); // sanity check - assertEquals(new Double(Double.NEGATIVE_INFINITY), new Double(1.0 - Double.POSITIVE_INFINITY)); // sanity check - - final Duration result = Duration.ONE.subtract(Duration.INDEFINITE); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - assertEquals(new Duration(Double.NEGATIVE_INFINITY), result); - } - - @Test public void subtract_INDEFINITE_and_INDEFINITE_ResultsInUnknown() { - assertTrue(Double.isNaN(Double.POSITIVE_INFINITY - Double.POSITIVE_INFINITY)); // sanity check - assertEquals(new Double(Double.NaN), new Double(Double.POSITIVE_INFINITY - Double.POSITIVE_INFINITY)); // sanity check - - assertFalse(Duration.INDEFINITE.subtract(Duration.INDEFINITE).isIndefinite()); - assertTrue(Duration.INDEFINITE.subtract(Duration.INDEFINITE).isUnknown()); - } - - @Test public void subtract_UNKNOWN_and_INDEFINITE_ResultsInUnknown() { - assertTrue(Double.isNaN(Double.NaN - Double.POSITIVE_INFINITY)); // sanity check - assertEquals(new Double(Double.NaN), new Double(Double.NaN - Double.POSITIVE_INFINITY)); // sanity check - - assertFalse(Duration.UNKNOWN.subtract(Duration.INDEFINITE).isIndefinite()); - assertTrue(Duration.UNKNOWN.subtract(Duration.INDEFINITE).isUnknown()); - } - - @Test public void subtract_ZERO_and_UNKNOWN_ResultsInUnknown() { - assertTrue(Double.isNaN(0 - Double.NaN)); // sanity check - assertEquals(new Double(Double.NaN), new Double(0.0 - Double.NaN)); // sanity check - - assertFalse(Duration.ZERO.subtract(Duration.UNKNOWN).isIndefinite()); - assertTrue(Duration.ZERO.subtract(Duration.UNKNOWN).isUnknown()); - } - - @Test public void subtract_ONE_and_UNKNOWN_ResultsInUnknown() { - assertTrue(Double.isNaN(1.0 - Double.NaN)); // sanity check - assertEquals(new Double(Double.NaN), new Double(1.0 - Double.NaN)); // sanity check - - assertFalse(Duration.ONE.subtract(Duration.UNKNOWN).isIndefinite()); - assertTrue(Duration.ONE.subtract(Duration.UNKNOWN).isUnknown()); - } - - @Test public void testSubtractUsingMixedUnits() { - Duration a = Duration.minutes(10); - Duration b = Duration.seconds(30); - Duration expected = Duration.millis((1000 * 30) + (9 * 60 * 1000)); - assertEquals(expected, a.subtract(b)); - } - - /************************************************************************************ - * - * Tests for multiplying two Durations - * - ***********************************************************************************/ - - @Test public void multiply_doesNotModifyTheInputArguments() { - Duration a = new Duration(3); - Duration result = a.multiply(2); - assertEquals(new Duration(6), result); - assertEquals(3, a.toMillis(), 0); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - @Test public void multiply_ZERO_and_ZERO_ResultsIn_ZERO() { - assertSame(Duration.ZERO, Duration.ZERO.multiply(0)); - } - - @Test public void multiply_ZERO_and_ONE_ResultsIn_ZERO() { - assertSame(Duration.ZERO, Duration.ZERO.multiply(1)); - assertSame(Duration.ZERO, Duration.ONE.multiply(0)); - } - - @Test public void multiply_ONE_and_ONE_ResultsIn_ONE() { - assertEquals(Duration.ONE, Duration.ONE.multiply(1)); - } - - @Test public void multiply_ONE_Second_and_ONE_Milli_ResultsInOneSecond() { - assertEquals(new Duration(1000), Duration.seconds(1).multiply(1)); - } - - @Test public void multiply_ZERO_and_INDEFINITE_ResultsInUnknown() { - assertTrue(Double.isNaN(0.0 * Double.POSITIVE_INFINITY)); // sanity check - assertEquals(new Double(Double.NaN), new Double(0.0 * Double.POSITIVE_INFINITY)); // sanity check - - assertFalse(Duration.ZERO.multiply(Double.POSITIVE_INFINITY).isIndefinite()); - assertTrue(Duration.ZERO.multiply(Double.POSITIVE_INFINITY).isUnknown()); - } - - @Test public void multiply_ONE_and_INDEFINITE_ResultsInIndefinite() { - //assertTrue(1.0 * Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY); // sanity check - assertEquals(new Double(Double.POSITIVE_INFINITY), new Double(1.0 * Double.POSITIVE_INFINITY)); // sanity check - - assertTrue(Duration.ONE.multiply(Double.POSITIVE_INFINITY).isIndefinite()); - assertFalse(Duration.ONE.multiply(Double.POSITIVE_INFINITY).isUnknown()); - } - - @Test public void multiply_INDEFINITE_and_INDEFINITE_ResultsInIndefinite() { - //assertTrue(Double.POSITIVE_INFINITY * Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY); // sanity check - assertEquals(new Double(Double.POSITIVE_INFINITY), new Double(Double.POSITIVE_INFINITY * Double.POSITIVE_INFINITY)); // sanity check - - assertTrue(Duration.INDEFINITE.multiply(Double.POSITIVE_INFINITY).isIndefinite()); - assertFalse(Duration.INDEFINITE.multiply(Double.POSITIVE_INFINITY).isUnknown()); - } - - @Test public void multiply_UNKNOWN_and_INDEFINITE_ResultsInUnknown() { - assertTrue(Double.isNaN(Double.NaN * Double.POSITIVE_INFINITY)); // sanity check - assertEquals(new Double(Double.NaN), new Double(Double.NaN * Double.POSITIVE_INFINITY)); // sanity check - - assertFalse(Duration.UNKNOWN.multiply(Double.POSITIVE_INFINITY).isIndefinite()); - assertTrue(Duration.UNKNOWN.multiply(Double.POSITIVE_INFINITY).isUnknown()); - } - - @Test public void multiply_ZERO_and_UNKNOWN_ResultsInUnknown() { - assertTrue(Double.isNaN(0 * Double.NaN)); // sanity check - assertEquals(new Double(Double.NaN), new Double(0.0 * Double.NaN)); // sanity check - - assertFalse(Duration.ZERO.multiply(Double.NaN).isIndefinite()); - assertTrue(Duration.ZERO.multiply(Double.NaN).isUnknown()); - } - - @Test public void multiply_ONE_and_UNKNOWN_ResultsInUnknown() { - assertTrue(Double.isNaN(1.0 * Double.NaN)); // sanity check - assertEquals(new Double(Double.NaN), new Double(1.0 * Double.NaN)); // sanity check - - assertFalse(Duration.ONE.multiply(Double.NaN).isIndefinite()); - assertTrue(Duration.ONE.multiply(Double.NaN).isUnknown()); - } - - @SuppressWarnings("deprecation") - @Test public void testMultiplyUsingMixedUnits() { - Duration a = Duration.minutes(10); - Duration b = Duration.seconds(30); - Duration expected = Duration.millis((1000.0 * 30) * (10 * 60 * 1000.0)); - assertEquals(expected, a.multiply(b)); - } - - /************************************************************************************ - * - * Tests for dividing two Durations - * - ***********************************************************************************/ - - @Test public void divide_doesNotModifyTheInputArguments() { - Duration a = new Duration(10); - Duration result = a.divide(2); - assertEquals(new Duration(5), result); - assertEquals(10, a.toMillis(), 0); - assertFalse(result.isIndefinite()); - assertFalse(result.isUnknown()); - } - - @Test public void divide_Ten_by_ZERO_ResultsIn_INDEFINITE() { - assertTrue(new Duration(10).divide(0).isIndefinite()); - assertFalse(new Duration(10).divide(0).isUnknown()); - } - - @Test public void divide_ZERO_by_Ten_ResultsIn_ZERO() { - assertSame(Duration.ZERO, Duration.ZERO.divide(10)); - } - - @Test public void divide_ONE_by_ONE_ResultsIn_ONE() { - assertEquals(Duration.ONE, Duration.ONE.divide(1)); - } - - @Test public void divide_ONE_Second_by_ONE_Milli_ResultsInOneSecond() { - assertEquals(new Duration(1000), Duration.seconds(1).divide(1)); - } - - @Test public void divide_ZERO_by_INDEFINITE_ResultsIn_ZERO() { - //assertTrue(0.0 / Double.POSITIVE_INFINITY == 0.0); // sanity check - assertEquals(new Double(0.0), new Double(0.0 / Double.POSITIVE_INFINITY)); // sanity check - - assertSame(Duration.ZERO, Duration.ZERO.divide(Double.POSITIVE_INFINITY)); - } - - @Test public void divide_ONE_by_INDEFINITE_ResultsIn_ZERO() { - //assertTrue(1.0 / Double.POSITIVE_INFINITY == 0.0); // sanity check - assertEquals(new Double(0.0), new Double(1.0 / Double.POSITIVE_INFINITY)); // sanity check - - assertSame(Duration.ZERO, Duration.ONE.divide(Double.POSITIVE_INFINITY)); - } - - @Test public void divide_INDEFINITE_by_INDEFINITE_ResultsInUnknown() { - assertTrue(Double.isNaN(Double.POSITIVE_INFINITY / Double.POSITIVE_INFINITY)); // sanity check - assertEquals(new Double(Double.NaN), new Double(Double.POSITIVE_INFINITY / Double.POSITIVE_INFINITY)); // sanity check - - assertFalse(Duration.INDEFINITE.divide(Double.POSITIVE_INFINITY).isIndefinite()); - assertTrue(Duration.INDEFINITE.divide(Double.POSITIVE_INFINITY).isUnknown()); - } - - @Test public void divide_UNKNOWN_by_INDEFINITE_ResultsInUnknown() { - assertTrue(Double.isNaN(Double.NaN / Double.POSITIVE_INFINITY)); // sanity check - assertEquals(new Double(Double.NaN), new Double(Double.NaN / Double.POSITIVE_INFINITY)); // sanity check - - assertFalse(Duration.UNKNOWN.divide(Double.POSITIVE_INFINITY).isIndefinite()); - assertTrue(Duration.UNKNOWN.divide(Double.POSITIVE_INFINITY).isUnknown()); - } - - @Test public void divide_ZERO_by_UNKNOWN_ResultsInUnknown() { - assertTrue(Double.isNaN(0.0 / Double.NaN)); // sanity check - assertEquals(new Double(Double.NaN), new Double(0.0 / Double.NaN)); // sanity check - - assertFalse(Duration.ZERO.divide(Double.NaN).isIndefinite()); - assertTrue(Duration.ZERO.divide(Double.NaN).isUnknown()); - } - - @Test public void divide_ONE_by_UNKNOWN_ResultsInUnknown() { - assertTrue(Double.isNaN(1.0 / Double.NaN)); // sanity check - assertEquals(new Double(Double.NaN), new Double(1.0 / Double.NaN)); // sanity check - - assertFalse(Duration.ONE.divide(Double.NaN).isIndefinite()); - assertTrue(Duration.ONE.divide(Double.NaN).isUnknown()); - } - - @SuppressWarnings("deprecation") - @Test public void testDivideUsingMixedUnits() { - Duration a = Duration.minutes(10); - Duration b = Duration.seconds(30); - Duration expected = Duration.millis((10 * 60 * 1000.0) / (1000.0 * 30)); - assertEquals(expected, a.divide(b)); - } - - /************************************************************************************ - * - * Tests for negating a Duration - * - ***********************************************************************************/ - - @Test public void negate_ZERO_ResultsIn_NegativeZeroOr_ZERO() { - assertEquals(new Duration(-0), Duration.ZERO.negate()); - assertSame(Duration.ZERO, Duration.ZERO.negate()); - } - - @Test public void negate_ONE_ResultsIn_NegativeOne() { - assertEquals(new Duration(-1), Duration.ONE.negate()); - } - - @Test public void negate_INDEFINITE_ResultsIn_NegativeInfinity() { - final Duration result = Duration.INDEFINITE.negate(); - assertEquals(new Duration(Double.NEGATIVE_INFINITY), result); - assertNotSame(Duration.INDEFINITE, result); - } - - @Test public void negate_UNKNOWN_ResultsIn_UNKNOWN() { - final Duration result = Duration.UNKNOWN.negate(); - assertSame(Duration.UNKNOWN, result); - assertFalse(result.isIndefinite()); - assertTrue(result.isUnknown()); - } - - @Test public void negate_NegativeResultsInPositive() { - assertEquals(new Duration(50), new Duration(-50).negate()); - } - - @Test public void negate_PositiveResultsInNegative() { - assertEquals(new Duration(-50), new Duration(50).negate()); - } - - /************************************************************************************ - * - * Tests for lessThan comparison with Duration - * - ***********************************************************************************/ - - @Test public void negativeInfinityIsLessThan_ZERO() { - assertTrue(Double.NEGATIVE_INFINITY < 0); - assertTrue(new Duration(Double.NEGATIVE_INFINITY).lessThan(Duration.ZERO)); - } - - @Test public void negativeInfinityIsNotLessThanNegativeInfinity() { - assertFalse(Double.NEGATIVE_INFINITY < Double.NEGATIVE_INFINITY); - Duration a = new Duration(Double.NEGATIVE_INFINITY); - assertFalse(a.lessThan(a)); - } - - @Test public void negativeNumberIsLessThanZero() { - assertTrue(-10 < 0.0); - assertTrue(new Duration(-10).lessThan(Duration.ZERO)); - } - - @Test public void ZERO_isLessThan_ONE() { - assertTrue(0 < 1); - assertTrue(Duration.ZERO.lessThan(Duration.ONE)); - } - - @Test public void ONE_isLessThan_INDEFINITE() { - assertTrue(0 < Double.POSITIVE_INFINITY); - assertTrue(Duration.ONE.lessThan(Duration.INDEFINITE)); - } - - @Test public void INDEFINITE_isNotLessThan_INDEFINITE() { - assertFalse(Double.POSITIVE_INFINITY < Double.POSITIVE_INFINITY); - assertFalse(Duration.INDEFINITE.lessThan(Duration.INDEFINITE)); - } - - @Test public void UNKNOWN_isNotLessThan_NegativeInfinity() { - assertFalse(Double.NaN < Double.NEGATIVE_INFINITY); - assertFalse(Duration.UNKNOWN.lessThan(new Duration(Double.NEGATIVE_INFINITY))); - } - - @Test public void UNKNOWN_isNotLessThan_ZERO() { - assertFalse(Double.NaN < 0.0); - assertFalse(Duration.UNKNOWN.lessThan(Duration.ZERO)); - } - - @Test public void UNKNOWN_isNotLessThan_ONE() { - assertFalse(Double.NaN < 1.0); - assertFalse(Duration.UNKNOWN.lessThan(Duration.ONE)); - } - - @Test public void UNKNOWN_isNotLessThan_INDEFINITE() { - assertFalse(Double.NaN < Double.POSITIVE_INFINITY); - assertFalse(Duration.UNKNOWN.lessThan(Duration.INDEFINITE)); - } - - @Test public void UNKNOWN_isNotLessThan_UNKNOWN() { - assertFalse(Double.NaN < Double.NaN); - assertFalse(Duration.UNKNOWN.lessThan(Duration.UNKNOWN)); - } - - /************************************************************************************ - * - * Tests for lessThanOrEqualTo comparison with Duration - * - ***********************************************************************************/ - - @Test public void negativeInfinityIsLessThanOrEqualTo_ZERO() { - assertTrue(Double.NEGATIVE_INFINITY <= 0); - assertTrue(new Duration(Double.NEGATIVE_INFINITY).lessThanOrEqualTo(Duration.ZERO)); - } - - @Test public void negativeInfinityIsLessThanOrEqualToNegativeInfinity() { - assertTrue(Double.NEGATIVE_INFINITY <= Double.NEGATIVE_INFINITY); - Duration a = new Duration(Double.NEGATIVE_INFINITY); - assertTrue(a.lessThanOrEqualTo(a)); - } - - @Test public void negativeNumberIsLessOrEqualToThanZero() { - assertTrue(-10 <= 0); - assertTrue(new Duration(-10).lessThanOrEqualTo(Duration.ZERO)); - } - - @Test public void ZERO_isLessThanOrEqualTo_ONE() { - assertTrue(0 <= 1); - assertTrue(Duration.ZERO.lessThanOrEqualTo(Duration.ONE)); - } - - @Test public void ONE_isLessThanOrEqualTo_INDEFINITE() { - assertTrue(1 <= Double.POSITIVE_INFINITY); - assertTrue(Duration.ONE.lessThanOrEqualTo(Duration.INDEFINITE)); - } - - @Test public void INDEFINITE_isLessThanOrEqualTo_INDEFINITE() { - assertTrue(Double.POSITIVE_INFINITY <= Double.POSITIVE_INFINITY); - assertTrue(Duration.INDEFINITE.lessThanOrEqualTo(Duration.INDEFINITE)); - } - - @Test public void UNKNOWN_isNotLessThanOrEqualTo_NegativeInfinity() { - assertFalse(Double.NaN <= Double.NEGATIVE_INFINITY); - assertFalse(Duration.UNKNOWN.lessThanOrEqualTo(new Duration(Double.NEGATIVE_INFINITY))); - } - - @Test public void UNKNOWN_isNotLessThanOrEqualTo_ZERO() { - assertFalse(Double.NaN <= 0.0); - assertFalse(Duration.UNKNOWN.lessThanOrEqualTo(Duration.ZERO)); - } - - @Test public void UNKNOWN_isNotLessThanOrEqualTo_ONE() { - assertFalse(Double.NaN <= 1.0); - assertFalse(Duration.UNKNOWN.lessThanOrEqualTo(Duration.ONE)); - } - - @Test public void UNKNOWN_isNotLessThanOrEqualTo_INDEFINITE() { - assertFalse(Double.NaN <= Double.POSITIVE_INFINITY); - assertFalse(Duration.UNKNOWN.lessThanOrEqualTo(Duration.INDEFINITE)); - } - - @Test public void UNKNOWN_isNotLessThanOrEqualTo_UNKNOWN() { - assertFalse(Double.NaN <= Double.NaN); - assertFalse(Duration.UNKNOWN.lessThanOrEqualTo(Duration.UNKNOWN)); - } - - /************************************************************************************ - * - * Tests for greaterThan comparison with Duration - * - ***********************************************************************************/ - - @Test public void ZERO_isGreaterThanNegativeInfinity() { - assertTrue(Duration.ZERO.greaterThan(new Duration(Double.NEGATIVE_INFINITY))); - } - - @Test public void negativeInfinityIsNotGreaterThanNegativeInfinity() { - Duration a = new Duration(Double.NEGATIVE_INFINITY); - assertFalse(a.greaterThan(a)); - } - - @Test public void ZERO_isGreaterThanNegativeNumber() { - assertTrue(Duration.ZERO.greaterThan(new Duration(-10))); - } - - @Test public void ONE_isGreaterThan_ZERO() { - assertTrue(Duration.ONE.greaterThan(Duration.ZERO)); - } - - @Test public void INDEFINITE_isGreaterThan_ONE() { - assertTrue(Duration.INDEFINITE.greaterThan(Duration.ONE)); - } - - @Test public void INDEFINITE_isNotGreaterThan_INDEFINITE() { - assertFalse(Duration.INDEFINITE.greaterThan(Duration.INDEFINITE)); - } - - @Test public void UNKNOWN_isNotGreaterThan_NegativeInfinity() { - assertFalse(Duration.UNKNOWN.greaterThan(new Duration(Double.NEGATIVE_INFINITY))); - } - - @Test public void UNKNOWN_isNotGreaterThan_ZERO() { - assertFalse(Duration.UNKNOWN.greaterThan(Duration.ZERO)); - } - - @Test public void UNKNOWN_isNotGreaterThan_ONE() { - assertFalse(Duration.UNKNOWN.greaterThan(Duration.ONE)); - } - - @Test public void UNKNOWN_isNotGreaterThan_INDEFINITE() { - assertFalse(Duration.UNKNOWN.greaterThan(Duration.INDEFINITE)); - } - - @Test public void UNKNOWN_isNotGreaterThan_UNKNOWN() { - assertFalse(Duration.UNKNOWN.greaterThan(Duration.UNKNOWN)); - } - - /************************************************************************************ - * - * Tests for greaterThanOrEqualTo comparison with Duration - * - ***********************************************************************************/ - - @Test public void ZERO_isGreaterThanOrEqualToNegativeInfinity() { - assertTrue(Duration.ZERO.greaterThanOrEqualTo(new Duration(Double.NEGATIVE_INFINITY))); - } - - @Test public void negativeInfinityIsGreaterThanOrEqualToNegativeInfinity() { - Duration a = new Duration(Double.NEGATIVE_INFINITY); - assertTrue(a.greaterThanOrEqualTo(a)); - } - - @Test public void ZERO_isGreaterThanOrEqualToNegativeNumber() { - assertTrue(Duration.ZERO.greaterThanOrEqualTo(new Duration(-10))); - } - - @Test public void ONE_isGreaterThanOrEqualTo_ZERO() { - assertTrue(Duration.ONE.greaterThanOrEqualTo(Duration.ZERO)); - } - - @Test public void INDEFINITE_isGreaterThanOrEqualTo_ONE() { - assertTrue(Duration.INDEFINITE.greaterThanOrEqualTo(Duration.ONE)); - } - - @Test public void INDEFINITE_isGreaterThanOrEqualTo_INDEFINITE() { - assertTrue(Duration.INDEFINITE.greaterThanOrEqualTo(Duration.INDEFINITE)); - } - - @Test public void UNKNOWN_isNotGreaterThanOrEqualTo_NegativeInfinity() { - assertFalse(Duration.UNKNOWN.greaterThanOrEqualTo(new Duration(Double.NEGATIVE_INFINITY))); - } - - @Test public void UNKNOWN_isNotGreaterThanOrEqualTo_ZERO() { - assertFalse(Duration.UNKNOWN.greaterThanOrEqualTo(Duration.ZERO)); - } - - @Test public void UNKNOWN_isNotGreaterThanOrEqualTo_ONE() { - assertFalse(Duration.UNKNOWN.greaterThanOrEqualTo(Duration.ONE)); - } - - @Test public void UNKNOWN_isNotGreaterThanOrEqualTo_INDEFINITE() { - assertFalse(Duration.UNKNOWN.greaterThanOrEqualTo(Duration.INDEFINITE)); - } - - @Test public void UNKNOWN_isNotGreaterThanOrEqualTo_UNKNOWN() { - assertFalse(Duration.UNKNOWN.greaterThanOrEqualTo(Duration.UNKNOWN)); - } - - /************************************************************************************ - * - * Tests for equality comparison with Duration - * - ***********************************************************************************/ - - @Test public void NegativeInfinityEqualsNegativeInfinity() { - assertEquals(new Duration(Double.NEGATIVE_INFINITY), new Duration(Double.NEGATIVE_INFINITY)); - } - - @Test public void ZERO_EqualsZero() { - assertEquals(Duration.ZERO, new Duration(0)); - } - - @Test public void ONE_EqualsOne() { - assertEquals(Duration.ONE, new Duration(1)); - } - - @Test public void INDEFINITE_Equals_PositiveInfinity() { - assertEquals(Duration.INDEFINITE, new Duration(Double.POSITIVE_INFINITY)); - } - - @Test public void UNKNOWN_DoesNotEqualNaN() { - assertFalse(Duration.UNKNOWN.equals(new Duration(Double.NaN))); - } - - @Test public void UNKNOWN_Equals_UNKNOWN() { - assertEquals(Duration.UNKNOWN, Duration.UNKNOWN); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/DurationTest.java 2015-08-31 10:25:10.013216321 -0400 @@ -0,0 +1,906 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util; + +import javafx.util.Duration; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + */ +public class DurationTest { + + /************************************************************************************ + * + * Tests for the static millis() method + * + ***********************************************************************************/ + + @Test public void millis_withZeroResultsIn_ZERO() { + assertSame(Duration.ZERO, Duration.millis(0)); + } + + @Test public void millis_withOneResultsIn_ONE() { + assertSame(Duration.ONE, Duration.millis(1)); + } + + @Test public void millis_withPositiveInfinityResultsIn_INDEFINITE() { + assertSame(Duration.INDEFINITE, Duration.millis(Double.POSITIVE_INFINITY)); + } + + @Test public void millis_withNaNResultsIn_UNKNOWN() { + assertSame(Duration.UNKNOWN, Duration.millis(Double.NaN)); + } + + @Test public void millis_withPositiveResultsInNewDuration() { + final Duration result = Duration.millis(9); + assertEquals(result.toMillis(), 9, 0); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + /************************************************************************************ + * + * Tests for the static seconds() method + * + ***********************************************************************************/ + + @Test public void seconds_withZeroResultsIn_ZERO() { + assertSame(Duration.ZERO, Duration.seconds(0)); + } + + @Test public void seconds_withPositiveInfinityResultsIn_INDEFINITE() { + assertSame(Duration.INDEFINITE, Duration.seconds(Double.POSITIVE_INFINITY)); + } + + @Test public void seconds_withNaNResultsIn_UNKNOWN() { + assertSame(Duration.UNKNOWN, Duration.seconds(Double.NaN)); + } + + @Test public void seconds_withPositiveResultsInNewDuration() { + final Duration result = Duration.seconds(9); + assertEquals(result.toSeconds(), 9, 0); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + /************************************************************************************ + * + * Tests for the static minutes() method + * + ***********************************************************************************/ + + @Test public void minutes_withZeroResultsIn_ZERO() { + assertSame(Duration.ZERO, Duration.minutes(0)); + } + + @Test public void minutes_withPositiveInfinityResultsIn_INDEFINITE() { + assertSame(Duration.INDEFINITE, Duration.minutes(Double.POSITIVE_INFINITY)); + } + + @Test public void minutes_withNaNResultsIn_UNKNOWN() { + assertSame(Duration.UNKNOWN, Duration.minutes(Double.NaN)); + } + + @Test public void minutes_withPositiveResultsInNewDuration() { + final Duration result = Duration.minutes(9); + assertEquals(result.toMinutes(), 9, 0); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + /************************************************************************************ + * + * Tests for the static hours() method + * + ***********************************************************************************/ + + @Test public void hours_withZeroResultsIn_ZERO() { + assertSame(Duration.ZERO, Duration.hours(0)); + } + + @Test public void hours_withPositiveInfinityResultsIn_INDEFINITE() { + assertSame(Duration.INDEFINITE, Duration.hours(Double.POSITIVE_INFINITY)); + } + + @Test public void hours_withNaNResultsIn_UNKNOWN() { + assertSame(Duration.UNKNOWN, Duration.hours(Double.NaN)); + } + + @Test public void hours_withPositiveResultsInNewDuration() { + final Duration result = Duration.hours(9); + assertEquals(result.toHours(), 9, 0); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + /************************************************************************************ + * + * Tests for the one-arg constructor + * + ***********************************************************************************/ + + @Test public void constructor_withZeroEquals_ZERO() { + assertEquals(Duration.ZERO, new Duration(0)); + } + + @Test public void constructor_withOneEquals_ONE() { + assertEquals(Duration.ONE, new Duration(1)); + } + + @Test public void constructor_withPositiveInfinityEquals_INDEFINITE() { + assertTrue(Duration.INDEFINITE.equals(new Duration(Double.POSITIVE_INFINITY))); + } + + @Test public void constructor_withNaNDoesNotEqual_UNKNOWN() { + assertFalse(Duration.UNKNOWN.equals(new Duration(Double.NaN))); + } + + @Test public void constructor_withPositiveResultsInNewDuration() { + final Duration result = new Duration(9); + assertEquals(result.toMillis(), 9, 0); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + /************************************************************************************ + * + * Tests for the toMillis method + * + ***********************************************************************************/ + + @Test public void toMillis_when_ZERO_resultsInZero() { + assertEquals(0, Duration.ZERO.toMillis(), 0); + } + + @Test public void toMillis_when_ONE_resultsInOne() { + assertEquals(1, Duration.ONE.toMillis(), 0); + } + + @Test public void toMillis_when_INDEFINITE_resultsInPositiveInfinity() { + assertTrue(Double.isInfinite(Duration.INDEFINITE.toMillis())); + } + + @Test public void toMillis_whenNegativeInfinityResultsInNegativeInfinity() { + assertTrue(Double.isInfinite(new Duration(Double.NEGATIVE_INFINITY).toMillis())); + } + + @Test public void toMillis_when_UNKNOWN_ResultsInNaN() { + assertTrue(Double.isNaN(Duration.UNKNOWN.toMillis())); + } + + @Test public void toMillis_whenPositiveNumberResultsInTheSameNumber() { + assertEquals(87, new Duration(87).toMillis(), 0); + } + + @Test public void toMillis_whenNegativeNumberResultsInTheSameNumber() { + assertEquals(-7, new Duration(-7).toMillis(), 0); + } + + /************************************************************************************ + * + * Tests for the toSeconds method + * + ***********************************************************************************/ + + @Test public void toSeconds_when_ZERO_resultsInZero() { + assertEquals(0, Duration.ZERO.toSeconds(), 0); + } + + @Test public void toSeconds_when_ONE_resultsInPointZeroZeroOne() { + assertEquals(.001, Duration.ONE.toSeconds(), 0); + } + + @Test public void toSeconds_when_INDEFINITE_resultsInPositiveInfinity() { + assertTrue(Double.isInfinite(Duration.INDEFINITE.toSeconds())); + } + + @Test public void toSeconds_whenNegativeInfinityResultsInNegativeInfinity() { + assertTrue(Double.isInfinite(new Duration(Double.NEGATIVE_INFINITY).toSeconds())); + } + + @Test public void toSeconds_when_UNKNOWN_ResultsInNaN() { + assertTrue(Double.isNaN(Duration.UNKNOWN.toSeconds())); + } + + @Test public void toSeconds_whenPositiveNumberResultsInTheSameNumber() { + assertEquals(.087, new Duration(87).toSeconds(), 0); + } + + @Test public void toSeconds_whenNegativeNumberResultsInTheSameNumber() { + assertEquals(-.007, new Duration(-7).toSeconds(), 0); + } + + // toMinutes + // 0, +infinity, -infinity, Nan, positive value, negative value + // toHours + // 0, +infinity, -infinity, Nan, positive value, negative value + + + /************************************************************************************ + * + * Tests for adding two Durations. For the most part I just test millis, + * because I know the implementation stores just millis, but for completeness + * and to avoid regressions should we change the storage format, I'll also + * throw in a few tests which work on seconds, minutes, and a mixture of + * seconds and minutes. + * + ***********************************************************************************/ + + @Test public void add_doesNotModifyTheInputArguments() { + Duration a = new Duration(10); + Duration b = new Duration(20); + final Duration result = a.add(b); + assertEquals(new Duration(30), result); + assertEquals(10, a.toMillis(), 0); + assertEquals(20, b.toMillis(), 0); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + @Test public void add_ZERO_and_ZERO_ResultsIn_ZERO() { + assertSame(Duration.ZERO, Duration.ZERO.add(Duration.ZERO)); + } + + @Test public void add_ZERO_and_ONE_ResultsIn_ONE() { + assertSame(Duration.ONE, Duration.ZERO.add(Duration.ONE)); + assertSame(Duration.ONE, Duration.ONE.add(Duration.ZERO)); + } + + @Test public void add_ONE_and_ONE_ResultsInTwo() { + final Duration result = Duration.ONE.add(Duration.ONE); + assertEquals(new Duration(2), result); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + @Test public void add_ONE_Second_and_ONE_Milli_ResultsInOneThousandOneMillis() { + final Duration result = Duration.seconds(1).add(Duration.ONE); + assertEquals(new Duration(1001), result); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + @Test public void add_ZERO_and_INDEFINITE_ResultsInIndefinite() { + //assertTrue(0.0 + Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY); // sanity check + assertEquals(new Double(Double.POSITIVE_INFINITY), new Double(0.0 + Double.POSITIVE_INFINITY)); // sanity check + + assertTrue(Duration.ZERO.add(Duration.INDEFINITE).isIndefinite()); + assertFalse(Duration.ZERO.add(Duration.INDEFINITE).isUnknown()); + } + + @Test public void add_ONE_and_INDEFINITE_ResultsInIndefinite() { + //assertTrue(1.0 + Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY); // sanity check + assertEquals(new Double(Double.POSITIVE_INFINITY), new Double(1.0 + Double.POSITIVE_INFINITY)); // sanity check + + assertTrue(Duration.ONE.add(Duration.INDEFINITE).isIndefinite()); + assertFalse(Duration.ONE.add(Duration.INDEFINITE).isUnknown()); + } + + @Test public void add_INDEFINITE_and_INDEFINITE_ResultsInIndefinite() { + //assertTrue(Double.POSITIVE_INFINITY + Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY); // sanity check + assertEquals(new Double(Double.POSITIVE_INFINITY), new Double(Double.POSITIVE_INFINITY + Double.POSITIVE_INFINITY)); // sanity check + + assertTrue(Duration.INDEFINITE.add(Duration.INDEFINITE).isIndefinite()); + assertFalse(Duration.INDEFINITE.add(Duration.INDEFINITE).isUnknown()); + } + + @Test public void add_UNKNOWN_and_INDEFINITE_ResultsInUnknown() { + assertTrue(Double.isNaN(Double.NaN + Double.POSITIVE_INFINITY)); // sanity check + assertEquals(new Double(Double.NaN), new Double(Double.NaN + Double.POSITIVE_INFINITY)); // sanity check + + assertFalse(Duration.UNKNOWN.add(Duration.INDEFINITE).isIndefinite()); + assertTrue(Duration.UNKNOWN.add(Duration.INDEFINITE).isUnknown()); + } + + @Test public void add_ZERO_and_UNKNOWN_ResultsInUnknown() { + assertTrue(Double.isNaN(0.0 + Double.NaN)); // sanity check + assertEquals(new Double(Double.NaN), new Double(0.0 + Double.NaN)); // sanity check + + assertFalse(Duration.ZERO.add(Duration.UNKNOWN).isIndefinite()); + assertTrue(Duration.ZERO.add(Duration.UNKNOWN).isUnknown()); + } + + @Test public void add_ONE_and_UNKNOWN_ResultsInUnknown() { + assertTrue(Double.isNaN(1.0 + Double.NaN)); // sanity check + assertEquals(new Double(Double.NaN), new Double(1.0 + Double.NaN)); // sanity check + + assertFalse(Duration.ONE.add(Duration.UNKNOWN).isIndefinite()); + assertTrue(Duration.ONE.add(Duration.UNKNOWN).isUnknown()); + } + + @Test public void testAddUsingMixedUnits() { + Duration a = Duration.seconds(30); + Duration b = Duration.minutes(10); + Duration result = a.add(b); + Duration expected = Duration.millis((1000 * 30) + (10 * 60 * 1000)); + assertEquals(expected, result); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + /************************************************************************************ + * + * Tests for subtracting two Durations + * + ***********************************************************************************/ + + @Test public void subtract_doesNotModifyTheInputArguments() { + Duration a = new Duration(30); + Duration b = new Duration(20); + Duration result = a.subtract(b); + assertEquals(new Duration(10), result); + assertEquals(30, a.toMillis(), 0); + assertEquals(20, b.toMillis(), 0); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + @Test public void subtract_ZERO_and_ZERO_ResultsIn_ZERO() { + assertSame(Duration.ZERO, Duration.ZERO.subtract(Duration.ZERO)); + } + + @Test public void subtract_ZERO_and_ONE_ResultsIn_NegativeOne() { + assertEquals(new Duration(-1), Duration.ZERO.subtract(Duration.ONE)); + } + + @Test public void subtract_ONE_and_ZERO_ResultsIn_ONE() { + assertSame(Duration.ONE, Duration.ONE.subtract(Duration.ZERO)); + } + + @Test public void subtract_ONE_and_ONE_ResultsInZERO() { + assertEquals(Duration.ZERO, Duration.ONE.subtract(Duration.ONE)); + } + + @Test public void subtract_ONE_Second_and_ONE_Milli_ResultsInNineHundredNinetyNineMillis() { + assertEquals(new Duration(999), Duration.seconds(1).subtract(Duration.ONE)); + } + + @Test public void subtract_ZERO_and_INDEFINITE_ResultsInNegativeInfinity() { + //assertTrue(0.0 - Double.POSITIVE_INFINITY == Double.NEGATIVE_INFINITY); // sanity check + assertEquals(new Double(Double.NEGATIVE_INFINITY), new Double(0.0 - Double.POSITIVE_INFINITY)); // sanity check + + final Duration result = Duration.ZERO.subtract(Duration.INDEFINITE); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + assertEquals(new Duration(Double.NEGATIVE_INFINITY), result); + } + + @Test public void subtract_ONE_and_INDEFINITE_ResultsInNegativeInfinity() { + //assertTrue(1.0 - Double.POSITIVE_INFINITY == Double.NEGATIVE_INFINITY); // sanity check + assertEquals(new Double(Double.NEGATIVE_INFINITY), new Double(1.0 - Double.POSITIVE_INFINITY)); // sanity check + + final Duration result = Duration.ONE.subtract(Duration.INDEFINITE); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + assertEquals(new Duration(Double.NEGATIVE_INFINITY), result); + } + + @Test public void subtract_INDEFINITE_and_INDEFINITE_ResultsInUnknown() { + assertTrue(Double.isNaN(Double.POSITIVE_INFINITY - Double.POSITIVE_INFINITY)); // sanity check + assertEquals(new Double(Double.NaN), new Double(Double.POSITIVE_INFINITY - Double.POSITIVE_INFINITY)); // sanity check + + assertFalse(Duration.INDEFINITE.subtract(Duration.INDEFINITE).isIndefinite()); + assertTrue(Duration.INDEFINITE.subtract(Duration.INDEFINITE).isUnknown()); + } + + @Test public void subtract_UNKNOWN_and_INDEFINITE_ResultsInUnknown() { + assertTrue(Double.isNaN(Double.NaN - Double.POSITIVE_INFINITY)); // sanity check + assertEquals(new Double(Double.NaN), new Double(Double.NaN - Double.POSITIVE_INFINITY)); // sanity check + + assertFalse(Duration.UNKNOWN.subtract(Duration.INDEFINITE).isIndefinite()); + assertTrue(Duration.UNKNOWN.subtract(Duration.INDEFINITE).isUnknown()); + } + + @Test public void subtract_ZERO_and_UNKNOWN_ResultsInUnknown() { + assertTrue(Double.isNaN(0 - Double.NaN)); // sanity check + assertEquals(new Double(Double.NaN), new Double(0.0 - Double.NaN)); // sanity check + + assertFalse(Duration.ZERO.subtract(Duration.UNKNOWN).isIndefinite()); + assertTrue(Duration.ZERO.subtract(Duration.UNKNOWN).isUnknown()); + } + + @Test public void subtract_ONE_and_UNKNOWN_ResultsInUnknown() { + assertTrue(Double.isNaN(1.0 - Double.NaN)); // sanity check + assertEquals(new Double(Double.NaN), new Double(1.0 - Double.NaN)); // sanity check + + assertFalse(Duration.ONE.subtract(Duration.UNKNOWN).isIndefinite()); + assertTrue(Duration.ONE.subtract(Duration.UNKNOWN).isUnknown()); + } + + @Test public void testSubtractUsingMixedUnits() { + Duration a = Duration.minutes(10); + Duration b = Duration.seconds(30); + Duration expected = Duration.millis((1000 * 30) + (9 * 60 * 1000)); + assertEquals(expected, a.subtract(b)); + } + + /************************************************************************************ + * + * Tests for multiplying two Durations + * + ***********************************************************************************/ + + @Test public void multiply_doesNotModifyTheInputArguments() { + Duration a = new Duration(3); + Duration result = a.multiply(2); + assertEquals(new Duration(6), result); + assertEquals(3, a.toMillis(), 0); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + @Test public void multiply_ZERO_and_ZERO_ResultsIn_ZERO() { + assertSame(Duration.ZERO, Duration.ZERO.multiply(0)); + } + + @Test public void multiply_ZERO_and_ONE_ResultsIn_ZERO() { + assertSame(Duration.ZERO, Duration.ZERO.multiply(1)); + assertSame(Duration.ZERO, Duration.ONE.multiply(0)); + } + + @Test public void multiply_ONE_and_ONE_ResultsIn_ONE() { + assertEquals(Duration.ONE, Duration.ONE.multiply(1)); + } + + @Test public void multiply_ONE_Second_and_ONE_Milli_ResultsInOneSecond() { + assertEquals(new Duration(1000), Duration.seconds(1).multiply(1)); + } + + @Test public void multiply_ZERO_and_INDEFINITE_ResultsInUnknown() { + assertTrue(Double.isNaN(0.0 * Double.POSITIVE_INFINITY)); // sanity check + assertEquals(new Double(Double.NaN), new Double(0.0 * Double.POSITIVE_INFINITY)); // sanity check + + assertFalse(Duration.ZERO.multiply(Double.POSITIVE_INFINITY).isIndefinite()); + assertTrue(Duration.ZERO.multiply(Double.POSITIVE_INFINITY).isUnknown()); + } + + @Test public void multiply_ONE_and_INDEFINITE_ResultsInIndefinite() { + //assertTrue(1.0 * Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY); // sanity check + assertEquals(new Double(Double.POSITIVE_INFINITY), new Double(1.0 * Double.POSITIVE_INFINITY)); // sanity check + + assertTrue(Duration.ONE.multiply(Double.POSITIVE_INFINITY).isIndefinite()); + assertFalse(Duration.ONE.multiply(Double.POSITIVE_INFINITY).isUnknown()); + } + + @Test public void multiply_INDEFINITE_and_INDEFINITE_ResultsInIndefinite() { + //assertTrue(Double.POSITIVE_INFINITY * Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY); // sanity check + assertEquals(new Double(Double.POSITIVE_INFINITY), new Double(Double.POSITIVE_INFINITY * Double.POSITIVE_INFINITY)); // sanity check + + assertTrue(Duration.INDEFINITE.multiply(Double.POSITIVE_INFINITY).isIndefinite()); + assertFalse(Duration.INDEFINITE.multiply(Double.POSITIVE_INFINITY).isUnknown()); + } + + @Test public void multiply_UNKNOWN_and_INDEFINITE_ResultsInUnknown() { + assertTrue(Double.isNaN(Double.NaN * Double.POSITIVE_INFINITY)); // sanity check + assertEquals(new Double(Double.NaN), new Double(Double.NaN * Double.POSITIVE_INFINITY)); // sanity check + + assertFalse(Duration.UNKNOWN.multiply(Double.POSITIVE_INFINITY).isIndefinite()); + assertTrue(Duration.UNKNOWN.multiply(Double.POSITIVE_INFINITY).isUnknown()); + } + + @Test public void multiply_ZERO_and_UNKNOWN_ResultsInUnknown() { + assertTrue(Double.isNaN(0 * Double.NaN)); // sanity check + assertEquals(new Double(Double.NaN), new Double(0.0 * Double.NaN)); // sanity check + + assertFalse(Duration.ZERO.multiply(Double.NaN).isIndefinite()); + assertTrue(Duration.ZERO.multiply(Double.NaN).isUnknown()); + } + + @Test public void multiply_ONE_and_UNKNOWN_ResultsInUnknown() { + assertTrue(Double.isNaN(1.0 * Double.NaN)); // sanity check + assertEquals(new Double(Double.NaN), new Double(1.0 * Double.NaN)); // sanity check + + assertFalse(Duration.ONE.multiply(Double.NaN).isIndefinite()); + assertTrue(Duration.ONE.multiply(Double.NaN).isUnknown()); + } + + @SuppressWarnings("deprecation") + @Test public void testMultiplyUsingMixedUnits() { + Duration a = Duration.minutes(10); + Duration b = Duration.seconds(30); + Duration expected = Duration.millis((1000.0 * 30) * (10 * 60 * 1000.0)); + assertEquals(expected, a.multiply(b)); + } + + /************************************************************************************ + * + * Tests for dividing two Durations + * + ***********************************************************************************/ + + @Test public void divide_doesNotModifyTheInputArguments() { + Duration a = new Duration(10); + Duration result = a.divide(2); + assertEquals(new Duration(5), result); + assertEquals(10, a.toMillis(), 0); + assertFalse(result.isIndefinite()); + assertFalse(result.isUnknown()); + } + + @Test public void divide_Ten_by_ZERO_ResultsIn_INDEFINITE() { + assertTrue(new Duration(10).divide(0).isIndefinite()); + assertFalse(new Duration(10).divide(0).isUnknown()); + } + + @Test public void divide_ZERO_by_Ten_ResultsIn_ZERO() { + assertSame(Duration.ZERO, Duration.ZERO.divide(10)); + } + + @Test public void divide_ONE_by_ONE_ResultsIn_ONE() { + assertEquals(Duration.ONE, Duration.ONE.divide(1)); + } + + @Test public void divide_ONE_Second_by_ONE_Milli_ResultsInOneSecond() { + assertEquals(new Duration(1000), Duration.seconds(1).divide(1)); + } + + @Test public void divide_ZERO_by_INDEFINITE_ResultsIn_ZERO() { + //assertTrue(0.0 / Double.POSITIVE_INFINITY == 0.0); // sanity check + assertEquals(new Double(0.0), new Double(0.0 / Double.POSITIVE_INFINITY)); // sanity check + + assertSame(Duration.ZERO, Duration.ZERO.divide(Double.POSITIVE_INFINITY)); + } + + @Test public void divide_ONE_by_INDEFINITE_ResultsIn_ZERO() { + //assertTrue(1.0 / Double.POSITIVE_INFINITY == 0.0); // sanity check + assertEquals(new Double(0.0), new Double(1.0 / Double.POSITIVE_INFINITY)); // sanity check + + assertSame(Duration.ZERO, Duration.ONE.divide(Double.POSITIVE_INFINITY)); + } + + @Test public void divide_INDEFINITE_by_INDEFINITE_ResultsInUnknown() { + assertTrue(Double.isNaN(Double.POSITIVE_INFINITY / Double.POSITIVE_INFINITY)); // sanity check + assertEquals(new Double(Double.NaN), new Double(Double.POSITIVE_INFINITY / Double.POSITIVE_INFINITY)); // sanity check + + assertFalse(Duration.INDEFINITE.divide(Double.POSITIVE_INFINITY).isIndefinite()); + assertTrue(Duration.INDEFINITE.divide(Double.POSITIVE_INFINITY).isUnknown()); + } + + @Test public void divide_UNKNOWN_by_INDEFINITE_ResultsInUnknown() { + assertTrue(Double.isNaN(Double.NaN / Double.POSITIVE_INFINITY)); // sanity check + assertEquals(new Double(Double.NaN), new Double(Double.NaN / Double.POSITIVE_INFINITY)); // sanity check + + assertFalse(Duration.UNKNOWN.divide(Double.POSITIVE_INFINITY).isIndefinite()); + assertTrue(Duration.UNKNOWN.divide(Double.POSITIVE_INFINITY).isUnknown()); + } + + @Test public void divide_ZERO_by_UNKNOWN_ResultsInUnknown() { + assertTrue(Double.isNaN(0.0 / Double.NaN)); // sanity check + assertEquals(new Double(Double.NaN), new Double(0.0 / Double.NaN)); // sanity check + + assertFalse(Duration.ZERO.divide(Double.NaN).isIndefinite()); + assertTrue(Duration.ZERO.divide(Double.NaN).isUnknown()); + } + + @Test public void divide_ONE_by_UNKNOWN_ResultsInUnknown() { + assertTrue(Double.isNaN(1.0 / Double.NaN)); // sanity check + assertEquals(new Double(Double.NaN), new Double(1.0 / Double.NaN)); // sanity check + + assertFalse(Duration.ONE.divide(Double.NaN).isIndefinite()); + assertTrue(Duration.ONE.divide(Double.NaN).isUnknown()); + } + + @SuppressWarnings("deprecation") + @Test public void testDivideUsingMixedUnits() { + Duration a = Duration.minutes(10); + Duration b = Duration.seconds(30); + Duration expected = Duration.millis((10 * 60 * 1000.0) / (1000.0 * 30)); + assertEquals(expected, a.divide(b)); + } + + /************************************************************************************ + * + * Tests for negating a Duration + * + ***********************************************************************************/ + + @Test public void negate_ZERO_ResultsIn_NegativeZeroOr_ZERO() { + assertEquals(new Duration(-0), Duration.ZERO.negate()); + assertSame(Duration.ZERO, Duration.ZERO.negate()); + } + + @Test public void negate_ONE_ResultsIn_NegativeOne() { + assertEquals(new Duration(-1), Duration.ONE.negate()); + } + + @Test public void negate_INDEFINITE_ResultsIn_NegativeInfinity() { + final Duration result = Duration.INDEFINITE.negate(); + assertEquals(new Duration(Double.NEGATIVE_INFINITY), result); + assertNotSame(Duration.INDEFINITE, result); + } + + @Test public void negate_UNKNOWN_ResultsIn_UNKNOWN() { + final Duration result = Duration.UNKNOWN.negate(); + assertSame(Duration.UNKNOWN, result); + assertFalse(result.isIndefinite()); + assertTrue(result.isUnknown()); + } + + @Test public void negate_NegativeResultsInPositive() { + assertEquals(new Duration(50), new Duration(-50).negate()); + } + + @Test public void negate_PositiveResultsInNegative() { + assertEquals(new Duration(-50), new Duration(50).negate()); + } + + /************************************************************************************ + * + * Tests for lessThan comparison with Duration + * + ***********************************************************************************/ + + @Test public void negativeInfinityIsLessThan_ZERO() { + assertTrue(Double.NEGATIVE_INFINITY < 0); + assertTrue(new Duration(Double.NEGATIVE_INFINITY).lessThan(Duration.ZERO)); + } + + @Test public void negativeInfinityIsNotLessThanNegativeInfinity() { + assertFalse(Double.NEGATIVE_INFINITY < Double.NEGATIVE_INFINITY); + Duration a = new Duration(Double.NEGATIVE_INFINITY); + assertFalse(a.lessThan(a)); + } + + @Test public void negativeNumberIsLessThanZero() { + assertTrue(-10 < 0.0); + assertTrue(new Duration(-10).lessThan(Duration.ZERO)); + } + + @Test public void ZERO_isLessThan_ONE() { + assertTrue(0 < 1); + assertTrue(Duration.ZERO.lessThan(Duration.ONE)); + } + + @Test public void ONE_isLessThan_INDEFINITE() { + assertTrue(0 < Double.POSITIVE_INFINITY); + assertTrue(Duration.ONE.lessThan(Duration.INDEFINITE)); + } + + @Test public void INDEFINITE_isNotLessThan_INDEFINITE() { + assertFalse(Double.POSITIVE_INFINITY < Double.POSITIVE_INFINITY); + assertFalse(Duration.INDEFINITE.lessThan(Duration.INDEFINITE)); + } + + @Test public void UNKNOWN_isNotLessThan_NegativeInfinity() { + assertFalse(Double.NaN < Double.NEGATIVE_INFINITY); + assertFalse(Duration.UNKNOWN.lessThan(new Duration(Double.NEGATIVE_INFINITY))); + } + + @Test public void UNKNOWN_isNotLessThan_ZERO() { + assertFalse(Double.NaN < 0.0); + assertFalse(Duration.UNKNOWN.lessThan(Duration.ZERO)); + } + + @Test public void UNKNOWN_isNotLessThan_ONE() { + assertFalse(Double.NaN < 1.0); + assertFalse(Duration.UNKNOWN.lessThan(Duration.ONE)); + } + + @Test public void UNKNOWN_isNotLessThan_INDEFINITE() { + assertFalse(Double.NaN < Double.POSITIVE_INFINITY); + assertFalse(Duration.UNKNOWN.lessThan(Duration.INDEFINITE)); + } + + @Test public void UNKNOWN_isNotLessThan_UNKNOWN() { + assertFalse(Double.NaN < Double.NaN); + assertFalse(Duration.UNKNOWN.lessThan(Duration.UNKNOWN)); + } + + /************************************************************************************ + * + * Tests for lessThanOrEqualTo comparison with Duration + * + ***********************************************************************************/ + + @Test public void negativeInfinityIsLessThanOrEqualTo_ZERO() { + assertTrue(Double.NEGATIVE_INFINITY <= 0); + assertTrue(new Duration(Double.NEGATIVE_INFINITY).lessThanOrEqualTo(Duration.ZERO)); + } + + @Test public void negativeInfinityIsLessThanOrEqualToNegativeInfinity() { + assertTrue(Double.NEGATIVE_INFINITY <= Double.NEGATIVE_INFINITY); + Duration a = new Duration(Double.NEGATIVE_INFINITY); + assertTrue(a.lessThanOrEqualTo(a)); + } + + @Test public void negativeNumberIsLessOrEqualToThanZero() { + assertTrue(-10 <= 0); + assertTrue(new Duration(-10).lessThanOrEqualTo(Duration.ZERO)); + } + + @Test public void ZERO_isLessThanOrEqualTo_ONE() { + assertTrue(0 <= 1); + assertTrue(Duration.ZERO.lessThanOrEqualTo(Duration.ONE)); + } + + @Test public void ONE_isLessThanOrEqualTo_INDEFINITE() { + assertTrue(1 <= Double.POSITIVE_INFINITY); + assertTrue(Duration.ONE.lessThanOrEqualTo(Duration.INDEFINITE)); + } + + @Test public void INDEFINITE_isLessThanOrEqualTo_INDEFINITE() { + assertTrue(Double.POSITIVE_INFINITY <= Double.POSITIVE_INFINITY); + assertTrue(Duration.INDEFINITE.lessThanOrEqualTo(Duration.INDEFINITE)); + } + + @Test public void UNKNOWN_isNotLessThanOrEqualTo_NegativeInfinity() { + assertFalse(Double.NaN <= Double.NEGATIVE_INFINITY); + assertFalse(Duration.UNKNOWN.lessThanOrEqualTo(new Duration(Double.NEGATIVE_INFINITY))); + } + + @Test public void UNKNOWN_isNotLessThanOrEqualTo_ZERO() { + assertFalse(Double.NaN <= 0.0); + assertFalse(Duration.UNKNOWN.lessThanOrEqualTo(Duration.ZERO)); + } + + @Test public void UNKNOWN_isNotLessThanOrEqualTo_ONE() { + assertFalse(Double.NaN <= 1.0); + assertFalse(Duration.UNKNOWN.lessThanOrEqualTo(Duration.ONE)); + } + + @Test public void UNKNOWN_isNotLessThanOrEqualTo_INDEFINITE() { + assertFalse(Double.NaN <= Double.POSITIVE_INFINITY); + assertFalse(Duration.UNKNOWN.lessThanOrEqualTo(Duration.INDEFINITE)); + } + + @Test public void UNKNOWN_isNotLessThanOrEqualTo_UNKNOWN() { + assertFalse(Double.NaN <= Double.NaN); + assertFalse(Duration.UNKNOWN.lessThanOrEqualTo(Duration.UNKNOWN)); + } + + /************************************************************************************ + * + * Tests for greaterThan comparison with Duration + * + ***********************************************************************************/ + + @Test public void ZERO_isGreaterThanNegativeInfinity() { + assertTrue(Duration.ZERO.greaterThan(new Duration(Double.NEGATIVE_INFINITY))); + } + + @Test public void negativeInfinityIsNotGreaterThanNegativeInfinity() { + Duration a = new Duration(Double.NEGATIVE_INFINITY); + assertFalse(a.greaterThan(a)); + } + + @Test public void ZERO_isGreaterThanNegativeNumber() { + assertTrue(Duration.ZERO.greaterThan(new Duration(-10))); + } + + @Test public void ONE_isGreaterThan_ZERO() { + assertTrue(Duration.ONE.greaterThan(Duration.ZERO)); + } + + @Test public void INDEFINITE_isGreaterThan_ONE() { + assertTrue(Duration.INDEFINITE.greaterThan(Duration.ONE)); + } + + @Test public void INDEFINITE_isNotGreaterThan_INDEFINITE() { + assertFalse(Duration.INDEFINITE.greaterThan(Duration.INDEFINITE)); + } + + @Test public void UNKNOWN_isNotGreaterThan_NegativeInfinity() { + assertFalse(Duration.UNKNOWN.greaterThan(new Duration(Double.NEGATIVE_INFINITY))); + } + + @Test public void UNKNOWN_isNotGreaterThan_ZERO() { + assertFalse(Duration.UNKNOWN.greaterThan(Duration.ZERO)); + } + + @Test public void UNKNOWN_isNotGreaterThan_ONE() { + assertFalse(Duration.UNKNOWN.greaterThan(Duration.ONE)); + } + + @Test public void UNKNOWN_isNotGreaterThan_INDEFINITE() { + assertFalse(Duration.UNKNOWN.greaterThan(Duration.INDEFINITE)); + } + + @Test public void UNKNOWN_isNotGreaterThan_UNKNOWN() { + assertFalse(Duration.UNKNOWN.greaterThan(Duration.UNKNOWN)); + } + + /************************************************************************************ + * + * Tests for greaterThanOrEqualTo comparison with Duration + * + ***********************************************************************************/ + + @Test public void ZERO_isGreaterThanOrEqualToNegativeInfinity() { + assertTrue(Duration.ZERO.greaterThanOrEqualTo(new Duration(Double.NEGATIVE_INFINITY))); + } + + @Test public void negativeInfinityIsGreaterThanOrEqualToNegativeInfinity() { + Duration a = new Duration(Double.NEGATIVE_INFINITY); + assertTrue(a.greaterThanOrEqualTo(a)); + } + + @Test public void ZERO_isGreaterThanOrEqualToNegativeNumber() { + assertTrue(Duration.ZERO.greaterThanOrEqualTo(new Duration(-10))); + } + + @Test public void ONE_isGreaterThanOrEqualTo_ZERO() { + assertTrue(Duration.ONE.greaterThanOrEqualTo(Duration.ZERO)); + } + + @Test public void INDEFINITE_isGreaterThanOrEqualTo_ONE() { + assertTrue(Duration.INDEFINITE.greaterThanOrEqualTo(Duration.ONE)); + } + + @Test public void INDEFINITE_isGreaterThanOrEqualTo_INDEFINITE() { + assertTrue(Duration.INDEFINITE.greaterThanOrEqualTo(Duration.INDEFINITE)); + } + + @Test public void UNKNOWN_isNotGreaterThanOrEqualTo_NegativeInfinity() { + assertFalse(Duration.UNKNOWN.greaterThanOrEqualTo(new Duration(Double.NEGATIVE_INFINITY))); + } + + @Test public void UNKNOWN_isNotGreaterThanOrEqualTo_ZERO() { + assertFalse(Duration.UNKNOWN.greaterThanOrEqualTo(Duration.ZERO)); + } + + @Test public void UNKNOWN_isNotGreaterThanOrEqualTo_ONE() { + assertFalse(Duration.UNKNOWN.greaterThanOrEqualTo(Duration.ONE)); + } + + @Test public void UNKNOWN_isNotGreaterThanOrEqualTo_INDEFINITE() { + assertFalse(Duration.UNKNOWN.greaterThanOrEqualTo(Duration.INDEFINITE)); + } + + @Test public void UNKNOWN_isNotGreaterThanOrEqualTo_UNKNOWN() { + assertFalse(Duration.UNKNOWN.greaterThanOrEqualTo(Duration.UNKNOWN)); + } + + /************************************************************************************ + * + * Tests for equality comparison with Duration + * + ***********************************************************************************/ + + @Test public void NegativeInfinityEqualsNegativeInfinity() { + assertEquals(new Duration(Double.NEGATIVE_INFINITY), new Duration(Double.NEGATIVE_INFINITY)); + } + + @Test public void ZERO_EqualsZero() { + assertEquals(Duration.ZERO, new Duration(0)); + } + + @Test public void ONE_EqualsOne() { + assertEquals(Duration.ONE, new Duration(1)); + } + + @Test public void INDEFINITE_Equals_PositiveInfinity() { + assertEquals(Duration.INDEFINITE, new Duration(Double.POSITIVE_INFINITY)); + } + + @Test public void UNKNOWN_DoesNotEqualNaN() { + assertFalse(Duration.UNKNOWN.equals(new Duration(Double.NaN))); + } + + @Test public void UNKNOWN_Equals_UNKNOWN() { + assertEquals(Duration.UNKNOWN, Duration.UNKNOWN); + } +} --- old/modules/base/src/test/java/javafx/util/DurationValueOfTest.java 2015-08-31 10:25:10.965216310 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util; - -import java.util.Arrays; -import java.util.Collection; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import static org.junit.Assert.assertEquals; - -/** - */ -@RunWith(Parameterized.class) -public class DurationValueOfTest { - @SuppressWarnings("rawtypes") - @Parameterized.Parameters public static Collection implementations() { - return Arrays.asList(new Object[][]{ - {"5ms", Duration.millis(5)}, - {"0ms", Duration.ZERO}, - {"25.5ms", Duration.millis(25.5)}, - {"-10ms", Duration.millis(-10)}, - {"5s", Duration.seconds(5)}, - {"0s", Duration.ZERO}, - {"25.5s", Duration.seconds(25.5)}, - {"-10s", Duration.seconds(-10)}, - {"5m", Duration.minutes(5)}, - {"0m", Duration.ZERO}, - {"25.5m", Duration.minutes(25.5)}, - {"-10m", Duration.minutes(-10)}, - {"5h", Duration.hours(5)}, - {"0h", Duration.ZERO}, - {"25.5h", Duration.hours(25.5)}, - {"-10h", Duration.hours(-10)} - }); - } - - private String asString; - private Duration expected; - - public DurationValueOfTest(String asString, Duration expected) { - this.asString = asString; - this.expected = expected; - } - - @Test public void testValueOf() { - Duration actual = Duration.valueOf(asString); - assertEquals(expected, actual); - } - - @Test(expected = IllegalArgumentException.class) - public void leadingSpaceResultsInException() { - Duration.valueOf(" " + asString); - } - - @Test(expected = IllegalArgumentException.class) - public void trailingSpaceResultsInException() { - Duration.valueOf(asString + " "); - } - - @Test(expected = IllegalArgumentException.class) - public void wrongCaseResultsInException() { - String mangled = asString.substring(0, asString.length()-1) + Character.toUpperCase(asString.charAt(asString.length()-1)); - Duration.valueOf(mangled); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/DurationValueOfTest.java 2015-08-31 10:25:10.825216312 -0400 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util; + +import java.util.Arrays; +import java.util.Collection; +import javafx.util.Duration; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import static org.junit.Assert.assertEquals; + +/** + */ +@RunWith(Parameterized.class) +public class DurationValueOfTest { + @SuppressWarnings("rawtypes") + @Parameterized.Parameters public static Collection implementations() { + return Arrays.asList(new Object[][]{ + {"5ms", Duration.millis(5)}, + {"0ms", Duration.ZERO}, + {"25.5ms", Duration.millis(25.5)}, + {"-10ms", Duration.millis(-10)}, + {"5s", Duration.seconds(5)}, + {"0s", Duration.ZERO}, + {"25.5s", Duration.seconds(25.5)}, + {"-10s", Duration.seconds(-10)}, + {"5m", Duration.minutes(5)}, + {"0m", Duration.ZERO}, + {"25.5m", Duration.minutes(25.5)}, + {"-10m", Duration.minutes(-10)}, + {"5h", Duration.hours(5)}, + {"0h", Duration.ZERO}, + {"25.5h", Duration.hours(25.5)}, + {"-10h", Duration.hours(-10)} + }); + } + + private String asString; + private Duration expected; + + public DurationValueOfTest(String asString, Duration expected) { + this.asString = asString; + this.expected = expected; + } + + @Test public void testValueOf() { + Duration actual = Duration.valueOf(asString); + assertEquals(expected, actual); + } + + @Test(expected = IllegalArgumentException.class) + public void leadingSpaceResultsInException() { + Duration.valueOf(" " + asString); + } + + @Test(expected = IllegalArgumentException.class) + public void trailingSpaceResultsInException() { + Duration.valueOf(asString + " "); + } + + @Test(expected = IllegalArgumentException.class) + public void wrongCaseResultsInException() { + String mangled = asString.substring(0, asString.length()-1) + Character.toUpperCase(asString.charAt(asString.length()-1)); + Duration.valueOf(mangled); + } +} --- old/modules/base/src/test/java/javafx/util/converter/BigDecimalStringConverterTest.java 2015-08-31 10:25:11.649216303 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Collection; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import javafx.util.StringConverter; - -import org.junit.Before; -import org.junit.Test; -import org.junit.Ignore; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - */ -public class BigDecimalStringConverterTest { - private BigDecimalStringConverter converter; - - private final BigDecimal bigDecimal = new BigDecimal(BigInteger.TEN); - - @Before public void setup() { - converter = new BigDecimalStringConverter(); - } - - @Test public void fromString_testValidStringInput() { - assertEquals(bigDecimal, converter.fromString("10")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace() { - assertEquals(bigDecimal, converter.fromString(" 10 ")); - } - - @Test public void toString_testStringInput() { - assertEquals("10", converter.toString(bigDecimal)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/BigDecimalStringConverterTest.java 2015-08-31 10:25:11.437216305 -0400 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collection; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import javafx.util.StringConverter; +import javafx.util.converter.BigDecimalStringConverter; + +import org.junit.Before; +import org.junit.Test; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + */ +public class BigDecimalStringConverterTest { + private BigDecimalStringConverter converter; + + private final BigDecimal bigDecimal = new BigDecimal(BigInteger.TEN); + + @Before public void setup() { + converter = new BigDecimalStringConverter(); + } + + @Test public void fromString_testValidStringInput() { + assertEquals(bigDecimal, converter.fromString("10")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace() { + assertEquals(bigDecimal, converter.fromString(" 10 ")); + } + + @Test public void toString_testStringInput() { + assertEquals("10", converter.toString(bigDecimal)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/BigIntegerStringConverterTest.java 2015-08-31 10:25:12.317216295 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.math.BigInteger; -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class BigIntegerStringConverterTest { - private BigIntegerStringConverter converter; - - @Before public void setup() { - converter = new BigIntegerStringConverter(); - } - - @Test public void fromString_testValidStringInput() { - assertEquals(BigInteger.TEN, converter.fromString("10")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace() { - assertEquals(BigInteger.TEN, converter.fromString(" 10 ")); - } - - @Test public void toString_testStringInput() { - assertEquals("10", converter.toString(BigInteger.TEN)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/BigIntegerStringConverterTest.java 2015-08-31 10:25:12.109216297 -0400 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.math.BigInteger; +import javafx.util.converter.BigIntegerStringConverter; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class BigIntegerStringConverterTest { + private BigIntegerStringConverter converter; + + @Before public void setup() { + converter = new BigIntegerStringConverter(); + } + + @Test public void fromString_testValidStringInput() { + assertEquals(BigInteger.TEN, converter.fromString("10")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace() { + assertEquals(BigInteger.TEN, converter.fromString(" 10 ")); + } + + @Test public void toString_testStringInput() { + assertEquals("10", converter.toString(BigInteger.TEN)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/BooleanStringConverterTest.java 2015-08-31 10:25:12.997216287 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.math.BigInteger; -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class BooleanStringConverterTest { - private BooleanStringConverter converter; - - @Before public void setup() { - converter = new BooleanStringConverter(); - } - - @Test public void fromString_testValidStringInput_lowercase_true() { - assertEquals(Boolean.TRUE, converter.fromString("true")); - } - - @Test public void fromString_testValidStringInput_uppercase_true() { - assertEquals(Boolean.TRUE, converter.fromString("TRUE")); - } - - @Test public void fromString_testValidStringInput_mixedCase_true() { - assertEquals(Boolean.TRUE, converter.fromString("tRUe")); - } - - @Test public void fromString_testValidStringInput_lowercase_false() { - assertEquals(Boolean.FALSE, converter.fromString("false")); - } - - @Test public void fromString_testValidStringInput_uppercase_false() { - assertEquals(Boolean.FALSE, converter.fromString("FALSE")); - } - - @Test public void fromString_testValidStringInput_mixedCase_false() { - assertEquals(Boolean.FALSE, converter.fromString("fALsE")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace_true() { - assertEquals(Boolean.TRUE, converter.fromString(" true ")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace_false() { - assertEquals(Boolean.FALSE, converter.fromString(" false ")); - } - - @Test public void toString_true() { - assertEquals("true", converter.toString(true)); - } - - @Test public void toString_false() { - assertEquals("false", converter.toString(false)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/BooleanStringConverterTest.java 2015-08-31 10:25:12.861216289 -0400 @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.math.BigInteger; +import javafx.util.converter.BooleanStringConverter; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class BooleanStringConverterTest { + private BooleanStringConverter converter; + + @Before public void setup() { + converter = new BooleanStringConverter(); + } + + @Test public void fromString_testValidStringInput_lowercase_true() { + assertEquals(Boolean.TRUE, converter.fromString("true")); + } + + @Test public void fromString_testValidStringInput_uppercase_true() { + assertEquals(Boolean.TRUE, converter.fromString("TRUE")); + } + + @Test public void fromString_testValidStringInput_mixedCase_true() { + assertEquals(Boolean.TRUE, converter.fromString("tRUe")); + } + + @Test public void fromString_testValidStringInput_lowercase_false() { + assertEquals(Boolean.FALSE, converter.fromString("false")); + } + + @Test public void fromString_testValidStringInput_uppercase_false() { + assertEquals(Boolean.FALSE, converter.fromString("FALSE")); + } + + @Test public void fromString_testValidStringInput_mixedCase_false() { + assertEquals(Boolean.FALSE, converter.fromString("fALsE")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace_true() { + assertEquals(Boolean.TRUE, converter.fromString(" true ")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace_false() { + assertEquals(Boolean.FALSE, converter.fromString(" false ")); + } + + @Test public void toString_true() { + assertEquals("true", converter.toString(true)); + } + + @Test public void toString_false() { + assertEquals("false", converter.toString(false)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/ByteStringConverterTest.java 2015-08-31 10:25:13.669216280 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class ByteStringConverterTest { - private ByteStringConverter converter; - - private final byte byteValue_10 = 10; - - @Before public void setup() { - converter = new ByteStringConverter(); - } - - @Test public void fromString_testValidStringInput() { - assertEquals((Object)byteValue_10, converter.fromString("10")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace() { - assertEquals((Object)byteValue_10, converter.fromString(" 10 ")); - } - - @Test public void toString_testStringInput() { - assertEquals("10", converter.toString(byteValue_10)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/ByteStringConverterTest.java 2015-08-31 10:25:13.537216281 -0400 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import javafx.util.converter.ByteStringConverter; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class ByteStringConverterTest { + private ByteStringConverter converter; + + private final byte byteValue_10 = 10; + + @Before public void setup() { + converter = new ByteStringConverter(); + } + + @Test public void fromString_testValidStringInput() { + assertEquals((Object)byteValue_10, converter.fromString("10")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace() { + assertEquals((Object)byteValue_10, converter.fromString(" 10 ")); + } + + @Test public void toString_testStringInput() { + assertEquals("10", converter.toString(byteValue_10)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/CharacterStringConverterTest.java 2015-08-31 10:25:14.265216273 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class CharacterStringConverterTest { - private CharacterStringConverter converter; - - private final char char_c = 'c'; - private final char char_C = 'C'; - - @Before public void setup() { - converter = new CharacterStringConverter(); - } - - @Test public void fromString_testValidStringInput_lowercase() { - assertEquals((Object)char_c, converter.fromString("c")); - } - - @Test public void fromString_testValidStringInput_uppercase() { - assertEquals((Object)char_C, converter.fromString("C")); - } - - @Test public void fromString_testValidStringInput_differentCase_one() { - assertNotSame((Object)char_C, converter.fromString("c")); - } - - @Test public void fromString_testValidStringInput_differentCase_two() { - assertNotSame((Object)char_c, converter.fromString("C")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace_lowercase() { - assertEquals((Object)char_c, converter.fromString(" c ")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace_uppercase() { - assertEquals((Object)char_C, converter.fromString(" C ")); - } - - @Test public void toString_lowercase() { - assertEquals("c", converter.toString(char_c)); - } - - @Test public void toString_uppercase() { - assertEquals("C", converter.toString(char_C)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/CharacterStringConverterTest.java 2015-08-31 10:25:14.133216275 -0400 @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import javafx.util.converter.CharacterStringConverter; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class CharacterStringConverterTest { + private CharacterStringConverter converter; + + private final char char_c = 'c'; + private final char char_C = 'C'; + + @Before public void setup() { + converter = new CharacterStringConverter(); + } + + @Test public void fromString_testValidStringInput_lowercase() { + assertEquals((Object)char_c, converter.fromString("c")); + } + + @Test public void fromString_testValidStringInput_uppercase() { + assertEquals((Object)char_C, converter.fromString("C")); + } + + @Test public void fromString_testValidStringInput_differentCase_one() { + assertNotSame((Object)char_C, converter.fromString("c")); + } + + @Test public void fromString_testValidStringInput_differentCase_two() { + assertNotSame((Object)char_c, converter.fromString("C")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace_lowercase() { + assertEquals((Object)char_c, converter.fromString(" c ")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace_uppercase() { + assertEquals((Object)char_C, converter.fromString(" C ")); + } + + @Test public void toString_lowercase() { + assertEquals("c", converter.toString(char_c)); + } + + @Test public void toString_uppercase() { + assertEquals("C", converter.toString(char_C)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/CurrencyStringConverterTest.java 2015-08-31 10:25:15.053216264 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.Currency; -import java.util.Locale; -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class CurrencyStringConverterTest { - private CurrencyStringConverter converter; - - @Before public void setup() { - converter = new CurrencyStringConverter(Locale.US); - } - - /********************************************************************* - * Test constructors - ********************************************************************/ - - @Test public void testDefaultConstructor() { - CurrencyStringConverter c = new CurrencyStringConverter(); - assertEquals(Locale.getDefault(), c.locale); - assertNull(c.pattern); - assertNull(c.numberFormat); - } - - @Test public void testConstructor_locale() { - CurrencyStringConverter c = new CurrencyStringConverter(Locale.CANADA); - assertEquals(Locale.CANADA, c.locale); - assertNull(c.pattern); - assertNull(c.numberFormat); - } - - @Test public void testConstructor_pattern() { - CurrencyStringConverter c = new CurrencyStringConverter("#,##,###,####"); - assertEquals(Locale.getDefault(), c.locale); - assertEquals("#,##,###,####", c.pattern); - assertNull(c.numberFormat); - } - - @Test public void testConstructor_locale_pattern() { - CurrencyStringConverter c = new CurrencyStringConverter(Locale.CANADA, "#,##,###,####"); - assertEquals(Locale.CANADA, c.locale); - assertEquals("#,##,###,####", c.pattern); - assertNull(c.numberFormat); - } - - @Test public void testConstructor_numberFormat() { - NumberFormat format = NumberFormat.getCurrencyInstance(Locale.JAPAN); - CurrencyStringConverter c = new CurrencyStringConverter(format); - assertNull(c.locale); - assertNull(c.pattern); - assertEquals(format, c.numberFormat); - } - - - /********************************************************************* - * Test methods - ********************************************************************/ - - @Test public void getNumberFormat_default() { - assertNotNull(converter.getNumberFormat()); - } - - @Test public void getNumberFormat_nonNullPattern() { - converter = new CurrencyStringConverter("#,##,###,####"); - assertTrue(converter.getNumberFormat() instanceof DecimalFormat); - } - - @Test public void getNumberFormat_nonNullNumberFormat() { - NumberFormat nf = NumberFormat.getCurrencyInstance(); - converter = new CurrencyStringConverter(nf); - assertEquals(nf, converter.getNumberFormat()); - } - - - /********************************************************************* - * Test toString / fromString methods - ********************************************************************/ - - @Test public void fromString_testValidStringInput() { - assertEquals(10.32, converter.fromString("$10.32")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace() { - assertEquals(10.32, converter.fromString(" $10.32 ")); - } - - @Test public void toString_validInput() { - assertEquals("$10.32", converter.toString(10.32)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/CurrencyStringConverterTest.java 2015-08-31 10:25:14.841216267 -0400 @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.Currency; +import java.util.Locale; +import javafx.util.converter.LocalTimeStringConverterShim; +import javafx.util.converter.CurrencyStringConverter; +import javafx.util.converter.NumberStringConverterShim; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class CurrencyStringConverterTest { + private CurrencyStringConverter converter; + + @Before public void setup() { + converter = new CurrencyStringConverter(Locale.US); + } + + /********************************************************************* + * Test constructors + ********************************************************************/ + + @Test public void testDefaultConstructor() { + CurrencyStringConverter c = new CurrencyStringConverter(); + assertEquals(Locale.getDefault(), NumberStringConverterShim.getLocale(c)); + assertNull(NumberStringConverterShim.getPattern(c)); + assertNull(NumberStringConverterShim.getNumberFormatVar(c)); + } + + @Test public void testConstructor_locale() { + CurrencyStringConverter c = new CurrencyStringConverter(Locale.CANADA); + assertEquals(Locale.CANADA, NumberStringConverterShim.getLocale(c)); + assertNull(NumberStringConverterShim.getPattern(c)); + assertNull(NumberStringConverterShim.getNumberFormatVar(c)); + } + + @Test public void testConstructor_pattern() { + CurrencyStringConverter c = new CurrencyStringConverter("#,##,###,####"); + assertEquals(Locale.getDefault(), NumberStringConverterShim.getLocale(c)); + assertEquals("#,##,###,####", NumberStringConverterShim.getPattern(c)); + assertNull(NumberStringConverterShim.getNumberFormatVar(c)); + } + + @Test public void testConstructor_locale_pattern() { + CurrencyStringConverter c = new CurrencyStringConverter(Locale.CANADA, "#,##,###,####"); + assertEquals(Locale.CANADA, NumberStringConverterShim.getLocale(c)); + assertEquals("#,##,###,####", NumberStringConverterShim.getPattern(c)); + assertNull(NumberStringConverterShim.getNumberFormatVar(c)); + } + + @Test public void testConstructor_numberFormat() { + NumberFormat format = NumberFormat.getCurrencyInstance(Locale.JAPAN); + CurrencyStringConverter c = new CurrencyStringConverter(format); + assertNull(NumberStringConverterShim.getLocale(c)); + assertNull(NumberStringConverterShim.getPattern(c)); + assertEquals(format, NumberStringConverterShim.getNumberFormatVar(c)); + } + + + /********************************************************************* + * Test methods + ********************************************************************/ + + @Test public void getNumberFormat_default() { + assertNotNull(NumberStringConverterShim.getNumberFormat(converter)); + } + + @Test public void getNumberFormat_nonNullPattern() { + converter = new CurrencyStringConverter("#,##,###,####"); + assertTrue( + NumberStringConverterShim.getNumberFormat(converter) + instanceof DecimalFormat); + } + + @Test public void getNumberFormat_nonNullNumberFormat() { + NumberFormat nf = NumberFormat.getCurrencyInstance(); + converter = new CurrencyStringConverter(nf); + assertEquals(nf, NumberStringConverterShim.getNumberFormat(converter)); + } + + + /********************************************************************* + * Test toString / fromString methods + ********************************************************************/ + + @Test public void fromString_testValidStringInput() { + assertEquals(10.32, converter.fromString("$10.32")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace() { + assertEquals(10.32, converter.fromString(" $10.32 ")); + } + + @Test public void toString_validInput() { + assertEquals("$10.32", converter.toString(10.32)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/DateStringConverterTest.java 2015-08-31 10:25:15.805216256 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; -import org.junit.Ignore; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - */ -@RunWith(Parameterized.class) -public class DateStringConverterTest { - private static final Date VALID_DATE; - - static { - TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - Calendar c = Calendar.getInstance(); - c.set(Calendar.YEAR, 1985); - c.set(Calendar.MONTH, Calendar.JANUARY); - c.set(Calendar.DAY_OF_MONTH, 12); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - c.set(Calendar.MILLISECOND, 0); - VALID_DATE = c.getTime(); - } - - @Parameterized.Parameters public static Collection implementations() { - return Arrays.asList(new Object[][] { - { new DateStringConverter(), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, - VALID_DATE, null, null }, - - { new DateStringConverter(DateFormat.SHORT), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.SHORT, - VALID_DATE, null, null }, - - { new DateStringConverter(Locale.UK), - Locale.UK, DateFormat.DEFAULT, - VALID_DATE, null, null }, - - { new DateStringConverter(Locale.UK, DateFormat.SHORT), - Locale.UK, DateFormat.SHORT, - VALID_DATE, null, null }, - - { new DateStringConverter("dd MM yyyy"), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, - VALID_DATE, "dd MM yyyy", null }, - - { new DateStringConverter(DateFormat.getDateInstance(DateFormat.LONG)), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, - VALID_DATE, null, DateFormat.getDateInstance(DateFormat.LONG) }, - }); - } - - private DateStringConverter converter; - private Locale locale; - private int dateStyle; - private String pattern; - private DateFormat dateFormat; - private Date validDate; - private DateFormat validFormatter; - - public DateStringConverterTest(DateStringConverter converter, Locale locale, int dateStyle, Date validDate, String pattern, DateFormat dateFormat) { - this.converter = converter; - this.locale = locale; - this.dateStyle = dateStyle; - this.validDate = validDate; - this.pattern = pattern; - this.dateFormat = dateFormat; - - if (dateFormat != null) { - validFormatter = dateFormat; - } else if (pattern != null) { - validFormatter = new SimpleDateFormat(pattern); - } else { - validFormatter = DateFormat.getDateInstance(dateStyle, locale); - } - } - - @Before public void setup() { - } - - /********************************************************************* - * Test constructors - ********************************************************************/ - - @Test public void testConstructor() { - assertEquals(locale, converter.locale); - assertEquals(dateStyle, converter.dateStyle); - assertEquals(pattern, converter.pattern); - assertEquals(dateFormat, converter.dateFormat); - } - - - /********************************************************************* - * Test methods - ********************************************************************/ - - @Test public void getDateFormat() { - assertNotNull(converter.getDateFormat()); - } - - @Test public void getDateFormat_nonNullPattern() { - converter = new DateStringConverter("yyyy"); - assertTrue(converter.getDateFormat() instanceof SimpleDateFormat); - } - - /********************************************************************* - * Test toString / fromString methods - ********************************************************************/ - - @Test public void fromString_testValidInput() { - String input = validFormatter.format(validDate); - assertEquals("Input = "+input, validDate, converter.fromString(input)); - } - - @Test public void fromString_testValidInputWithWhiteSpace() { - String input = validFormatter.format(validDate); - assertEquals("Input = "+input, validDate, converter.fromString(" " + input + " ")); - } - - @Test(expected=RuntimeException.class) - public void fromString_testInvalidInput() { - converter.fromString("abcdefg"); - } - - @Test public void toString_validOutput() { - assertEquals(validFormatter.format(validDate), converter.toString(validDate)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/DateStringConverterTest.java 2015-08-31 10:25:15.597216258 -0400 @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; +import javafx.util.converter.LocalTimeStringConverterShim; +import javafx.util.converter.DateStringConverter; +import javafx.util.converter.DateTimeStringConverterShim; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + */ +@RunWith(Parameterized.class) +public class DateStringConverterTest { + private static final Date VALID_DATE; + + static { + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + Calendar c = Calendar.getInstance(); + c.set(Calendar.YEAR, 1985); + c.set(Calendar.MONTH, Calendar.JANUARY); + c.set(Calendar.DAY_OF_MONTH, 12); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + c.set(Calendar.MILLISECOND, 0); + VALID_DATE = c.getTime(); + } + + @Parameterized.Parameters public static Collection implementations() { + return Arrays.asList(new Object[][] { + { new DateStringConverter(), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, + VALID_DATE, null, null }, + + { new DateStringConverter(DateFormat.SHORT), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.SHORT, + VALID_DATE, null, null }, + + { new DateStringConverter(Locale.UK), + Locale.UK, DateFormat.DEFAULT, + VALID_DATE, null, null }, + + { new DateStringConverter(Locale.UK, DateFormat.SHORT), + Locale.UK, DateFormat.SHORT, + VALID_DATE, null, null }, + + { new DateStringConverter("dd MM yyyy"), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, + VALID_DATE, "dd MM yyyy", null }, + + { new DateStringConverter(DateFormat.getDateInstance(DateFormat.LONG)), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, + VALID_DATE, null, DateFormat.getDateInstance(DateFormat.LONG) }, + }); + } + + private DateStringConverter converter; + private Locale locale; + private int dateStyle; + private String pattern; + private DateFormat dateFormat; + private Date validDate; + private DateFormat validFormatter; + + public DateStringConverterTest(DateStringConverter converter, Locale locale, int dateStyle, Date validDate, String pattern, DateFormat dateFormat) { + this.converter = converter; + this.locale = locale; + this.dateStyle = dateStyle; + this.validDate = validDate; + this.pattern = pattern; + this.dateFormat = dateFormat; + + if (dateFormat != null) { + validFormatter = dateFormat; + } else if (pattern != null) { + validFormatter = new SimpleDateFormat(pattern); + } else { + validFormatter = DateFormat.getDateInstance(dateStyle, locale); + } + } + + @Before public void setup() { + } + + /********************************************************************* + * Test constructors + ********************************************************************/ + + @Test public void testConstructor() { + assertEquals(locale, DateTimeStringConverterShim.getLocale(converter)); + assertEquals(dateStyle, DateTimeStringConverterShim.getDateStyle(converter)); + assertEquals(pattern, DateTimeStringConverterShim.getPattern(converter)); + assertEquals(dateFormat, DateTimeStringConverterShim.getDateFormatVar(converter)); + } + + + /********************************************************************* + * Test methods + ********************************************************************/ + + @Test public void getDateFormat() { + assertNotNull(DateTimeStringConverterShim.getDateFormat(converter)); + } + + @Test public void getDateFormat_nonNullPattern() { + converter = new DateStringConverter("yyyy"); + assertTrue( + DateTimeStringConverterShim.getDateFormat(converter) + instanceof SimpleDateFormat); + } + + /********************************************************************* + * Test toString / fromString methods + ********************************************************************/ + + @Test public void fromString_testValidInput() { + String input = validFormatter.format(validDate); + assertEquals("Input = "+input, validDate, converter.fromString(input)); + } + + @Test public void fromString_testValidInputWithWhiteSpace() { + String input = validFormatter.format(validDate); + assertEquals("Input = "+input, validDate, converter.fromString(" " + input + " ")); + } + + @Test(expected=RuntimeException.class) + public void fromString_testInvalidInput() { + converter.fromString("abcdefg"); + } + + @Test public void toString_validOutput() { + assertEquals(validFormatter.format(validDate), converter.toString(validDate)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/DateTimeStringConverterTest.java 2015-08-31 10:25:16.533216248 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; -import org.junit.Ignore; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - */ -@RunWith(Parameterized.class) -public class DateTimeStringConverterTest { - private static final Date VALID_DATE_WITH_SECONDS; - private static final Date VALID_DATE_WITHOUT_SECONDS; - - static { - TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - Calendar c = Calendar.getInstance(); - c.set(Calendar.YEAR, 1985); - c.set(Calendar.MONTH, Calendar.JANUARY); - c.set(Calendar.DAY_OF_MONTH, 12); - c.set(Calendar.HOUR_OF_DAY, 12); - c.set(Calendar.MINUTE, 34); - c.set(Calendar.SECOND, 56); - c.set(Calendar.MILLISECOND, 0); - VALID_DATE_WITH_SECONDS = c.getTime(); - c.set(Calendar.SECOND, 0); - VALID_DATE_WITHOUT_SECONDS = c.getTime(); - } - - @Parameterized.Parameters public static Collection implementations() { - return Arrays.asList(new Object[][] { - { new DateTimeStringConverter(), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, DateFormat.DEFAULT, - VALID_DATE_WITH_SECONDS, null, null }, - - { new DateTimeStringConverter(DateFormat.SHORT, DateFormat.SHORT), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.SHORT, DateFormat.SHORT, - VALID_DATE_WITHOUT_SECONDS, null, null }, - - { new DateTimeStringConverter(Locale.UK), - Locale.UK, DateFormat.DEFAULT, DateFormat.DEFAULT, - VALID_DATE_WITH_SECONDS, null, null }, - - { new DateTimeStringConverter(Locale.UK, DateFormat.SHORT, DateFormat.SHORT), - Locale.UK, DateFormat.SHORT, DateFormat.SHORT, - VALID_DATE_WITHOUT_SECONDS, null, null }, - - { new DateTimeStringConverter("dd MM yyyy HH mm ss"), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, DateFormat.DEFAULT, - VALID_DATE_WITH_SECONDS, "dd MM yyyy HH mm ss", null }, - - { new DateTimeStringConverter(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL)), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, DateFormat.DEFAULT, - VALID_DATE_WITH_SECONDS, null, DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL) }, - }); - } - - private DateTimeStringConverter converter; - private Locale locale; - private int dateStyle; - private int timeStyle; - private String pattern; - private DateFormat dateFormat; - private Date validDate; - private DateFormat validFormatter; - - public DateTimeStringConverterTest(DateTimeStringConverter converter, Locale locale, int dateStyle, int timeStyle, Date validDate, String pattern, DateFormat dateFormat) { - this.converter = converter; - this.locale = locale; - this.dateStyle = dateStyle; - this.timeStyle = timeStyle; - this.validDate = validDate; - this.pattern = pattern; - this.dateFormat = dateFormat; - - if (dateFormat != null) { - validFormatter = dateFormat; - } else if (pattern != null) { - validFormatter = new SimpleDateFormat(pattern); - } else { - validFormatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale); - } - } - - @Before public void setup() { - } - - /********************************************************************* - * Test constructors - ********************************************************************/ - - @Test public void testConstructor() { - assertEquals(locale, converter.locale); - assertEquals(dateStyle, converter.dateStyle); - assertEquals(timeStyle, converter.timeStyle); - assertEquals(pattern, converter.pattern); - assertEquals(dateFormat, converter.dateFormat); - } - - /********************************************************************* - * Test methods - ********************************************************************/ - - @Test public void getDateFormat_default() { - assertNotNull(converter.getDateFormat()); - } - - @Test public void getDateFormat_nonNullPattern() { - converter = new DateTimeStringConverter("yyyy/MM/dd HH:mm:ss"); - assertTrue(converter.getDateFormat() instanceof SimpleDateFormat); - } - - /********************************************************************* - * Test toString / fromString methods - ********************************************************************/ - - @Test public void fromString_testValidInput() { - String input = validFormatter.format(validDate); - assertEquals("Input = "+input, validDate, converter.fromString(input)); - } - - @Test public void fromString_testValidInputWithWhiteSpace() { - String input = validFormatter.format(validDate); - assertEquals("Input = "+input, validDate, converter.fromString(" " + input + " ")); - } - - @Test(expected=RuntimeException.class) - public void fromString_testInvalidInput() { - converter.fromString("abcdefg"); - } - - @Test public void toString_validOutput() { - assertEquals(validFormatter.format(validDate), converter.toString(validDate)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/DateTimeStringConverterTest.java 2015-08-31 10:25:16.329216250 -0400 @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; +import javafx.util.converter.LocalTimeStringConverterShim; +import javafx.util.converter.DateTimeStringConverter; +import javafx.util.converter.DateTimeStringConverterShim; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + */ +@RunWith(Parameterized.class) +public class DateTimeStringConverterTest { + private static final Date VALID_DATE_WITH_SECONDS; + private static final Date VALID_DATE_WITHOUT_SECONDS; + + static { + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + Calendar c = Calendar.getInstance(); + c.set(Calendar.YEAR, 1985); + c.set(Calendar.MONTH, Calendar.JANUARY); + c.set(Calendar.DAY_OF_MONTH, 12); + c.set(Calendar.HOUR_OF_DAY, 12); + c.set(Calendar.MINUTE, 34); + c.set(Calendar.SECOND, 56); + c.set(Calendar.MILLISECOND, 0); + VALID_DATE_WITH_SECONDS = c.getTime(); + c.set(Calendar.SECOND, 0); + VALID_DATE_WITHOUT_SECONDS = c.getTime(); + } + + @Parameterized.Parameters public static Collection implementations() { + return Arrays.asList(new Object[][] { + { new DateTimeStringConverter(), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, DateFormat.DEFAULT, + VALID_DATE_WITH_SECONDS, null, null }, + + { new DateTimeStringConverter(DateFormat.SHORT, DateFormat.SHORT), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.SHORT, DateFormat.SHORT, + VALID_DATE_WITHOUT_SECONDS, null, null }, + + { new DateTimeStringConverter(Locale.UK), + Locale.UK, DateFormat.DEFAULT, DateFormat.DEFAULT, + VALID_DATE_WITH_SECONDS, null, null }, + + { new DateTimeStringConverter(Locale.UK, DateFormat.SHORT, DateFormat.SHORT), + Locale.UK, DateFormat.SHORT, DateFormat.SHORT, + VALID_DATE_WITHOUT_SECONDS, null, null }, + + { new DateTimeStringConverter("dd MM yyyy HH mm ss"), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, DateFormat.DEFAULT, + VALID_DATE_WITH_SECONDS, "dd MM yyyy HH mm ss", null }, + + { new DateTimeStringConverter(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL)), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, DateFormat.DEFAULT, + VALID_DATE_WITH_SECONDS, null, DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL) }, + }); + } + + private DateTimeStringConverter converter; + private Locale locale; + private int dateStyle; + private int timeStyle; + private String pattern; + private DateFormat dateFormat; + private Date validDate; + private DateFormat validFormatter; + + public DateTimeStringConverterTest(DateTimeStringConverter converter, Locale locale, int dateStyle, int timeStyle, Date validDate, String pattern, DateFormat dateFormat) { + this.converter = converter; + this.locale = locale; + this.dateStyle = dateStyle; + this.timeStyle = timeStyle; + this.validDate = validDate; + this.pattern = pattern; + this.dateFormat = dateFormat; + + if (dateFormat != null) { + validFormatter = dateFormat; + } else if (pattern != null) { + validFormatter = new SimpleDateFormat(pattern); + } else { + validFormatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale); + } + } + + @Before public void setup() { + } + + /********************************************************************* + * Test constructors + ********************************************************************/ + + @Test public void testConstructor() { + assertEquals(locale, DateTimeStringConverterShim.getLocale(converter)); + assertEquals(dateStyle, DateTimeStringConverterShim.getDateStyle(converter)); + assertEquals(pattern, DateTimeStringConverterShim.getPattern(converter)); + assertEquals(dateFormat, DateTimeStringConverterShim.getDateFormatVar(converter)); + assertEquals(timeStyle, DateTimeStringConverterShim.getTimeStyle(converter)); + } + + /********************************************************************* + * Test methods + ********************************************************************/ + + @Test public void getDateFormat_default() { + assertNotNull(DateTimeStringConverterShim.getDateFormat(converter)); + } + + @Test public void getDateFormat_nonNullPattern() { + converter = new DateTimeStringConverter("yyyy/MM/dd HH:mm:ss"); + assertTrue(DateTimeStringConverterShim.getDateFormat(converter) + instanceof SimpleDateFormat); + } + + /********************************************************************* + * Test toString / fromString methods + ********************************************************************/ + + @Test public void fromString_testValidInput() { + String input = validFormatter.format(validDate); + assertEquals("Input = "+input, validDate, converter.fromString(input)); + } + + @Test public void fromString_testValidInputWithWhiteSpace() { + String input = validFormatter.format(validDate); + assertEquals("Input = "+input, validDate, converter.fromString(" " + input + " ")); + } + + @Test(expected=RuntimeException.class) + public void fromString_testInvalidInput() { + converter.fromString("abcdefg"); + } + + @Test public void toString_validOutput() { + assertEquals(validFormatter.format(validDate), converter.toString(validDate)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/DefaultStringConverterTest.java 2015-08-31 10:25:17.221216240 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.util.Arrays; -import java.util.Collection; -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class DefaultStringConverterTest { - private DefaultStringConverter converter; - - @Before public void setup() { - converter = new DefaultStringConverter(); - } - - @Test public void fromString_testValidStringInput() { - assertEquals("string", converter.fromString("string")); - } - - @Test public void fromString_testEmptytringInput() { - assertEquals("", converter.fromString("")); - } - - @Test public void toString_testValidStringInput() { - assertEquals("string", converter.toString("string")); - } - - @Test public void toString_testEmptyStringInput() { - assertEquals("", converter.toString("")); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/DefaultStringConverterTest.java 2015-08-31 10:25:17.013216242 -0400 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.util.Arrays; +import java.util.Collection; +import javafx.util.converter.DefaultStringConverter; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class DefaultStringConverterTest { + private DefaultStringConverter converter; + + @Before public void setup() { + converter = new DefaultStringConverter(); + } + + @Test public void fromString_testValidStringInput() { + assertEquals("string", converter.fromString("string")); + } + + @Test public void fromString_testEmptytringInput() { + assertEquals("", converter.fromString("")); + } + + @Test public void toString_testValidStringInput() { + assertEquals("string", converter.toString("string")); + } + + @Test public void toString_testEmptyStringInput() { + assertEquals("", converter.toString("")); + } +} --- old/modules/base/src/test/java/javafx/util/converter/DoubleStringConverterTest.java 2015-08-31 10:25:17.909216232 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class DoubleStringConverterTest { - private DoubleStringConverter converter; - - @Before public void setup() { - converter = new DoubleStringConverter(); - } - - @Test public void fromString_testValidStringInput() { - assertEquals(Double.valueOf(10), converter.fromString("10")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace() { - assertEquals(Double.valueOf(10), converter.fromString(" 10 ")); - } - - @Test public void toString_validInput() { - assertEquals("10.0", converter.toString(10D)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/DoubleStringConverterTest.java 2015-08-31 10:25:17.773216234 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import javafx.util.converter.DoubleStringConverter; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class DoubleStringConverterTest { + private DoubleStringConverter converter; + + @Before public void setup() { + converter = new DoubleStringConverter(); + } + + @Test public void fromString_testValidStringInput() { + assertEquals(Double.valueOf(10), converter.fromString("10")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace() { + assertEquals(Double.valueOf(10), converter.fromString(" 10 ")); + } + + @Test public void toString_validInput() { + assertEquals("10.0", converter.toString(10D)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/FloatStringConverterTest.java 2015-08-31 10:25:18.537216225 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class FloatStringConverterTest { - private FloatStringConverter converter; - - @Before public void setup() { - converter = new FloatStringConverter(); - } - - @Test public void fromString_testValidStringInput() { - assertEquals((Float)10.3521f, converter.fromString("10.3521")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace() { - assertEquals((Float)10.3521f, converter.fromString(" 10.3521 ")); - } - - @Test public void toString_validInput() { - assertEquals("10.3521", converter.toString(10.3521f)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/FloatStringConverterTest.java 2015-08-31 10:25:18.405216227 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import javafx.util.converter.FloatStringConverter; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class FloatStringConverterTest { + private FloatStringConverter converter; + + @Before public void setup() { + converter = new FloatStringConverter(); + } + + @Test public void fromString_testValidStringInput() { + assertEquals((Float)10.3521f, converter.fromString("10.3521")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace() { + assertEquals((Float)10.3521f, converter.fromString(" 10.3521 ")); + } + + @Test public void toString_validInput() { + assertEquals("10.3521", converter.toString(10.3521f)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/IntegerStringConverterTest.java 2015-08-31 10:25:19.129216219 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class IntegerStringConverterTest { - private IntegerStringConverter converter; - - @Before public void setup() { - converter = new IntegerStringConverter(); - } - - @Test public void fromString_testValidStringInput() { - assertEquals((Integer) 10, converter.fromString("10")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace() { - assertEquals((Integer) 10, converter.fromString(" 10 ")); - } - - @Test public void toString_validInput() { - assertEquals("10", converter.toString(10)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/IntegerStringConverterTest.java 2015-08-31 10:25:18.997216220 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import javafx.util.converter.IntegerStringConverter; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class IntegerStringConverterTest { + private IntegerStringConverter converter; + + @Before public void setup() { + converter = new IntegerStringConverter(); + } + + @Test public void fromString_testValidStringInput() { + assertEquals((Integer) 10, converter.fromString("10")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace() { + assertEquals((Integer) 10, converter.fromString(" 10 ")); + } + + @Test public void toString_validInput() { + assertEquals("10", converter.toString(10)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/LocalDateStringConverterTest.java 2015-08-31 10:25:19.881216210 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.util.Arrays; -import java.time.LocalDate; -import java.time.chrono.Chronology; -import java.time.chrono.IsoChronology; -import java.time.format.DateTimeFormatter; -import java.time.format.FormatStyle; -import java.util.Collection; -import java.util.Locale; - -import javafx.util.StringConverter; - -import static org.junit.Assert.*; -import org.junit.Before; -import org.junit.Test; -import org.junit.Ignore; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - */ -@RunWith(Parameterized.class) -public class LocalDateStringConverterTest { - private static final LocalDate VALID_DATE = LocalDate.of(1985, 1, 12); - - private static final DateTimeFormatter aFormatter = DateTimeFormatter.ofPattern("dd MM yyyy"); - private static final DateTimeFormatter aParser = DateTimeFormatter.ofPattern("yyyy MM dd"); - - - @Parameterized.Parameters public static Collection implementations() { - return Arrays.asList(new Object[][] { - { new LocalDateStringConverter(), - Locale.getDefault(Locale.Category.FORMAT), FormatStyle.SHORT, - VALID_DATE, null, null }, - - { new LocalDateStringConverter(aFormatter, aParser), - Locale.getDefault(Locale.Category.FORMAT), null, - VALID_DATE, aFormatter, aParser }, - - { new LocalDateStringConverter(FormatStyle.SHORT, Locale.UK, IsoChronology.INSTANCE), - Locale.UK, FormatStyle.SHORT, - VALID_DATE, null, null }, - }); - } - - private LocalDateStringConverter converter; - private Locale locale; - private FormatStyle dateStyle; - private DateTimeFormatter formatter, parser; - private LocalDate validDate; - - public LocalDateStringConverterTest(LocalDateStringConverter converter, Locale locale, FormatStyle dateStyle, LocalDate validDate, DateTimeFormatter formatter, DateTimeFormatter parser) { - this.converter = converter; - this.locale = locale; - this.dateStyle = dateStyle; - this.validDate = validDate; - this.formatter = formatter; - this.parser = parser; - } - - @Before public void setup() { - } - - /********************************************************************* - * Test constructors - ********************************************************************/ - - @Test public void testConstructor() { - assertEquals(locale, converter.ldtConverter.locale); - assertEquals((dateStyle != null) ? dateStyle : FormatStyle.SHORT, converter.ldtConverter.dateStyle); - assertNull(converter.ldtConverter.timeStyle); - if (formatter != null) { - assertEquals(formatter, converter.ldtConverter.formatter); - } - if (parser != null) { - assertEquals(parser, converter.ldtConverter.parser); - } else if (formatter != null) { - assertEquals(formatter, converter.ldtConverter.parser); - } - } - - - /********************************************************************* - * Test toString / fromString methods - ********************************************************************/ - - @Test public void toString_to_fromString_testRoundtrip() { - if (formatter == null) { - // Only the default formatter/parser can guarantee roundtrip symmetry - assertEquals(validDate, converter.fromString(converter.toString(validDate))); - } - } - - @Test(expected=RuntimeException.class) - public void fromString_testInvalidInput() { - converter.fromString("abcdefg"); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/LocalDateStringConverterTest.java 2015-08-31 10:25:19.741216212 -0400 @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.util.Arrays; +import java.time.LocalDate; +import java.time.chrono.Chronology; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.util.Collection; +import java.util.Locale; + +import javafx.util.StringConverter; +import javafx.util.converter.LocalTimeStringConverterShim; +import javafx.util.converter.LocalDateStringConverter; +import javafx.util.converter.LocalDateStringConverterShim; + +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + */ +@RunWith(Parameterized.class) +public class LocalDateStringConverterTest { + private static final LocalDate VALID_DATE = LocalDate.of(1985, 1, 12); + + private static final DateTimeFormatter aFormatter = DateTimeFormatter.ofPattern("dd MM yyyy"); + private static final DateTimeFormatter aParser = DateTimeFormatter.ofPattern("yyyy MM dd"); + + + @Parameterized.Parameters public static Collection implementations() { + return Arrays.asList(new Object[][] { + { new LocalDateStringConverter(), + Locale.getDefault(Locale.Category.FORMAT), FormatStyle.SHORT, + VALID_DATE, null, null }, + + { new LocalDateStringConverter(aFormatter, aParser), + Locale.getDefault(Locale.Category.FORMAT), null, + VALID_DATE, aFormatter, aParser }, + + { new LocalDateStringConverter(FormatStyle.SHORT, Locale.UK, IsoChronology.INSTANCE), + Locale.UK, FormatStyle.SHORT, + VALID_DATE, null, null }, + }); + } + + private LocalDateStringConverter converter; + private Locale locale; + private FormatStyle dateStyle; + private DateTimeFormatter formatter, parser; + private LocalDate validDate; + + public LocalDateStringConverterTest(LocalDateStringConverter converter, Locale locale, FormatStyle dateStyle, LocalDate validDate, DateTimeFormatter formatter, DateTimeFormatter parser) { + this.converter = converter; + this.locale = locale; + this.dateStyle = dateStyle; + this.validDate = validDate; + this.formatter = formatter; + this.parser = parser; + } + + @Before public void setup() { + } + + /********************************************************************* + * Test constructors + ********************************************************************/ + + @Test public void testConstructor() { + assertEquals(locale, LocalDateStringConverterShim.getldtConverterLocale(converter)); + assertEquals((dateStyle != null) ? dateStyle : FormatStyle.SHORT, + LocalDateStringConverterShim.getldtConverterDateStyle(converter)); + assertNull(LocalDateStringConverterShim.getldtConverterTimeStyle(converter)); + if (formatter != null) { + assertEquals(formatter, + LocalDateStringConverterShim.getldtConverterFormatter(converter)); + } + if (parser != null) { + assertEquals(parser, + LocalDateStringConverterShim.getldtConverterParser(converter)); + } else if (formatter != null) { + assertEquals(formatter, + LocalDateStringConverterShim.getldtConverterParser(converter)); + } + } + + + /********************************************************************* + * Test toString / fromString methods + ********************************************************************/ + + @Test public void toString_to_fromString_testRoundtrip() { + if (formatter == null) { + // Only the default formatter/parser can guarantee roundtrip symmetry + assertEquals(validDate, converter.fromString(converter.toString(validDate))); + } + } + + @Test(expected=RuntimeException.class) + public void fromString_testInvalidInput() { + converter.fromString("abcdefg"); + } +} --- old/modules/base/src/test/java/javafx/util/converter/LocalDateTimeStringConverterTest.java 2015-08-31 10:25:20.569216202 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.time.LocalDateTime; -import java.time.chrono.Chronology; -import java.time.chrono.IsoChronology; -import java.time.format.DateTimeFormatter; -import java.time.format.FormatStyle; -import java.util.Arrays; -import java.util.Collection; -import java.util.Locale; -import static org.junit.Assert.*; - -import javafx.util.StringConverter; - -import org.junit.Before; -import org.junit.Test; -import org.junit.Ignore; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - */ -@RunWith(Parameterized.class) -public class LocalDateTimeStringConverterTest { - private static final LocalDateTime VALID_LDT_WITH_SECONDS = LocalDateTime.of(1985, 1, 12, 12, 34, 56); - private static final LocalDateTime VALID_LDT_WITHOUT_SECONDS = LocalDateTime.of(1985, 1, 12, 12, 34, 0); - - private static final DateTimeFormatter aFormatter = DateTimeFormatter.ofPattern("dd MM yyyy HH mm ss"); - private static final DateTimeFormatter aParser = DateTimeFormatter.ofPattern("yyyy MM dd hh mm ss a"); - - @Parameterized.Parameters public static Collection implementations() { - return Arrays.asList(new Object[][] { - { new LocalDateTimeStringConverter(), - Locale.getDefault(Locale.Category.FORMAT), FormatStyle.SHORT, FormatStyle.SHORT, - VALID_LDT_WITHOUT_SECONDS, null, null }, - - { new LocalDateTimeStringConverter(aFormatter, aParser), - Locale.getDefault(Locale.Category.FORMAT), null, null, - VALID_LDT_WITH_SECONDS, aFormatter, aParser }, - - { new LocalDateTimeStringConverter(FormatStyle.SHORT, FormatStyle.SHORT, Locale.UK, IsoChronology.INSTANCE), - Locale.UK, FormatStyle.SHORT, FormatStyle.SHORT, - VALID_LDT_WITHOUT_SECONDS, null, null }, - }); - } - - private LocalDateTimeStringConverter converter; - private Locale locale; - private FormatStyle dateStyle; - private FormatStyle timeStyle; - private DateTimeFormatter formatter, parser; - - private LocalDateTime validDateTime; - - public LocalDateTimeStringConverterTest(LocalDateTimeStringConverter converter, Locale locale, FormatStyle dateStyle, FormatStyle timeStyle, LocalDateTime validDateTime, DateTimeFormatter formatter, DateTimeFormatter parser) { - this.converter = converter; - this.locale = locale; - this.dateStyle = dateStyle; - this.timeStyle = timeStyle; - this.validDateTime = validDateTime; - this.formatter = formatter; - this.parser = parser; - } - - @Before public void setup() { - } - - /********************************************************************* - * Test constructors - ********************************************************************/ - - @Test public void testConstructor() { - assertEquals(locale, converter.ldtConverter.locale); - assertEquals((dateStyle != null) ? dateStyle : FormatStyle.SHORT, converter.ldtConverter.dateStyle); - assertEquals((timeStyle != null) ? timeStyle : FormatStyle.SHORT, converter.ldtConverter.timeStyle); - if (formatter != null) { - assertEquals(formatter, converter.ldtConverter.formatter); - } - if (parser != null) { - assertEquals(parser, converter.ldtConverter.parser); - } else if (formatter != null) { - assertEquals(formatter, converter.ldtConverter.parser); - } - } - - - /********************************************************************* - * Test toString / fromString methods - ********************************************************************/ - - @Test public void toString_to_fromString_testRoundtrip() { - if (formatter == null) { - // Only the default formatter/parser can guarantee roundtrip symmetry - assertEquals(validDateTime, converter.fromString(converter.toString(validDateTime))); - } - } - - - @Test(expected=RuntimeException.class) - public void fromString_testInvalidInput() { - converter.fromString("abcdefg"); - } - - @Test public void converter_with_specified_formatter_and_parser() { - String formatPattern = "dd MMMM yyyy, HH:mm:ss"; - String parsePattern = "MMMM dd, yyyy, HH:mm:ss"; - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatPattern); - DateTimeFormatter parser = DateTimeFormatter.ofPattern(parsePattern); - StringConverter converter = new LocalDateTimeStringConverter(formatter, parser); - assertEquals("12 January 1985, 12:34:56", converter.toString(VALID_LDT_WITH_SECONDS)); - assertEquals(VALID_LDT_WITH_SECONDS, converter.fromString("January 12, 1985, 12:34:56")); - } - - @Test public void converter_with_specified_formatter_and_null_parser() { - String pattern = "dd MMMM yyyy, HH:mm:ss"; - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); - StringConverter converter = new LocalDateTimeStringConverter(formatter, null); - assertEquals("12 January 1985, 12:34:56", converter.toString(VALID_LDT_WITH_SECONDS)); - assertEquals(VALID_LDT_WITH_SECONDS, converter.fromString("12 January 1985, 12:34:56")); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/LocalDateTimeStringConverterTest.java 2015-08-31 10:25:20.433216204 -0400 @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.time.LocalDateTime; +import java.time.chrono.Chronology; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.util.Arrays; +import java.util.Collection; +import java.util.Locale; +import static org.junit.Assert.*; + +import javafx.util.StringConverter; +import javafx.util.converter.LocalTimeStringConverterShim; +import javafx.util.converter.LocalDateTimeStringConverter; +import javafx.util.converter.LocalDateTimeStringConverterShim; + +import org.junit.Before; +import org.junit.Test; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + */ +@RunWith(Parameterized.class) +public class LocalDateTimeStringConverterTest { + private static final LocalDateTime VALID_LDT_WITH_SECONDS = LocalDateTime.of(1985, 1, 12, 12, 34, 56); + private static final LocalDateTime VALID_LDT_WITHOUT_SECONDS = LocalDateTime.of(1985, 1, 12, 12, 34, 0); + + private static final DateTimeFormatter aFormatter = DateTimeFormatter.ofPattern("dd MM yyyy HH mm ss"); + private static final DateTimeFormatter aParser = DateTimeFormatter.ofPattern("yyyy MM dd hh mm ss a"); + + @Parameterized.Parameters public static Collection implementations() { + return Arrays.asList(new Object[][] { + { new LocalDateTimeStringConverter(), + Locale.getDefault(Locale.Category.FORMAT), FormatStyle.SHORT, FormatStyle.SHORT, + VALID_LDT_WITHOUT_SECONDS, null, null }, + + { new LocalDateTimeStringConverter(aFormatter, aParser), + Locale.getDefault(Locale.Category.FORMAT), null, null, + VALID_LDT_WITH_SECONDS, aFormatter, aParser }, + + { new LocalDateTimeStringConverter(FormatStyle.SHORT, FormatStyle.SHORT, Locale.UK, IsoChronology.INSTANCE), + Locale.UK, FormatStyle.SHORT, FormatStyle.SHORT, + VALID_LDT_WITHOUT_SECONDS, null, null }, + }); + } + + private LocalDateTimeStringConverter converter; + private Locale locale; + private FormatStyle dateStyle; + private FormatStyle timeStyle; + private DateTimeFormatter formatter, parser; + + private LocalDateTime validDateTime; + + public LocalDateTimeStringConverterTest(LocalDateTimeStringConverter converter, Locale locale, FormatStyle dateStyle, FormatStyle timeStyle, LocalDateTime validDateTime, DateTimeFormatter formatter, DateTimeFormatter parser) { + this.converter = converter; + this.locale = locale; + this.dateStyle = dateStyle; + this.timeStyle = timeStyle; + this.validDateTime = validDateTime; + this.formatter = formatter; + this.parser = parser; + } + + @Before public void setup() { + } + + /********************************************************************* + * Test constructors + ********************************************************************/ + + @Test public void testConstructor() { + assertEquals(locale, + LocalDateTimeStringConverterShim.getldtConverterLocale(converter)); + assertEquals((dateStyle != null) ? dateStyle : FormatStyle.SHORT, + LocalDateTimeStringConverterShim.getldtConverterDateStyle(converter)); + assertEquals((timeStyle != null) ? timeStyle : FormatStyle.SHORT, + LocalDateTimeStringConverterShim.getldtConverterTimeStyle(converter)); + if (formatter != null) { + assertEquals(formatter, + LocalDateTimeStringConverterShim.getldtConverterFormatter(converter)); + } + if (parser != null) { + assertEquals(parser, + LocalDateTimeStringConverterShim.getldtConverterParser(converter)); + } else if (formatter != null) { + assertEquals(formatter, + LocalDateTimeStringConverterShim.getldtConverterFormatter(converter)); + } + } + + + /********************************************************************* + * Test toString / fromString methods + ********************************************************************/ + + @Test public void toString_to_fromString_testRoundtrip() { + if (formatter == null) { + // Only the default formatter/parser can guarantee roundtrip symmetry + assertEquals(validDateTime, converter.fromString(converter.toString(validDateTime))); + } + } + + + @Test(expected=RuntimeException.class) + public void fromString_testInvalidInput() { + converter.fromString("abcdefg"); + } + + @Test public void converter_with_specified_formatter_and_parser() { + String formatPattern = "dd MMMM yyyy, HH:mm:ss"; + String parsePattern = "MMMM dd, yyyy, HH:mm:ss"; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatPattern); + DateTimeFormatter parser = DateTimeFormatter.ofPattern(parsePattern); + StringConverter converter = new LocalDateTimeStringConverter(formatter, parser); + assertEquals("12 January 1985, 12:34:56", converter.toString(VALID_LDT_WITH_SECONDS)); + assertEquals(VALID_LDT_WITH_SECONDS, converter.fromString("January 12, 1985, 12:34:56")); + } + + @Test public void converter_with_specified_formatter_and_null_parser() { + String pattern = "dd MMMM yyyy, HH:mm:ss"; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); + StringConverter converter = new LocalDateTimeStringConverter(formatter, null); + assertEquals("12 January 1985, 12:34:56", converter.toString(VALID_LDT_WITH_SECONDS)); + assertEquals(VALID_LDT_WITH_SECONDS, converter.fromString("12 January 1985, 12:34:56")); + } +} --- old/modules/base/src/test/java/javafx/util/converter/LocalTimeStringConverterTest.java 2015-08-31 10:25:21.337216194 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.time.LocalTime; -import java.time.chrono.Chronology; -import java.time.chrono.IsoChronology; -import java.time.format.DateTimeFormatter; -import java.time.format.FormatStyle; -import java.util.Arrays; -import java.util.Collection; -import java.util.Locale; - -import javafx.util.StringConverter; - -import static org.junit.Assert.*; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - */ -@RunWith(Parameterized.class) -public class LocalTimeStringConverterTest { - private static final LocalTime VALID_TIME_WITH_SECONDS; - private static final LocalTime VALID_TIME_WITHOUT_SECONDS; - - static { - VALID_TIME_WITH_SECONDS = LocalTime.of(12, 34, 56); - VALID_TIME_WITHOUT_SECONDS = LocalTime.of(12, 34, 0); - } - - private static final DateTimeFormatter aFormatter = DateTimeFormatter.ofPattern("HH mm ss"); - private static final DateTimeFormatter aParser = DateTimeFormatter.ofPattern("hh mm ss a"); - - - @Parameterized.Parameters public static Collection implementations() { - return Arrays.asList(new Object[][] { - { new LocalTimeStringConverter(), - Locale.getDefault(Locale.Category.FORMAT), FormatStyle.SHORT, - VALID_TIME_WITHOUT_SECONDS, null, null }, - - { new LocalTimeStringConverter(aFormatter, aParser), - Locale.getDefault(Locale.Category.FORMAT), null, - VALID_TIME_WITH_SECONDS, aFormatter, aParser }, - - { new LocalTimeStringConverter(FormatStyle.SHORT, Locale.UK), - Locale.UK, FormatStyle.SHORT, - VALID_TIME_WITHOUT_SECONDS, null, null }, - }); - } - - private LocalTimeStringConverter converter; - private Locale locale; - private FormatStyle timeStyle; - private DateTimeFormatter formatter, parser; - private LocalTime validTime; - - public LocalTimeStringConverterTest(LocalTimeStringConverter converter, Locale locale, FormatStyle timeStyle, LocalTime validTime, DateTimeFormatter formatter, DateTimeFormatter parser) { - this.converter = converter; - this.locale = locale; - this.timeStyle = timeStyle; - this.validTime = validTime; - this.formatter = formatter; - this.parser = parser; - } - - @Before public void setup() { - } - - /********************************************************************* - * Test constructors - ********************************************************************/ - - @Test public void testConstructor() { - assertEquals(locale, converter.ldtConverter.locale); - assertNull(converter.ldtConverter.dateStyle); - assertEquals((timeStyle != null) ? timeStyle : FormatStyle.SHORT, converter.ldtConverter.timeStyle); - if (formatter != null) { - assertEquals(formatter, converter.ldtConverter.formatter); - } - if (parser != null) { - assertEquals(parser, converter.ldtConverter.parser); - } else if (formatter != null) { - assertEquals(formatter, converter.ldtConverter.parser); - } - } - - - - /********************************************************************* - * Test toString / fromString methods - ********************************************************************/ - - @Test public void toString_to_fromString_testRoundtrip() { - if (formatter == null) { - // Only the default formatter/parser can guarantee roundtrip symmetry - assertEquals(validTime, converter.fromString(converter.toString(validTime))); - } - } - - @Test(expected=RuntimeException.class) - public void fromString_testInvalidInput() { - converter.fromString("abcdefg"); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/LocalTimeStringConverterTest.java 2015-08-31 10:25:21.145216196 -0400 @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.time.LocalTime; +import java.time.chrono.Chronology; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.util.Arrays; +import java.util.Collection; +import java.util.Locale; + +import javafx.util.StringConverter; +import javafx.util.converter.LocalTimeStringConverterShim; +import javafx.util.converter.LocalTimeStringConverter; + +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + */ +@RunWith(Parameterized.class) +public class LocalTimeStringConverterTest { + private static final LocalTime VALID_TIME_WITH_SECONDS; + private static final LocalTime VALID_TIME_WITHOUT_SECONDS; + + static { + VALID_TIME_WITH_SECONDS = LocalTime.of(12, 34, 56); + VALID_TIME_WITHOUT_SECONDS = LocalTime.of(12, 34, 0); + } + + private static final DateTimeFormatter aFormatter = DateTimeFormatter.ofPattern("HH mm ss"); + private static final DateTimeFormatter aParser = DateTimeFormatter.ofPattern("hh mm ss a"); + + + @Parameterized.Parameters public static Collection implementations() { + return Arrays.asList(new Object[][] { + { new LocalTimeStringConverter(), + Locale.getDefault(Locale.Category.FORMAT), FormatStyle.SHORT, + VALID_TIME_WITHOUT_SECONDS, null, null }, + + { new LocalTimeStringConverter(aFormatter, aParser), + Locale.getDefault(Locale.Category.FORMAT), null, + VALID_TIME_WITH_SECONDS, aFormatter, aParser }, + + { new LocalTimeStringConverter(FormatStyle.SHORT, Locale.UK), + Locale.UK, FormatStyle.SHORT, + VALID_TIME_WITHOUT_SECONDS, null, null }, + }); + } + + private LocalTimeStringConverter converter; + private Locale locale; + private FormatStyle timeStyle; + private DateTimeFormatter formatter, parser; + private LocalTime validTime; + + public LocalTimeStringConverterTest(LocalTimeStringConverter converter, Locale locale, FormatStyle timeStyle, LocalTime validTime, DateTimeFormatter formatter, DateTimeFormatter parser) { + this.converter = converter; + this.locale = locale; + this.timeStyle = timeStyle; + this.validTime = validTime; + this.formatter = formatter; + this.parser = parser; + } + + @Before public void setup() { + } + + /********************************************************************* + * Test constructors + ********************************************************************/ + + @Test public void testConstructor() { + assertEquals(locale, + LocalTimeStringConverterShim.getldtConverterLocale(converter)); + assertNull(LocalTimeStringConverterShim.getldtConverterDateStyle(converter)); + assertEquals((timeStyle != null) ? timeStyle : FormatStyle.SHORT, + LocalTimeStringConverterShim.getldtConverterTimeStyle(converter)); + if (formatter != null) { + assertEquals(formatter, + LocalTimeStringConverterShim.getldtConverterFormatter(converter)); + } + if (parser != null) { + assertEquals(parser, + LocalTimeStringConverterShim.getldtConverterParser(converter)); + } else if (formatter != null) { + assertEquals(formatter, + LocalTimeStringConverterShim.getldtConverterFormatter(converter)); + } + } + + + + /********************************************************************* + * Test toString / fromString methods + ********************************************************************/ + + @Test public void toString_to_fromString_testRoundtrip() { + if (formatter == null) { + // Only the default formatter/parser can guarantee roundtrip symmetry + assertEquals(validTime, converter.fromString(converter.toString(validTime))); + } + } + + @Test(expected=RuntimeException.class) + public void fromString_testInvalidInput() { + converter.fromString("abcdefg"); + } +} --- old/modules/base/src/test/java/javafx/util/converter/LongStringConverterTest.java 2015-08-31 10:25:22.025216186 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class LongStringConverterTest { - private LongStringConverter converter; - - @Before public void setup() { - converter = new LongStringConverter(); - } - - @Test public void fromString_testValidStringInput() { - assertEquals(Long.valueOf(10), converter.fromString("10")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace() { - assertEquals(Long.valueOf(10), converter.fromString(" 10 ")); - } - - @Test public void toString_validInput() { - assertEquals("10", converter.toString(10L)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/LongStringConverterTest.java 2015-08-31 10:25:21.893216187 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import javafx.util.converter.LongStringConverter; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class LongStringConverterTest { + private LongStringConverter converter; + + @Before public void setup() { + converter = new LongStringConverter(); + } + + @Test public void fromString_testValidStringInput() { + assertEquals(Long.valueOf(10), converter.fromString("10")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace() { + assertEquals(Long.valueOf(10), converter.fromString(" 10 ")); + } + + @Test public void toString_validInput() { + assertEquals("10", converter.toString(10L)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/NumberStringConverterTest.java 2015-08-31 10:25:22.781216177 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.Locale; -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class NumberStringConverterTest { - private NumberStringConverter converter; - - @Before public void setup() { - converter = new NumberStringConverter(); - } - - /********************************************************************* - * Test constructors - ********************************************************************/ - - @Test public void testDefaultConstructor() { - NumberStringConverter c = new NumberStringConverter(); - assertEquals(Locale.getDefault(), c.locale); - assertNull(c.pattern); - assertNull(c.numberFormat); - } - - @Test public void testConstructor_locale() { - NumberStringConverter c = new NumberStringConverter(Locale.CANADA); - assertEquals(Locale.CANADA, c.locale); - assertNull(c.pattern); - assertNull(c.numberFormat); - } - - @Test public void testConstructor_pattern() { - NumberStringConverter c = new NumberStringConverter("#,##,###,####"); - assertEquals(Locale.getDefault(), c.locale); - assertEquals("#,##,###,####", c.pattern); - assertNull(c.numberFormat); - } - - @Test public void testConstructor_locale_pattern() { - NumberStringConverter c = new NumberStringConverter(Locale.CANADA, "#,##,###,####"); - assertEquals(Locale.CANADA, c.locale); - assertEquals("#,##,###,####", c.pattern); - assertNull(c.numberFormat); - } - - @Test public void testConstructor_numberFormat() { - NumberFormat format = NumberFormat.getCurrencyInstance(Locale.JAPAN); - NumberStringConverter c = new NumberStringConverter(format); - assertNull(c.locale); - assertNull(c.pattern); - assertEquals(format, c.numberFormat); - } - - - /********************************************************************* - * Test methods - ********************************************************************/ - - @Test public void getNumberFormat_default() { - assertNotNull(converter.getNumberFormat()); - } - - @Test public void getNumberFormat_nonNullPattern() { - converter = new NumberStringConverter("#,##,###,####"); - assertTrue(converter.getNumberFormat() instanceof DecimalFormat); - } - - @Test public void getNumberFormat_nonNullNumberFormat() { - NumberFormat nf = NumberFormat.getCurrencyInstance(); - converter = new NumberStringConverter(nf); - assertEquals(nf, converter.getNumberFormat()); - } - - - /********************************************************************* - * Test toString / fromString methods - ********************************************************************/ - - @Test public void fromString_testValidInput() { - assertEquals(10L, converter.fromString("10")); - } - - @Test public void fromString_testValidInputWithWhiteSpace() { - assertEquals(10L, converter.fromString(" 10 ")); - } - - @Test(expected=RuntimeException.class) - public void fromString_testInvalidInput() { - converter.fromString("abcdefg"); - } - - @Test public void toString_validInput() { - assertEquals("10", converter.toString(10L)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/NumberStringConverterTest.java 2015-08-31 10:25:22.637216179 -0400 @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.Locale; +import javafx.util.converter.LocalTimeStringConverterShim; +import javafx.util.converter.NumberStringConverter; +import javafx.util.converter.NumberStringConverterShim; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class NumberStringConverterTest { + private NumberStringConverter converter; + + @Before public void setup() { + converter = new NumberStringConverter(); + } + + /********************************************************************* + * Test constructors + ********************************************************************/ + + @Test public void testDefaultConstructor() { + NumberStringConverter c = new NumberStringConverter(); + assertEquals(Locale.getDefault(), NumberStringConverterShim.getLocale(c)); + assertNull(NumberStringConverterShim.getPattern(c)); + assertNull(NumberStringConverterShim.getNumberFormatVar(c)); + } + + @Test public void testConstructor_locale() { + NumberStringConverter c = new NumberStringConverter(Locale.CANADA); + assertEquals(Locale.CANADA, NumberStringConverterShim.getLocale(c)); + assertNull(NumberStringConverterShim.getPattern(c)); + assertNull(NumberStringConverterShim.getNumberFormatVar(c)); + } + + @Test public void testConstructor_pattern() { + NumberStringConverter c = new NumberStringConverter("#,##,###,####"); + assertEquals(Locale.getDefault(), NumberStringConverterShim.getLocale(c)); + assertEquals("#,##,###,####", NumberStringConverterShim.getPattern(c)); + assertNull(NumberStringConverterShim.getNumberFormatVar(c)); + } + + @Test public void testConstructor_locale_pattern() { + NumberStringConverter c = new NumberStringConverter(Locale.CANADA, "#,##,###,####"); + assertEquals(Locale.CANADA, NumberStringConverterShim.getLocale(c)); + assertEquals("#,##,###,####", NumberStringConverterShim.getPattern(c)); + assertNull(NumberStringConverterShim.getNumberFormatVar(c)); + } + + @Test public void testConstructor_numberFormat() { + NumberFormat format = NumberFormat.getCurrencyInstance(Locale.JAPAN); + NumberStringConverter c = new NumberStringConverter(format); + assertNull(NumberStringConverterShim.getLocale(c)); + assertNull(NumberStringConverterShim.getPattern(c)); + assertEquals(format, NumberStringConverterShim.getNumberFormatVar(c)); + } + + + /********************************************************************* + * Test methods + ********************************************************************/ + + @Test public void getNumberFormat_default() { + assertNotNull(NumberStringConverterShim.getNumberFormat(converter)); + } + + @Test public void getNumberFormat_nonNullPattern() { + converter = new NumberStringConverter("#,##,###,####"); + assertTrue( + NumberStringConverterShim.getNumberFormat(converter) + instanceof DecimalFormat); + } + + @Test public void getNumberFormat_nonNullNumberFormat() { + NumberFormat nf = NumberFormat.getCurrencyInstance(); + converter = new NumberStringConverter(nf); + assertEquals(nf, NumberStringConverterShim.getNumberFormat(converter)); + } + + + /********************************************************************* + * Test toString / fromString methods + ********************************************************************/ + + @Test public void fromString_testValidInput() { + assertEquals(10L, converter.fromString("10")); + } + + @Test public void fromString_testValidInputWithWhiteSpace() { + assertEquals(10L, converter.fromString(" 10 ")); + } + + @Test(expected=RuntimeException.class) + public void fromString_testInvalidInput() { + converter.fromString("abcdefg"); + } + + @Test public void toString_validInput() { + assertEquals("10", converter.toString(10L)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/ParameterizedConverterTest.java 2015-08-31 10:25:23.417216170 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.util.Arrays; -import java.util.Collection; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import javafx.util.StringConverter; - -import org.junit.Before; -import org.junit.Test; -import org.junit.Ignore; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - */ -@RunWith(Parameterized.class) -public class ParameterizedConverterTest { - private final Class converterClass; - private StringConverter converter; - - @Parameterized.Parameters public static Collection implementations() { - return Arrays.asList(new Object[][] { - { BigDecimalStringConverter.class }, - { BigIntegerStringConverter.class }, - { BooleanStringConverter.class }, - { ByteStringConverter.class }, - { CharacterStringConverter.class }, - { CurrencyStringConverter.class }, - { DateStringConverter.class }, - { DateTimeStringConverter.class }, - { DefaultStringConverter.class }, - { DoubleStringConverter.class }, - { FloatStringConverter.class }, - { IntegerStringConverter.class }, - { LongStringConverter.class }, - { NumberStringConverter.class }, - { PercentageStringConverter.class }, - { ShortStringConverter.class }, - { TimeStringConverter.class }, - }); - } - - public ParameterizedConverterTest(Class converterClass) { - this.converterClass = converterClass; - } - - @Before public void setup() { - try { - converter = converterClass.newInstance(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - @Test public void toString_testNull() { - assertEquals("", converter.toString(null)); - } - - @Test public void fromString_testEmptyStringWithWhiteSpace() { - if (converterClass == DefaultStringConverter.class) { - assertEquals(" ", converter.fromString(" ")); - } else { - assertNull(converter.fromString(" ")); - } - } - - @Test public void fromString_testNull() { - assertNull(converter.fromString(null)); - } - - @Test public void fromString_testEmptyString() { - if (converterClass == DefaultStringConverter.class) { - assertEquals("", converter.fromString("")); - } else { - assertNull(converter.fromString("")); - } - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/ParameterizedConverterTest.java 2015-08-31 10:25:23.249216172 -0400 @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.util.Arrays; +import java.util.Collection; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import javafx.util.StringConverter; +import javafx.util.converter.BigDecimalStringConverter; +import javafx.util.converter.BigIntegerStringConverter; +import javafx.util.converter.BooleanStringConverter; +import javafx.util.converter.ByteStringConverter; +import javafx.util.converter.CharacterStringConverter; +import javafx.util.converter.CurrencyStringConverter; +import javafx.util.converter.DateStringConverter; +import javafx.util.converter.DateTimeStringConverter; +import javafx.util.converter.DefaultStringConverter; +import javafx.util.converter.DoubleStringConverter; +import javafx.util.converter.FloatStringConverter; +import javafx.util.converter.IntegerStringConverter; +import javafx.util.converter.LongStringConverter; +import javafx.util.converter.NumberStringConverter; +import javafx.util.converter.PercentageStringConverter; +import javafx.util.converter.ShortStringConverter; +import javafx.util.converter.TimeStringConverter; + +import org.junit.Before; +import org.junit.Test; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + */ +@RunWith(Parameterized.class) +public class ParameterizedConverterTest { + private final Class converterClass; + private StringConverter converter; + + @Parameterized.Parameters public static Collection implementations() { + return Arrays.asList(new Object[][] { + { BigDecimalStringConverter.class }, + { BigIntegerStringConverter.class }, + { BooleanStringConverter.class }, + { ByteStringConverter.class }, + { CharacterStringConverter.class }, + { CurrencyStringConverter.class }, + { DateStringConverter.class }, + { DateTimeStringConverter.class }, + { DefaultStringConverter.class }, + { DoubleStringConverter.class }, + { FloatStringConverter.class }, + { IntegerStringConverter.class }, + { LongStringConverter.class }, + { NumberStringConverter.class }, + { PercentageStringConverter.class }, + { ShortStringConverter.class }, + { TimeStringConverter.class }, + }); + } + + public ParameterizedConverterTest(Class converterClass) { + this.converterClass = converterClass; + } + + @Before public void setup() { + try { + converter = converterClass.newInstance(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @Test public void toString_testNull() { + assertEquals("", converter.toString(null)); + } + + @Test public void fromString_testEmptyStringWithWhiteSpace() { + if (converterClass == DefaultStringConverter.class) { + assertEquals(" ", converter.fromString(" ")); + } else { + assertNull(converter.fromString(" ")); + } + } + + @Test public void fromString_testNull() { + assertNull(converter.fromString(null)); + } + + @Test public void fromString_testEmptyString() { + if (converterClass == DefaultStringConverter.class) { + assertEquals("", converter.fromString("")); + } else { + assertNull(converter.fromString("")); + } + } +} --- old/modules/base/src/test/java/javafx/util/converter/PercentageStringConverterTest.java 2015-08-31 10:25:24.089216163 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.Locale; -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class PercentageStringConverterTest { - private PercentageStringConverter converter; - - @Before public void setup() { - converter = new PercentageStringConverter(Locale.US); - } - - /********************************************************************* - * Test constructors - ********************************************************************/ - - @Test public void testDefaultConstructor() { - PercentageStringConverter c = new PercentageStringConverter(); - assertEquals(Locale.getDefault(), c.locale); - assertNull(c.pattern); - assertNull(c.numberFormat); - } - - @Test public void testConstructor_locale() { - PercentageStringConverter c = new PercentageStringConverter(Locale.CANADA); - assertEquals(Locale.CANADA, c.locale); - assertNull(c.pattern); - assertNull(c.numberFormat); - } - - @Test public void testConstructor_numberFormat() { - NumberFormat format = NumberFormat.getCurrencyInstance(Locale.JAPAN); - PercentageStringConverter c = new PercentageStringConverter(format); - assertNull(c.locale); - assertNull(c.pattern); - assertEquals(format, c.numberFormat); - } - - - /********************************************************************* - * Test methods - ********************************************************************/ - - @Test public void getNumberFormat_default() { - assertNotNull(converter.getNumberFormat()); - } - - @Test public void getNumberFormat_nonNullNumberFormat() { - NumberFormat nf = NumberFormat.getCurrencyInstance(); - converter = new PercentageStringConverter(nf); - assertEquals(nf, converter.getNumberFormat()); - } - - - /********************************************************************* - * Test toString / fromString methods - ********************************************************************/ - - @Test public void fromString_testValidStringInput() { - assertEquals(.1032, converter.fromString("10.32%")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace() { - assertEquals(.1032, converter.fromString(" 10.32% ")); - } - - @Test public void toString_validInput() { - assertEquals("10%", converter.toString(.10)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/PercentageStringConverterTest.java 2015-08-31 10:25:23.881216165 -0400 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.Locale; +import javafx.util.converter.LocalTimeStringConverterShim; +import javafx.util.converter.NumberStringConverterShim; +import javafx.util.converter.PercentageStringConverter; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class PercentageStringConverterTest { + private PercentageStringConverter converter; + + @Before public void setup() { + converter = new PercentageStringConverter(Locale.US); + } + + /********************************************************************* + * Test constructors + ********************************************************************/ + + @Test public void testDefaultConstructor() { + PercentageStringConverter c = new PercentageStringConverter(); + assertEquals(Locale.getDefault(), NumberStringConverterShim.getLocale(c)); + assertNull(NumberStringConverterShim.getPattern(c)); + assertNull(NumberStringConverterShim.getNumberFormatVar(c)); + } + + @Test public void testConstructor_locale() { + PercentageStringConverter c = new PercentageStringConverter(Locale.CANADA); + assertEquals(Locale.CANADA, NumberStringConverterShim.getLocale(c)); + assertNull(NumberStringConverterShim.getPattern(c)); + assertNull(NumberStringConverterShim.getNumberFormatVar(c)); + } + + @Test public void testConstructor_numberFormat() { + NumberFormat format = NumberFormat.getCurrencyInstance(Locale.JAPAN); + PercentageStringConverter c = new PercentageStringConverter(format); + assertNull(NumberStringConverterShim.getLocale(c)); + assertNull(NumberStringConverterShim.getPattern(c)); + assertEquals(format, NumberStringConverterShim.getNumberFormatVar(c)); + } + + + /********************************************************************* + * Test methods + ********************************************************************/ + + @Test public void getNumberFormat_default() { + assertNotNull(NumberStringConverterShim.getNumberFormat(converter)); + } + + @Test public void getNumberFormat_nonNullNumberFormat() { + NumberFormat nf = NumberFormat.getCurrencyInstance(); + converter = new PercentageStringConverter(nf); + assertEquals(nf, NumberStringConverterShim.getNumberFormat(converter)); + } + + + /********************************************************************* + * Test toString / fromString methods + ********************************************************************/ + + @Test public void fromString_testValidStringInput() { + assertEquals(.1032, converter.fromString("10.32%")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace() { + assertEquals(.1032, converter.fromString(" 10.32% ")); + } + + @Test public void toString_validInput() { + assertEquals("10%", converter.toString(.10)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/ShortStringConverterTest.java 2015-08-31 10:25:24.713216156 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class ShortStringConverterTest { - private ShortStringConverter converter; - - private final short shortValue_10 = 10; - - @Before public void setup() { - converter = new ShortStringConverter(); - } - - @Test public void fromString_testValidStringInput() { - assertEquals((Object)shortValue_10, converter.fromString("10")); - } - - @Test public void fromString_testValidStringInputWithWhiteSpace() { - assertEquals((Object)shortValue_10, converter.fromString(" 10 ")); - } - - @Test public void toString_testStringInput() { - assertEquals("10", converter.toString(shortValue_10)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/ShortStringConverterTest.java 2015-08-31 10:25:24.577216157 -0400 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import javafx.util.converter.ShortStringConverter; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + */ +public class ShortStringConverterTest { + private ShortStringConverter converter; + + private final short shortValue_10 = 10; + + @Before public void setup() { + converter = new ShortStringConverter(); + } + + @Test public void fromString_testValidStringInput() { + assertEquals((Object)shortValue_10, converter.fromString("10")); + } + + @Test public void fromString_testValidStringInputWithWhiteSpace() { + assertEquals((Object)shortValue_10, converter.fromString(" 10 ")); + } + + @Test public void toString_testStringInput() { + assertEquals("10", converter.toString(shortValue_10)); + } +} --- old/modules/base/src/test/java/javafx/util/converter/TimeStringConverterTest.java 2015-08-31 10:25:25.329216149 -0400 +++ /dev/null 2015-08-30 16:31:40.093001923 -0400 @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.util.converter; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -/** - */ -@RunWith(Parameterized.class) -public class TimeStringConverterTest { - private static final Date VALID_TIME_WITH_SECONDS; - private static final Date VALID_TIME_WITHOUT_SECONDS; - - static { - TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - Calendar c = Calendar.getInstance(); - c.clear(); - c.set(Calendar.HOUR_OF_DAY, 12); - c.set(Calendar.MINUTE, 34); - c.set(Calendar.SECOND, 56); - VALID_TIME_WITH_SECONDS = c.getTime(); - c.set(Calendar.SECOND, 0); - VALID_TIME_WITHOUT_SECONDS = c.getTime(); - } - - @Parameterized.Parameters public static Collection implementations() { - return Arrays.asList(new Object[][] { - { new TimeStringConverter(), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, - VALID_TIME_WITH_SECONDS, null, null }, - - { new TimeStringConverter(DateFormat.SHORT), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.SHORT, - VALID_TIME_WITHOUT_SECONDS, null, null }, - - { new TimeStringConverter(Locale.UK), - Locale.UK, DateFormat.DEFAULT, - VALID_TIME_WITH_SECONDS, null, null }, - - { new TimeStringConverter(Locale.UK, DateFormat.SHORT), - Locale.UK, DateFormat.SHORT, - VALID_TIME_WITHOUT_SECONDS, null, null }, - - { new TimeStringConverter("HH mm ss"), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, - VALID_TIME_WITH_SECONDS, "HH mm ss", null }, - - { new TimeStringConverter(DateFormat.getTimeInstance(DateFormat.FULL)), - Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, - VALID_TIME_WITH_SECONDS, null, DateFormat.getTimeInstance(DateFormat.FULL) }, - }); - } - - private TimeStringConverter converter; - private Locale locale; - private int timeStyle; - private String pattern; - private DateFormat dateFormat; - private Date validDate; - private DateFormat validFormatter; - - public TimeStringConverterTest(TimeStringConverter converter, Locale locale, int timeStyle, Date validDate, String pattern, DateFormat dateFormat) { - this.converter = converter; - this.locale = locale; - this.timeStyle = timeStyle; - this.validDate = validDate; - this.pattern = pattern; - this.dateFormat = dateFormat; - - if (dateFormat != null) { - validFormatter = dateFormat; - } else if (pattern != null) { - validFormatter = new SimpleDateFormat(pattern); - } else { - validFormatter = DateFormat.getTimeInstance(timeStyle, locale); - } - } - - @Before public void setup() { - } - - /********************************************************************* - * Test constructors - ********************************************************************/ - - @Test public void testConstructor() { - assertEquals(locale, converter.locale); - assertEquals(timeStyle, converter.timeStyle); - assertEquals(pattern, converter.pattern); - assertEquals(dateFormat, converter.dateFormat); - } - - - /********************************************************************* - * Test methods - ********************************************************************/ - - @Test public void getDateFormat() { - assertNotNull(converter.getDateFormat()); - } - - @Test public void getDateFormat_nonNullPattern() { - converter = new TimeStringConverter("HH"); - assertTrue(converter.getDateFormat() instanceof SimpleDateFormat); - } - - - /********************************************************************* - * Test toString / fromString methods - ********************************************************************/ - - @Test public void fromString_testValidInput() { - String input = validFormatter.format(validDate); - assertEquals("Input = "+input, validDate, converter.fromString(input)); - } - - @Test public void fromString_testValidInputWithWhiteSpace() { - String input = validFormatter.format(validDate); - assertEquals("Input = "+input, validDate, converter.fromString(" " + input + " ")); - } - - @Test(expected=RuntimeException.class) - public void fromString_testInvalidInput() { - converter.fromString("abcdefg"); - } - - @Test public void toString_validOutput() { - assertEquals(validFormatter.format(validDate), converter.toString(validDate)); - } -} --- /dev/null 2015-08-30 16:31:40.093001923 -0400 +++ new/modules/base/src/test/java/test/javafx/util/converter/TimeStringConverterTest.java 2015-08-31 10:25:25.197216150 -0400 @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.util.converter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; +import javafx.util.converter.LocalTimeStringConverterShim; +import javafx.util.converter.DateTimeStringConverterShim; +import javafx.util.converter.TimeStringConverter; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + */ +@RunWith(Parameterized.class) +public class TimeStringConverterTest { + private static final Date VALID_TIME_WITH_SECONDS; + private static final Date VALID_TIME_WITHOUT_SECONDS; + + static { + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + Calendar c = Calendar.getInstance(); + c.clear(); + c.set(Calendar.HOUR_OF_DAY, 12); + c.set(Calendar.MINUTE, 34); + c.set(Calendar.SECOND, 56); + VALID_TIME_WITH_SECONDS = c.getTime(); + c.set(Calendar.SECOND, 0); + VALID_TIME_WITHOUT_SECONDS = c.getTime(); + } + + @Parameterized.Parameters public static Collection implementations() { + return Arrays.asList(new Object[][] { + { new TimeStringConverter(), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, + VALID_TIME_WITH_SECONDS, null, null }, + + { new TimeStringConverter(DateFormat.SHORT), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.SHORT, + VALID_TIME_WITHOUT_SECONDS, null, null }, + + { new TimeStringConverter(Locale.UK), + Locale.UK, DateFormat.DEFAULT, + VALID_TIME_WITH_SECONDS, null, null }, + + { new TimeStringConverter(Locale.UK, DateFormat.SHORT), + Locale.UK, DateFormat.SHORT, + VALID_TIME_WITHOUT_SECONDS, null, null }, + + { new TimeStringConverter("HH mm ss"), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, + VALID_TIME_WITH_SECONDS, "HH mm ss", null }, + + { new TimeStringConverter(DateFormat.getTimeInstance(DateFormat.FULL)), + Locale.getDefault(Locale.Category.FORMAT), DateFormat.DEFAULT, + VALID_TIME_WITH_SECONDS, null, DateFormat.getTimeInstance(DateFormat.FULL) }, + }); + } + + private TimeStringConverter converter; + private Locale locale; + private int timeStyle; + private String pattern; + private DateFormat dateFormat; + private Date validDate; + private DateFormat validFormatter; + + public TimeStringConverterTest(TimeStringConverter converter, Locale locale, int timeStyle, Date validDate, String pattern, DateFormat dateFormat) { + this.converter = converter; + this.locale = locale; + this.timeStyle = timeStyle; + this.validDate = validDate; + this.pattern = pattern; + this.dateFormat = dateFormat; + + if (dateFormat != null) { + validFormatter = dateFormat; + } else if (pattern != null) { + validFormatter = new SimpleDateFormat(pattern); + } else { + validFormatter = DateFormat.getTimeInstance(timeStyle, locale); + } + } + + @Before public void setup() { + } + + /********************************************************************* + * Test constructors + ********************************************************************/ + + @Test public void testConstructor() { + assertEquals(locale, DateTimeStringConverterShim.getLocale(converter)); + assertEquals(timeStyle, DateTimeStringConverterShim.getTimeStyle(converter)); + assertEquals(pattern, DateTimeStringConverterShim.getPattern(converter)); + assertEquals(dateFormat, DateTimeStringConverterShim.getDateFormatVar(converter)); + } + + + /********************************************************************* + * Test methods + ********************************************************************/ + + @Test public void getDateFormat() { + assertNotNull(DateTimeStringConverterShim.getDateFormat(converter)); + } + + @Test public void getDateFormat_nonNullPattern() { + converter = new TimeStringConverter("HH"); + assertTrue(DateTimeStringConverterShim.getDateFormat(converter) + instanceof SimpleDateFormat); + } + + + /********************************************************************* + * Test toString / fromString methods + ********************************************************************/ + + @Test public void fromString_testValidInput() { + String input = validFormatter.format(validDate); + assertEquals("Input = "+input, validDate, converter.fromString(input)); + } + + @Test public void fromString_testValidInputWithWhiteSpace() { + String input = validFormatter.format(validDate); + assertEquals("Input = "+input, validDate, converter.fromString(" " + input + " ")); + } + + @Test(expected=RuntimeException.class) + public void fromString_testInvalidInput() { + converter.fromString("abcdefg"); + } + + @Test public void toString_validOutput() { + assertEquals(validFormatter.format(validDate), converter.toString(validDate)); + } +}