6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.concurrent;
27
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.concurrent.atomic.AtomicBoolean;
31 import javafx.beans.value.ChangeListener;
32 import javafx.beans.value.ObservableValue;
33 import javafx.concurrent.mocks.EpicFailTask;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.junit.runners.Parameterized;
37
38 import static org.junit.Assert.*;
39
40 /**
41 * This tests that state is correct when a Task throws an exception partway through.
42 * In this particular case, the progress is updated to 50% before the exception
43 * occurs.
44 */
45 @RunWith(Parameterized.class)
46 public class ServiceExceptionTest extends ServiceTestBase {
47 @Parameterized.Parameters public static Collection implementations() {
48 return Arrays.asList(new Object[][]{
49 { new Exception("Exception") },
50 { new IllegalArgumentException("IAE") },
51 { new NullPointerException("NPE") },
52 { new RuntimeException("RuntimeException") }
53 });
54 }
55
56 private Exception exception;
57
58 public ServiceExceptionTest(Exception th) {
59 this.exception = th;
60 }
61
62 @Override protected TestServiceFactory setupServiceFactory() {
63 return new TestServiceFactory() {
64 @Override protected AbstractTask createTestTask() {
65 return new EpicFailTask(ServiceExceptionTest.this.exception);
66 }
67 };
68 }
69
70 /************************************************************************
71 * Run the concurrent and check that the exception property is set, and that
72 * the value property is null. The progress fields may be in some
73 * arbitrary state.
74 ***********************************************************************/
75
76 /**
77 * Whenever the exception occurs we should have the exception property set
78 */
79 @Test public void exceptionShouldBeSet() {
80 service.start();
81 handleEvents();
82 assertSame(exception, service.getException());
83 assertSame(exception, service.exceptionProperty().get());
84 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.javafx.concurrent;
27
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.concurrent.atomic.AtomicBoolean;
31 import javafx.beans.value.ChangeListener;
32 import javafx.beans.value.ObservableValue;
33 import javafx.concurrent.Worker;
34 import test.javafx.concurrent.mocks.EpicFailTask;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.junit.runners.Parameterized;
38
39 import static org.junit.Assert.*;
40
41 /**
42 * This tests that state is correct when a Task throws an exception partway through.
43 * In this particular case, the progress is updated to 50% before the exception
44 * occurs.
45 */
46 @RunWith(Parameterized.class)
47 public class ServiceExceptionTest extends ServiceTestBase {
48 @Parameterized.Parameters public static Collection implementations() {
49 return Arrays.asList(new Object[][]{
50 { new Exception("Exception") },
51 { new IllegalArgumentException("IAE") },
52 { new NullPointerException("NPE") },
53 { new RuntimeException("RuntimeException") }
54 });
55 }
56
57 private Exception exception;
58
59 public ServiceExceptionTest(Exception th) {
60 this.exception = th;
61 }
62
63 @Override protected TestServiceFactory setupServiceFactory() {
64 return new TestServiceFactory() {
65 @Override public AbstractTask createTestTask() {
66 return new EpicFailTask(ServiceExceptionTest.this.exception);
67 }
68 };
69 }
70
71 /************************************************************************
72 * Run the concurrent and check that the exception property is set, and that
73 * the value property is null. The progress fields may be in some
74 * arbitrary state.
75 ***********************************************************************/
76
77 /**
78 * Whenever the exception occurs we should have the exception property set
79 */
80 @Test public void exceptionShouldBeSet() {
81 service.start();
82 handleEvents();
83 assertSame(exception, service.getException());
84 assertSame(exception, service.exceptionProperty().get());
85 }
|