|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.equinox.frameworkadmin.tests; |
| 12 |
|
| 13 |
import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData; |
| 14 |
|
| 15 |
import junit.framework.TestCase; |
| 16 |
|
| 17 |
/** |
| 18 |
* @since 1.0 |
| 19 |
*/ |
| 20 |
public class LauncherDataTest extends TestCase { |
| 21 |
|
| 22 |
/* |
| 23 |
* Constructor for the class. |
| 24 |
*/ |
| 25 |
public LauncherDataTest(String name) { |
| 26 |
super(name); |
| 27 |
} |
| 28 |
|
| 29 |
public void testRemoveProgramArg() { |
| 30 |
LauncherData data = new LauncherData("equinox", "1.0", "eclipse", "1.0"); |
| 31 |
data.setProgramArgs(new String[] {"-console", "-startup", "foo"}); |
| 32 |
data.removeProgramArg("-startup"); |
| 33 |
assertEquals("1.0", new String[] {"-console"}, data.getProgramArgs()); |
| 34 |
|
| 35 |
data.setProgramArgs(null); |
| 36 |
data.setProgramArgs(new String[] {"-console", "-startup", "foo", "-bar"}); |
| 37 |
data.removeProgramArg("-startup"); |
| 38 |
assertEquals("2.0", new String[] {"-console", "-bar"}, data.getProgramArgs()); |
| 39 |
|
| 40 |
data.setProgramArgs(null); |
| 41 |
data.setProgramArgs(new String[] {"-startup", "foo"}); |
| 42 |
data.removeProgramArg("-startup"); |
| 43 |
assertEquals("3.0", new String[0], data.getProgramArgs()); |
| 44 |
|
| 45 |
data.setProgramArgs(null); |
| 46 |
data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar"}); |
| 47 |
data.removeProgramArg("-startup"); |
| 48 |
assertEquals("4.0", new String[] {"-console"}, data.getProgramArgs()); |
| 49 |
|
| 50 |
data.setProgramArgs(null); |
| 51 |
data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar", "-xxx"}); |
| 52 |
data.removeProgramArg("-startup"); |
| 53 |
assertEquals("5.0", new String[] {"-console", "-xxx"}, data.getProgramArgs()); |
| 54 |
|
| 55 |
// arg which doesn't start with a dash - dont' consume anything but that specific arg |
| 56 |
data.setProgramArgs(null); |
| 57 |
data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar", "-xxx"}); |
| 58 |
data.removeProgramArg("foo"); |
| 59 |
assertEquals("6.0", new String[] {"-console", "-startup", "bar", "-xxx"}, data.getProgramArgs()); |
| 60 |
|
| 61 |
// non-matching arg |
| 62 |
data.setProgramArgs(null); |
| 63 |
data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar", "-xxx"}); |
| 64 |
data.removeProgramArg("zzz"); |
| 65 |
assertEquals("7.0", new String[] {"-console", "-startup", "foo", "bar", "-xxx"}, data.getProgramArgs()); |
| 66 |
|
| 67 |
// empty string |
| 68 |
data.setProgramArgs(null); |
| 69 |
data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar", "-xxx"}); |
| 70 |
data.removeProgramArg(""); |
| 71 |
assertEquals("8.0", new String[] {"-console", "-startup", "foo", "bar", "-xxx"}, data.getProgramArgs()); |
| 72 |
|
| 73 |
// just whitespace |
| 74 |
data.setProgramArgs(null); |
| 75 |
data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar", "-xxx"}); |
| 76 |
data.removeProgramArg(" "); |
| 77 |
assertEquals("9.0", new String[] {"-console", "-startup", "foo", "bar", "-xxx"}, data.getProgramArgs()); |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
/* |
| 82 |
* Compare the give 2 arrays and assert whether or not they should be considered equal. |
| 83 |
*/ |
| 84 |
public static void assertEquals(String message, String[] one, String[] two) { |
| 85 |
if (one == null) |
| 86 |
assertNull(message, two); |
| 87 |
if (two == null) |
| 88 |
fail(message); |
| 89 |
assertEquals(message, one.length, two.length); |
| 90 |
for (int i = 0; i < one.length; i++) |
| 91 |
assertEquals(message, one[i], two[i]); |
| 92 |
} |
| 93 |
} |