• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / learnlib / 6433387082

06 Oct 2023 03:10PM UTC coverage: 92.296% (-0.007%) from 92.303%
6433387082

push

github

mtf90
update Falk's developer id

11573 of 12539 relevant lines covered (92.3%)

1.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/drivers/basic/src/main/java/de/learnlib/drivers/reflect/SimplePOJODataMapper.java
1
/* Copyright (C) 2013-2023 TU Dortmund
2
 * This file is part of LearnLib, http://www.learnlib.de/.
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 de.learnlib.drivers.reflect;
17

18
import java.lang.reflect.Constructor;
19
import java.lang.reflect.InvocationTargetException;
20
import java.util.HashMap;
21

22
import de.learnlib.api.exception.SULException;
23
import de.learnlib.mapper.api.SULMapper;
24
import org.checkerframework.checker.nullness.qual.Nullable;
25

26
/**
27
 * Basic stateless data mapper for objects.
28
 */
29
public class SimplePOJODataMapper
2✔
30
        implements SULMapper<MethodInput, MethodOutput, ConcreteMethodInput, @Nullable Object> {
31

32
    private final Constructor<?> initMethod;
33
    private final Object[] initParams;
34

35
    protected @Nullable Object delegate;
36

37
    protected SimplePOJODataMapper(Constructor<?> initMethod, Object... initParams) {
2✔
38
        this.initMethod = initMethod;
2✔
39
        this.initParams = initParams;
2✔
40
    }
2✔
41

42
    // RuntimeExceptions are the type of exceptions we allow to handle, therefore we should throw them
43
    @SuppressWarnings({"PMD.AvoidThrowingRawExceptionTypes", "PMD.PreserveStackTrace"})
44
    @Override
45
    public void pre() {
46
        try {
47
            delegate = initMethod.newInstance(initParams);
2✔
48
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) {
×
49
            throw new RuntimeException(e);
×
50
        } catch (InvocationTargetException e) {
×
51
            throw new SULException(e.getCause());
×
52
        }
2✔
53
    }
2✔
54

55
    @Override
56
    public void post() {
57
        delegate = null;
2✔
58
    }
2✔
59

60
    @Override
61
    public MappedException<? extends MethodOutput> mapUnwrappedException(RuntimeException exception) {
62
        final Throwable cause = exception.getCause();
2✔
63
        return MappedException.repeatOutput(new Error(cause != null ? cause : exception), Unobserved.INSTANCE);
2✔
64
    }
65

66
    @Override
67
    public ConcreteMethodInput mapInput(MethodInput abstractInput) {
68
        assert delegate != null;
2✔
69
        return new ConcreteMethodInput(abstractInput, new HashMap<>(), delegate);
2✔
70
    }
71

72
    @Override
73
    public MethodOutput mapOutput(@Nullable Object concreteOutput) {
74
        return new ReturnValue(concreteOutput);
2✔
75
    }
76

77
    @Override
78
    public boolean canFork() {
79
        return true;
×
80
    }
81

82
    @Override
83
    public SULMapper<MethodInput, MethodOutput, ConcreteMethodInput, @Nullable Object> fork() {
84
        return new SimplePOJODataMapper(initMethod, initParams);
×
85
    }
86

87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc