summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/io/FatalErrorHandlerTestCase.java
blob: 1999323af6bb8f398a576301cc957efd7c5db273 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.io;

import static org.junit.Assert.*;

import java.security.Permission;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Just to remove noise from the coverage report.
 *
 * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
 */
public class FatalErrorHandlerTestCase {
    private static final class AvoidExiting extends SecurityManager {

        @Override
        public void checkPermission(Permission perm) {
        }

        @Override
        public void checkExit(int status) {
            throw new SecurityException();
        }

    }

    private FatalErrorHandler h;

    @Before
    public void setUp() throws Exception {
        h = new FatalErrorHandler();
        System.setSecurityManager(new AvoidExiting());
    }

    @After
    public void tearDown() throws Exception {
        System.setSecurityManager(null);
    }

    @Test
    public final void testHandle() {
        boolean caught = false;
        try {
            h.handle(new Throwable(), "abc");
        } catch (SecurityException e) {
            caught = true;
        }
        assertTrue(caught);
    }

}