|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2024 Eclipse Foundation 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 | + * Eclipse Foundation - initial API and implementation |
| 13 | + *******************************************************************************/ |
| 14 | +package org.eclipse.search.tests; |
| 15 | + |
| 16 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 17 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 18 | + |
| 19 | +import org.eclipse.core.runtime.CoreException; |
| 20 | +import org.eclipse.search2.internal.ui.basic.views.GlobalNextPrevSearchEntryHandler; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +/** |
| 24 | + * Integration tests for {@link GlobalNextPrevSearchEntryHandler}. |
| 25 | + * These tests verify the basic functionality and integration points. |
| 26 | + * |
| 27 | + * @since 3.17 |
| 28 | + */ |
| 29 | +public class GlobalNextPrevSearchEntryHandlerIntegrationTest { |
| 30 | + |
| 31 | + /** |
| 32 | + * Test that the handler can be created and configured properly. |
| 33 | + * This test verifies the basic instantiation and configuration functionality. |
| 34 | + */ |
| 35 | + @Test |
| 36 | + public void testHandlerCreationAndConfiguration() throws CoreException { |
| 37 | + // Test Next handler |
| 38 | + GlobalNextPrevSearchEntryHandler nextHandler = new GlobalNextPrevSearchEntryHandler(); |
| 39 | + assertNotNull(nextHandler, "Next handler should be created successfully"); |
| 40 | + |
| 41 | + // Configure for next command (default behavior) |
| 42 | + nextHandler.setInitializationData(null, "command", "next"); |
| 43 | + // No exception should be thrown |
| 44 | + |
| 45 | + // Test Previous handler |
| 46 | + GlobalNextPrevSearchEntryHandler prevHandler = new GlobalNextPrevSearchEntryHandler(); |
| 47 | + assertNotNull(prevHandler, "Previous handler should be created successfully"); |
| 48 | + |
| 49 | + // Configure for previous command |
| 50 | + prevHandler.setInitializationData(null, "command", "previous"); |
| 51 | + // No exception should be thrown |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Test that the handler handles various configuration scenarios correctly. |
| 56 | + */ |
| 57 | + @Test |
| 58 | + public void testHandlerConfigurationScenarios() throws CoreException { |
| 59 | + GlobalNextPrevSearchEntryHandler handler = new GlobalNextPrevSearchEntryHandler(); |
| 60 | + |
| 61 | + // Test with null configuration |
| 62 | + handler.setInitializationData(null, null, null); |
| 63 | + // Should not throw exception |
| 64 | + |
| 65 | + // Test with empty string |
| 66 | + handler.setInitializationData(null, "", ""); |
| 67 | + // Should not throw exception |
| 68 | + |
| 69 | + // Test with unknown command type |
| 70 | + handler.setInitializationData(null, "command", "unknown"); |
| 71 | + // Should not throw exception and should default to next behavior |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Test that the handler implements the required interfaces. |
| 76 | + */ |
| 77 | + @Test |
| 78 | + public void testHandlerInterfaceImplementation() { |
| 79 | + GlobalNextPrevSearchEntryHandler handler = new GlobalNextPrevSearchEntryHandler(); |
| 80 | + |
| 81 | + // Verify it implements IHandler |
| 82 | + assertTrue(handler instanceof org.eclipse.core.commands.IHandler, |
| 83 | + "Handler should implement IHandler interface"); |
| 84 | + |
| 85 | + // Verify it implements IExecutableExtension |
| 86 | + assertTrue(handler instanceof org.eclipse.core.runtime.IExecutableExtension, |
| 87 | + "Handler should implement IExecutableExtension interface"); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Test that multiple handler instances can be created independently. |
| 92 | + */ |
| 93 | + @Test |
| 94 | + public void testMultipleHandlerInstances() throws CoreException { |
| 95 | + // Create multiple handlers |
| 96 | + GlobalNextPrevSearchEntryHandler handler1 = new GlobalNextPrevSearchEntryHandler(); |
| 97 | + GlobalNextPrevSearchEntryHandler handler2 = new GlobalNextPrevSearchEntryHandler(); |
| 98 | + GlobalNextPrevSearchEntryHandler handler3 = new GlobalNextPrevSearchEntryHandler(); |
| 99 | + |
| 100 | + // Configure them differently |
| 101 | + handler1.setInitializationData(null, "command", "next"); |
| 102 | + handler2.setInitializationData(null, "command", "previous"); |
| 103 | + handler3.setInitializationData(null, "command", "unknown"); |
| 104 | + |
| 105 | + // All should be created and configured without issues |
| 106 | + assertNotNull(handler1); |
| 107 | + assertNotNull(handler2); |
| 108 | + assertNotNull(handler3); |
| 109 | + } |
| 110 | +} |
0 commit comments