1 /*******************************************************************************
2  * Copyright (c) 2009, 2018 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.pde.api.tools.problems.tests;
15 
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertNotNull;
19 
20 import org.eclipse.pde.api.tools.internal.problems.ApiProblemFactory;
21 import org.eclipse.pde.api.tools.internal.problems.ApiProblemFilter;
22 import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor;
23 import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem;
24 import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemFilter;
25 import org.junit.Test;
26 
27 /**
28  * Tests the {@link org.eclipse.pde.api.tools.internal.problems.ApiProblemFilter} class
29  *
30  * @since 1.0.1
31  */
32 public class ApiFilterTests {
33 
34 	/**
35 	 * Tests the {@link ApiProblemFilter#toString()} method
36 	 */
37 	@Test
testToString()38 	public void testToString() {
39 		IApiProblem problem = ApiProblemFactory.newApiBaselineProblem("", null, null, IElementDescriptor.RESOURCE, IApiProblem.API_BASELINE_MISSING); //$NON-NLS-1$
40 		ApiProblemFilter filter = new ApiProblemFilter("comp.id", problem, null); //$NON-NLS-1$
41 		assertNotNull("The toString should not return null", filter.toString()); //$NON-NLS-1$
42 	}
43 
44 	/**
45 	 * Tests the {@link ApiProblemFilter#equals(Object)} method
46 	 */
47 	@Test
testEquals()48 	public void testEquals() {
49 		IApiProblem problem = ApiProblemFactory.newApiBaselineProblem("path", new String[] {"one"}, new String[] {"one"}, IElementDescriptor.RESOURCE, IApiProblem.API_BASELINE_MISSING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
50 		IApiProblemFilter filter1 = new ApiProblemFilter("comp.id", problem, null); //$NON-NLS-1$
51 		IApiProblemFilter filter2 = new ApiProblemFilter("comp.id", problem, null); //$NON-NLS-1$
52 		assertEquals("the filters should be equal", filter1, filter2); //$NON-NLS-1$
53 		assertEquals("the filters should be equal", filter2, filter1); //$NON-NLS-1$
54 		assertEquals("the filter should be equal to the problem", filter1, problem); //$NON-NLS-1$
55 		assertEquals("the filter should be equal to the problem", filter2, problem); //$NON-NLS-1$
56 		assertFalse("The filter should not be equal to the Object", filter1.equals(new Object())); //$NON-NLS-1$
57 		assertFalse("The filter should not be equal to the Object", new Object().equals(filter1)); //$NON-NLS-1$
58 		filter1 = new ApiProblemFilter(null, problem, null);
59 		filter2 = new ApiProblemFilter(null, problem, null);
60 		assertEquals("the filters should be equal", filter1, filter2); //$NON-NLS-1$
61 		assertEquals("the filters should be equal", filter2, filter1); //$NON-NLS-1$
62 	}
63 
64 	/**
65 	 * Tests the {@link ApiProblemFilter#clone()} method
66 	 */
67 	@Test
testClone()68 	public void testClone() {
69 		IApiProblem problem = ApiProblemFactory.newApiBaselineProblem("path", new String[] {"one"}, new String[] {"one"}, IElementDescriptor.RESOURCE, IApiProblem.API_BASELINE_MISSING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
70 		ApiProblemFilter filter1 = new ApiProblemFilter("comp.id", problem, null); //$NON-NLS-1$
71 		IApiProblemFilter filter2 = (IApiProblemFilter) filter1.clone();
72 		assertEquals("the filters should be equal", filter1, filter2); //$NON-NLS-1$
73 		assertEquals("the filters should be equal", filter2, filter1); //$NON-NLS-1$
74 		assertEquals("the filter should be equal to the problem", filter1, problem); //$NON-NLS-1$
75 		assertEquals("the filter should be equal to the problem", filter2, problem); //$NON-NLS-1$
76 	}
77 }
78