DefaultJLibnotifyNotification.java

1
/*
2
 * Copyright 2019 Hector Espert.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package es.blackleg.jlibnotify.core;
17
18
import com.sun.jna.Pointer;
19
import es.blackleg.jlibnotify.JLibnotifyNotification;
20
import es.blackleg.jlibnotify.jna.GBoolean;
21
import es.blackleg.jlibnotify.jna.NativeLibnotify;
22
23
/**
24
 * Reference implementation of {@link JLibnotifyNotification}.
25
 *
26
 * <p>Holds the raw {@link Pointer} that {@code notify_notification_new} returned for this
27
 * notification and passes it to every native call. The pointer belongs to the libnotify session
28
 * that created it, so the notification must not be used after {@link DefaultJLibnotify#unInit()}.</p>
29
 *
30
 * <p>Instances are built by
31
 * {@link DefaultJLibnotify#createNotification(String, String, String)}; application code should
32
 * depend on the {@link JLibnotifyNotification} interface instead.</p>
33
 *
34
 * @author Hector Espert
35
 */
36
public class DefaultJLibnotifyNotification implements JLibnotifyNotification {
37
38
    private final Pointer pointer;
39
40
    private final NativeLibnotify nativeLibnotify;
41
42
    /**
43
     * Creates a notification over an existing native notification structure.
44
     *
45
     * @param pointer         pointer returned by {@code notify_notification_new}
46
     * @param nativeLibnotify the loaded native library the pointer belongs to
47
     */
48
    public DefaultJLibnotifyNotification(Pointer pointer, NativeLibnotify nativeLibnotify) {
49
        this.pointer = pointer;
50
        this.nativeLibnotify = nativeLibnotify;
51
    }
52
53
    @Override
54
    public void show() {
55 1 1. show : negated conditional → NO_COVERAGE
        if (nativeLibnotify.notify_notification_show(pointer, Pointer.NULL) == GBoolean.FALSE) {
56
            throw new RuntimeException("Error when show notification"); //TODO: Capture error and throw exception
57
        }
58
    }
59
60
    @Override
61
    public void setTimeOut(int timeout) {
62 1 1. setTimeOut : removed call to es/blackleg/jlibnotify/jna/NativeLibnotify::notify_notification_set_timeout → KILLED
        nativeLibnotify.notify_notification_set_timeout(pointer, timeout);
63
    }
64
65
    @Override
66
    public void update(String summary, String body, String icon) {
67 1 1. update : negated conditional → NO_COVERAGE
        if (nativeLibnotify.notify_notification_update(pointer, summary, body, icon) == GBoolean.FALSE) {
68
            throw new RuntimeException("Error when showing notification");
69
        }
70
    }
71
72
    @Override
73
    public void close() {
74 1 1. close : negated conditional → NO_COVERAGE
        if (nativeLibnotify.notify_notification_close(pointer, Pointer.NULL) == GBoolean.FALSE) {
75
            throw new RuntimeException("Error when show notification");
76
        }
77
    }
78
79
}

Mutations

55

1.1
Location : show
Killed by : none
negated conditional → NO_COVERAGE

62

1.1
Location : setTimeOut
Killed by : es.blackleg.jlibnotify.core.DefaultJLibnotifyTest.testSetTimeOut(es.blackleg.jlibnotify.core.DefaultJLibnotifyTest)
removed call to es/blackleg/jlibnotify/jna/NativeLibnotify::notify_notification_set_timeout → KILLED

67

1.1
Location : update
Killed by : none
negated conditional → NO_COVERAGE

74

1.1
Location : close
Killed by : none
negated conditional → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.30.0 support