Skip to content

Commit fb59e04

Browse files
committed
Use status severity and codes in JDT model test assertions
1 parent c60ae50 commit fb59e04

4 files changed

Lines changed: 63 additions & 34 deletions

File tree

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ public void testVariableInitializerDeprecated() throws CoreException, IOExceptio
14081408
CompilerOptions.getFirstSupportedJavaVersion());
14091409
IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_DEPRECATED"), null, null);
14101410
IJavaModelStatus status = JavaConventions.validateClasspathEntry(project, variable, false);
1411-
assertStatus("Classpath variable 'TEST_DEPRECATED' in project 'P1' is deprecated: Test deprecated flag", status);
1411+
assertStatus(IStatus.WARNING, IJavaModelStatusConstants.DEPRECATED_VARIABLE, status);
14121412
assertFalse("Status should not be OK", status.isOK());
14131413
assertEquals("Status should have WARNING severity", IStatus.WARNING, status.getSeverity());
14141414
assertEquals("Status should have deprecated code", IJavaModelStatusConstants.DEPRECATED_VARIABLE, status.getCode());
@@ -1432,7 +1432,7 @@ public void testVariableInitializerUnboundAndDeprecated() throws CoreException {
14321432
IJavaProject project = createJavaProject("P1");
14331433
IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_DEPRECATED"), null, null);
14341434
IJavaModelStatus status = JavaConventions.validateClasspathEntry(project, variable, false);
1435-
assertStatus("Project 'P1' is missing required library: 'lib.jar'", status);
1435+
assertStatus(IStatus.ERROR, IJavaModelStatusConstants.INVALID_CLASSPATH, status);
14361436
assertFalse("Status should not be OK", status.isOK());
14371437
assertEquals("Status should have WARNING severity", IStatus.ERROR, status.getSeverity());
14381438
assertEquals("Status should have deprecated code", IJavaModelStatusConstants.INVALID_CLASSPATH, status.getCode());
@@ -1465,7 +1465,7 @@ public void testVariableInitializerReadOnly() throws CoreException, IOException
14651465
CompilerOptions.getFirstSupportedJavaVersion());
14661466
IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_READ_ONLY"), null, null);
14671467
IJavaModelStatus status = JavaConventions.validateClasspathEntry(project, variable, false);
1468-
assertStatus("OK", status);
1468+
assertStatus(IStatus.OK, status);
14691469
assertTrue("Status should be OK", status.isOK());
14701470
assertEquals("Status should be VERIFIED_OK", JavaModelStatus.VERIFIED_OK, status);
14711471
} finally {
@@ -1493,7 +1493,7 @@ public void testVariableInitializerDeprecatedAndReadOnly() throws CoreException,
14931493
CompilerOptions.getFirstSupportedJavaVersion());
14941494
IClasspathEntry variable = JavaCore.newVariableEntry(new Path("TEST_DEPRECATED_READ_ONLY"), null, null);
14951495
IJavaModelStatus status = JavaConventions.validateClasspathEntry(project, variable, false);
1496-
assertStatus("Classpath variable 'TEST_DEPRECATED_READ_ONLY' in project 'P1' is deprecated: A deprecated and read-only initializer", status);
1496+
assertStatus(IStatus.WARNING, IJavaModelStatusConstants.DEPRECATED_VARIABLE, status);
14971497
assertFalse("Status should not be OK", status.isOK());
14981498
assertEquals("Status should have WARNING severity", IStatus.WARNING, status.getSeverity());
14991499
assertEquals("Status should have deprecated code", IJavaModelStatusConstants.DEPRECATED_VARIABLE, status.getCode());

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.eclipse.jdt.internal.core.JavaProject;
5151
import org.eclipse.jdt.internal.core.UserLibraryClasspathContainer;
5252
import org.eclipse.jdt.internal.core.builder.State;
53-
import org.eclipse.jdt.internal.core.util.Messages;
5453
import org.eclipse.team.core.RepositoryProvider;
5554

