blob: 6587b323c8241cc1c53ba90a169afd46e763e3b3 (
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
|
/*******************************************************************************
* Copyright (c) 2012 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.orcs.core.internal.attribute;
import static org.mockito.Mockito.when;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
/**
* Test Case for {@link AttributeDeletedFilter}
*
* @author Roberto E. Escobar
*/
public class AttributeFilterTest {
// @formatter:off
@SuppressWarnings("rawtypes")
@Mock private Attribute attribute;
// @formatter:on
private AttributeFilter filter1;
private AttributeFilter filter2;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
filter1 = Mockito.spy(new FilterMock());
filter2 = Mockito.spy(new FilterMock());
}
@Test
public void testAnd() throws OseeCoreException {
AttributeFilter andFilter = filter1.and(filter2);
when(filter1.accept(attribute)).thenReturn(true);
when(filter2.accept(attribute)).thenReturn(true);
Assert.assertTrue(andFilter.accept(attribute));
when(filter1.accept(attribute)).thenReturn(false);
when(filter2.accept(attribute)).thenReturn(true);
Assert.assertFalse(andFilter.accept(attribute));
when(filter1.accept(attribute)).thenReturn(true);
when(filter2.accept(attribute)).thenReturn(false);
Assert.assertFalse(andFilter.accept(attribute));
when(filter1.accept(attribute)).thenReturn(false);
when(filter2.accept(attribute)).thenReturn(false);
Assert.assertFalse(andFilter.accept(attribute));
}
@Test
public void testOr() throws OseeCoreException {
AttributeFilter orFilter = filter1.or(filter2);
when(filter1.accept(attribute)).thenReturn(true);
when(filter2.accept(attribute)).thenReturn(true);
Assert.assertTrue(orFilter.accept(attribute));
when(filter1.accept(attribute)).thenReturn(false);
when(filter2.accept(attribute)).thenReturn(true);
Assert.assertTrue(orFilter.accept(attribute));
when(filter1.accept(attribute)).thenReturn(true);
when(filter2.accept(attribute)).thenReturn(false);
Assert.assertTrue(orFilter.accept(attribute));
when(filter1.accept(attribute)).thenReturn(false);
when(filter2.accept(attribute)).thenReturn(false);
Assert.assertFalse(orFilter.accept(attribute));
}
public class FilterMock extends AttributeFilter {
@Override
public boolean accept(Attribute<?> attribute) {
return false;
}
};
}
|