Skip to main content
summaryrefslogtreecommitdiffstats
blob: e3e909794a28794a1fed87aa5a0083370bbd3812 (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
/*******************************************************************************
 * Copyright (c) 2007, 2008 Oracle. 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:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.core.tests.internal.utility.jdt;

import org.eclipse.jpt.core.internal.utility.jdt.DefaultAnnotationEditFormatter;
import org.eclipse.jpt.utility.internal.ClassTools;

public class DefaultAnnotationEditFormatterTests extends AnnotationTestCase {


	// ********** TestCase behavior **********

	public DefaultAnnotationEditFormatterTests(String name) {
		super(name);
	}


	// ********** tests **********

	public void testCommaLength() throws Exception {
		assertEquals(1, this.commaLength(","));
		assertEquals(1, this.commaLength(", "));
		assertEquals(1, this.commaLength(",   "));

		assertEquals(2, this.commaLength(" ,"));
		assertEquals(2, this.commaLength(" , "));
		assertEquals(2, this.commaLength(" ,   "));

		assertEquals(3, this.commaLength("  ,"));
		assertEquals(3, this.commaLength("  , "));
		assertEquals(3, this.commaLength("  ,   "));

		assertEquals(0, this.commaLength("  ,,,"));
		assertEquals(0, this.commaLength("  ,,, "));
		assertEquals(0, this.commaLength("  ,   ,"));

		assertEquals(0, this.commaLength("  ,x"));
		assertEquals(0, this.commaLength("  ,x "));
		assertEquals(0, this.commaLength("  ,   x"));

		assertEquals(0, this.commaLength("x  ,"));
		assertEquals(0, this.commaLength("x  , "));
		assertEquals(0, this.commaLength("x  ,   "));
	}

	private int commaLength(String s) {
		Integer len = (Integer) ClassTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "commaLength", String.class, s);
		return len.intValue();
	}

	public void testStringIsAnnotation() throws Exception {
		assertTrue(this.stringIsAnnotation("@F"));
		assertTrue(this.stringIsAnnotation("@Foo"));
		assertTrue(this.stringIsAnnotation("@org.bar.Foo"));

		assertFalse(this.stringIsAnnotation(""));
		assertFalse(this.stringIsAnnotation("@"));
		assertFalse(this.stringIsAnnotation("Foo"));
		assertFalse(this.stringIsAnnotation("Foo@"));
	}

	private boolean stringIsAnnotation(String s) {
		Boolean b = (Boolean) ClassTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "stringIsAnnotation", String.class, s);
		return b.booleanValue();
	}

}

Back to the top