5655
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -445,8 +444,8 @@ public void test232816f() throws Exception {
445444
IJavaModelStatus status = JavaConventions.validateClasspathEntry(p, newClasspath, true);
446445
assertStatus(
447446
"should have complained about jdk level mismatch",
448-
"Incompatible .class files version in required binaries. Project 'P' is targeting a " + firstVersion
449-
+ " runtime, but is compiled against \'" + getExternalJCLPath(latestVersion).makeRelative() + "' (from the container 'container/default') which requires a "+latestVersion+" runtime",
447+
IStatus.ERROR,
448+
IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL,
450449
status);
451450
} finally {
452451
deleteProject("P");
@@ -1934,7 +1933,8 @@ public void testClasspathValidation27() throws CoreException {
19341933

19351934
IJavaModelStatus status = JavaConventions.validateClasspathEntry(proj2, JavaCore.newProjectEntry(new Path("/P1")), false);
19361935
assertStatus(
1937-
"Incompatible .class files version in required binaries. Project \'P2\' is targeting a 1.1 runtime, but is compiled against \'P1\' which requires a " + CompilerOptions.getFirstSupportedJavaVersion() + " runtime",
1936+
IStatus.ERROR,
1937+
IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL,
19381938
status);
19391939
} finally {
19401940
deleteProjects(new String[]{"P1", "P2"});
@@ -2185,9 +2185,7 @@ public void testClasspathValidation36() throws CoreException {
21852185

21862186
IJavaModelStatus status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
21872187

2188-
assertStatus(
2189-
"OK",
2190-
status);
2188+
assertStatus(IStatus.OK, status);
21912189
} finally {
21922190
this.deleteProject("P");
21932191
}
@@ -7099,7 +7097,8 @@ public void testBug287164() throws CoreException {
70997097
status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
71007098
assertTrue(status.isOK());
71017099
assertStatus(
7102-
"Source folder \'src\' in project \'P\' cannot output to distinct source folder \'src2\'",
7100+
IStatus.OK,
7101+
IJavaModelStatusConstants.OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE,
71037102
status);
71047103

71057104
assertBuildPathMarkers("Unexpected markers",
@@ -7115,14 +7114,16 @@ public void testBug287164() throws CoreException {
71157114
status = JavaConventions.validateClasspath(proj, newCP2, proj.getOutputLocation());
71167115
assertFalse(status.isOK());
71177116
assertStatus(
7118-
"Source folder \'src2\' in project 'P' cannot output to library \'lib2\'",
7117+
IStatus.ERROR,
7118+
IJavaModelStatusConstants.INVALID_CLASSPATH,
71197119
status);
71207120

71217121
proj.setOption(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.ERROR);
71227122

71237123
status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
71247124
assertStatus(
7125-
"Source folder \'src\' in project \'P\' cannot output to distinct source folder \'src2\'",
7125+
IStatus.ERROR,
7126+
IJavaModelStatusConstants.OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE,
71267127
status);
71277128

71287129
} finally {
@@ -7334,7 +7335,7 @@ public void testClasspathTestSourceValidation1() throws CoreException {
73347335

73357336
IJavaModelStatus status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
73367337

7337-
assertStatus("should not complain", "OK", status);
7338+
assertStatus("should not complain", IStatus.OK, status);
73387339
} finally {
73397340
this.deleteProject("P");
73407341
}
@@ -7353,7 +7354,7 @@ public void testClasspathTestSourceValidation2() throws CoreException {
73537354

73547355
IJavaModelStatus status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
73557356

7356-
assertStatus("should complain because tests have no output folder", "Test source folder 'src-tests' in project 'P' must have a separate output folder", status);
7357+
assertStatus("should complain because tests have no output folder", IStatus.ERROR, IJavaModelStatusConstants.TEST_SOURCE_REQUIRES_SEPARATE_OUTPUT_LOCATION, status);
73577358
} finally {
73587359
this.deleteProject("P");
73597360
}
@@ -7370,7 +7371,7 @@ public void testClasspathTestSourceValidation3() throws CoreException {
73707371

73717372
IJavaModelStatus status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
73727373

7373-
assertStatus("should not complain because no main sources are present", "OK", status);
7374+
assertStatus("should not complain because no main sources are present", IStatus.OK, status);
73747375
} finally {
73757376
this.deleteProject("P");
73767377
}
@@ -7389,7 +7390,7 @@ public void testClasspathTestSourceValidation4() throws CoreException {
73897390

73907391
IJavaModelStatus status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
73917392

7392-
assertStatus("should not complain because main sources have their own output folder", "OK", status);
7393+
assertStatus("should not complain because main sources have their own output folder", IStatus.OK, status);
73937394
} finally {
73947395
this.deleteProject("P");
73957396
}
@@ -7408,7 +7409,7 @@ public void testClasspathTestSourceValidation5() throws CoreException {
74087409

74097410
IJavaModelStatus status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
74107411

7411-
assertStatus("should complain because main sources have the same own output folder", "Test source folder 'src-tests' in project 'P' must have an output folder that is not also used for main sources", status);
7412+
assertStatus("should complain because main sources have the same own output folder", IStatus.ERROR, IJavaModelStatusConstants.TEST_OUTPUT_FOLDER_MUST_BE_SEPARATE_FROM_MAIN_OUTPUT_FOLDERS, status);
74127413
} finally {
74137414
this.deleteProject("P");
74147415
}
@@ -7435,10 +7436,10 @@ public void testBug539998() throws CoreException {
74357436

74367437
IJavaModelStatus status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
74377438

7438-
final String expected = Messages.bind(Messages.classpath_main_only_project_depends_on_test_only_project,
7439-
new String[] { proj.getElementName(), proj1TestOnly.getElementName() });
7440-
7441-
assertStatus("should complain", expected, status);
7439+
assertStatus("should complain",
7440+
IStatus.ERROR,
7441+
IJavaModelStatusConstants.MAIN_ONLY_PROJECT_DEPENDS_ON_TEST_ONLY_PROJECT,
7442+
status);
74427443
} finally {
74437444
this.deleteProjects(new String[] { "P1", "P2" });
74447445
}

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ public void testPackageFragmentRootRawEntry3() throws CoreException, IOException
18251825
IClasspathEntry rawEntry = roots[length-1].getRawClasspathEntry();
18261826
assertNotNull("We should no longer get a null classpath entry:", rawEntry);
18271827
} catch (JavaModelException jme) {
1828-
assertStatus(rootPath+" is not on its project's build path", jme.getJavaModelStatus());
1828+
assertStatus(IStatus.ERROR, IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, jme.getJavaModelStatus());
18291829
}
18301830
} finally {
18311831
if (libDir != null) {

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModifyingResourceTests.java

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,48 @@ protected void assertElementDescendants(String message, String expected, IJavaE
111111
actual);
112112
}
113113
protected void assertStatus(String expected, IStatus status) {
114-
String actual = status.getMessage();
115-
if (!expected.equals(actual)) {
116-
System.out.print(Util.displayString(actual, 2));
117-
System.out.println(",");
114+
if ("OK".equals(expected)) {
115+
assertStatus(IStatus.OK, status);
116+
return;
117+
}
118+
if (status.isOK()) {
119+
System.out.print(Util.displayString(status.getMessage(), 2));
120+
System.out.println(",");
118121
}
119-
assertEquals(expected, actual);
122+
assertFalse("Unexpected OK status", status.isOK());
120123
}
121124
protected void assertStatus(String message, String expected, IStatus status) {
122-
String actual = status.getMessage();
123-
if (!expected.equals(actual)) {
124-
System.out.print(Util.displayString(actual, 2));
125-
System.out.println(",");
125+
if ("OK".equals(expected)) {
126+
assertStatus(message, IStatus.OK, status);
127+
return;
128+
}
129+
if (status.isOK()) {
130+
System.out.print(Util.displayString(status.getMessage(), 2));
131+
System.out.println(",");
132+
}
133+
assertFalse(message, status.isOK());
134+
}
135+
protected void assertStatus(int expectedSeverity, IStatus status) {
136+
if (expectedSeverity != status.getSeverity()) {
137+
System.out.print(Util.displayString(status.getMessage(), 2));
138+
System.out.println(",");
139+
}
140+
assertEquals("Unexpected status severity", expectedSeverity, status.getSeverity());
141+
}
142+
protected void assertStatus(String message, int expectedSeverity, IStatus status) {
143+
if (expectedSeverity != status.getSeverity()) {
144+
System.out.print(Util.displayString(status.getMessage(), 2));
145+
System.out.println(",");
126146
}
127-
assertEquals(message, expected, actual);
147+
assertEquals(message, expectedSeverity, status.getSeverity());
148+
}
149+
protected void assertStatus(int expectedSeverity, int expectedCode, IStatus status) {
150+
assertStatus(expectedSeverity, status);
151+
assertEquals("Unexpected status code", expectedCode, status.getCode());
152+
}
153+
protected void assertStatus(String message, int expectedSeverity, int expectedCode, IStatus status) {
154+
assertStatus(message, expectedSeverity, status);
155+
assertEquals(message, expectedCode, status.getCode());
128156
}
129157
/**
130158
* E.g.

0 commit comments

Comments
 (0)