Skip to main content
summaryrefslogtreecommitdiffstats
blob: 86f36f8ba32ee1d0eddc36c8fa9e2e40330ff22d (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*******************************************************************************
 * Copyright (c) 2010, 2019 IBM Corporation and others.
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.test.util.mock;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;

public class MockMarker implements IMarker
{
    private final Map<String, Object> _attributes = new HashMap<String, Object>();
    private final IResource _resource;

    public MockMarker(final IResource resource)
    {
        _resource = resource;
    }

    public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter)
    {
        throw new UnsupportedOperationException();

    }

    public void delete() throws CoreException
    {
        throw new UnsupportedOperationException();

    }

    public boolean exists()
    {
        return true;
    }

    public Object getAttribute(String attributeName) throws CoreException
    {
        return _attributes.get(attributeName);
    }

    public int getAttribute(String attributeName, int defaultValue)
    {
        Object object = _attributes.get(attributeName);
        if (object instanceof Integer)
        {
            return ((Integer)object).intValue();
        }
        return defaultValue;
    }

    public String getAttribute(String attributeName, String defaultValue)
    {
        Object object = _attributes.get(attributeName);
        if (object instanceof String)
        {
            return ((String)object);
        }
        return defaultValue;
    }

    public boolean getAttribute(String attributeName, boolean defaultValue)
    {
        Object object = _attributes.get(attributeName);
        if (object instanceof Boolean)
        {
            return ((Boolean)object).booleanValue();
        }
        return defaultValue;
    }

    public Map<String, Object> getAttributes() throws CoreException
    {
        return Collections.unmodifiableMap(_attributes);
    }

    public Object[] getAttributes(String[] attributeNames) throws CoreException
    {
        throw new UnsupportedOperationException();

    }

    public long getCreationTime() throws CoreException
    {
        throw new UnsupportedOperationException();
    }

    public long getId()
    {
        throw new UnsupportedOperationException();
    }

    public IResource getResource()
    {
        return _resource;
    }

    public String getType() throws CoreException
    {
        throw new UnsupportedOperationException();

    }

    public boolean isSubtypeOf(String superType) throws CoreException
    {
        throw new UnsupportedOperationException();
    }

    public void setAttribute(String attributeName, int value)
            throws CoreException
    {
        setAttribute(attributeName, Integer.valueOf(value));
    }

    public void setAttribute(String attributeName, Object value)
            throws CoreException
    {
        _attributes.put(attributeName, value);
    }

    public void setAttribute(String attributeName, boolean value)
            throws CoreException
    {
        setAttribute(attributeName, Boolean.valueOf(value));
    }

    public void setAttributes(String[] attributeNames, Object[] values)
            throws CoreException
    {
        throw new UnsupportedOperationException();

    }

    @SuppressWarnings("unchecked")
    public void setAttributes(@SuppressWarnings("rawtypes") Map attributes)
            throws CoreException
    {
        _attributes.putAll(attributes);
    }

}

Back to the top