Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
11   66   6   2.2
2   27   0.55   5
5     1.2  
1    
 
  TestTerminator       Line # 25 11 0% 6 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Jul 19, 2008
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2008-2010 the original author or authors.
15    */
16    package org.fest.swing.core;
17   
18    import static org.fest.swing.util.AWTExceptionHandlerInstaller.installAWTExceptionHandler;
19   
20    /**
21    * Understands terminating running FEST-Swing tests.
22    *
23    * @author <a href="mailto:simeon.fitch@mseedsoft.com">Simeon H.K. Fitch</a>
24    */
 
25    class TestTerminator {
26   
27    private final ThreadsSource threadsSource;
28    private final FrameDisposer frameDisposer;
29    private final MainThreadIdentifier mainThreadIdentifier;
30   
 
31  5 toggle TestTerminator() {
32  5 this(new ThreadsSource(), new FrameDisposer(), new MainThreadIdentifier());
33    }
34   
 
35  7 toggle TestTerminator(ThreadsSource threadsSource, FrameDisposer frameDisposer, MainThreadIdentifier mainThreadIdentifier) {
36  7 this.threadsSource = threadsSource;
37  7 this.frameDisposer = frameDisposer;
38  7 this.mainThreadIdentifier = mainThreadIdentifier;
39    }
40   
41    /*
42    * We do three things to signal an abort.
43    * 1) sent an interrupt signal to main thread
44    * 2) dispose all available frames.
45    * 3) throw RuntimeException on AWT event thread
46    */
 
47  2 toggle void terminateTests() {
48  2 pokeMainThread();
49  2 frameDisposer.disposeFrames();
50  2 throw new RuntimeException("User aborted FEST-Swing tests");
51    }
52   
53    /*
54    * Calls {@link Thread#interrupt()} on main thread in attempt to interrupt current FEST operation. Only affects thread
55    * if it is in a {@link Object#wait()} or {@link Thread#sleep(long)} method.
56    */
 
57  2 toggle private void pokeMainThread() {
58  2 Thread mainThread = mainThreadIdentifier.mainThreadIn(threadsSource.allThreads());
59  1 if (mainThread != null) mainThread.interrupt();
60    }
61   
 
62  6 toggle static {
63    // Make sure there's an exception handler that will dump a stack trace on abort.
64  6 installAWTExceptionHandler(SimpleFallbackExceptionHandler.class);
65    }
66    }