Skip to content

Commit 90e1d23

Browse files
authored
Use named constants (#1551)
1 parent 7b38726 commit 90e1d23

2 files changed

Lines changed: 22 additions & 25 deletions

File tree

plugins/com.google.cloud.tools.eclipse.appengine.validation.test/src/com/google/cloud/tools/eclipse/appengine/validation/AbstractXmlValidatorTest.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020

21+
import com.google.cloud.tools.eclipse.test.util.project.TestProjectCreator;
2122
import java.io.ByteArrayInputStream;
2223
import org.eclipse.core.resources.IContainer;
2324
import org.eclipse.core.resources.IFile;
@@ -34,16 +35,15 @@
3435
import org.junit.Test;
3536
import org.xml.sax.SAXException;
3637
import org.xml.sax.SAXParseException;
37-
import com.google.cloud.tools.eclipse.test.util.project.TestProjectCreator;
3838

3939
public class AbstractXmlValidatorTest {
4040

4141
private final String ELEMENT_MESSAGE = "Project ID should be specified at deploy time.";
4242
private static IResource resource;
4343
private static IProject project;
44-
44+
4545
@ClassRule public static TestProjectCreator projectCreator = new TestProjectCreator();
46-
46+
4747
@BeforeClass
4848
public static void setUp() throws CoreException {
4949
project = projectCreator.getProject();
@@ -52,39 +52,37 @@ public static void setUp() throws CoreException {
5252
webXml.create(new ByteArrayInputStream(new byte[0]), true, null);
5353
resource = webXml;
5454
}
55-
55+
5656
@After
5757
public void tearDown() throws CoreException {
5858
if (resource != null) {
5959
resource.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
6060
}
6161
}
62-
62+
6363
@Test
6464
public void testCreateMarker() throws CoreException {
6565
BannedElement element = new BannedElement(ELEMENT_MESSAGE);
66-
String markerId = "org.eclipse.core.resources.problemmarker";
6766
AppEngineWebXmlValidator.createMarker(resource, element, 0);
68-
IMarker[] markers = resource.findMarkers(markerId, true, IResource.DEPTH_ZERO);
69-
assertEquals(ELEMENT_MESSAGE, (String) markers[0].getAttribute(IMarker.MESSAGE));
67+
IMarker[] markers = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
68+
assertEquals(ELEMENT_MESSAGE, markers[0].getAttribute(IMarker.MESSAGE));
7069
}
71-
70+
7271
@Test
7372
public void testCreateSAXErrorMessage() throws CoreException {
7473
SAXParseException spe = new SAXParseException("", "", "", 1, 1);
7574
SAXException ex = new SAXException(ELEMENT_MESSAGE, spe);
7675
AppEngineWebXmlValidator.createSaxErrorMessage(resource, ex);
77-
String problemMarker = "org.eclipse.core.resources.problemmarker";
78-
IMarker[] markers = resource.findMarkers(problemMarker, true, IResource.DEPTH_ZERO);
79-
assertEquals(ELEMENT_MESSAGE, (String) markers[0].getAttribute(IMarker.MESSAGE));
76+
IMarker[] markers = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
77+
assertEquals(ELEMENT_MESSAGE, markers[0].getAttribute(IMarker.MESSAGE));
8078
}
81-
79+
8280
private static void createFolders(IContainer parent, IPath path) throws CoreException {
8381
if (!path.isEmpty()) {
8482
IFolder folder = parent.getFolder(new Path(path.segment(0)));
8583
folder.create(true, true, null);
8684
createFolders(folder, path.removeFirstSegments(1));
8785
}
8886
}
89-
87+
9088
}

plugins/com.google.cloud.tools.eclipse.appengine.validation.test/src/com/google/cloud/tools/eclipse/appengine/validation/AppEngineWebXmlValidatorTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020

21+
import com.google.cloud.tools.eclipse.test.util.project.TestProjectCreator;
2122
import java.io.ByteArrayInputStream;
2223
import java.io.IOException;
2324
import java.nio.charset.StandardCharsets;
@@ -35,7 +36,6 @@
3536
import org.junit.BeforeClass;
3637
import org.junit.ClassRule;
3738
import org.junit.Test;
38-
import com.google.cloud.tools.eclipse.test.util.project.TestProjectCreator;
3939

4040
public class AppEngineWebXmlValidatorTest {
4141

@@ -46,9 +46,9 @@ public class AppEngineWebXmlValidatorTest {
4646
"com.google.cloud.tools.eclipse.appengine.validation.appEngineBlacklistMarker";
4747
private static IResource resource;
4848
private static IProject project;
49-
49+
5050
@ClassRule public static TestProjectCreator projectCreator = new TestProjectCreator();
51-
51+
5252
@BeforeClass
5353
public static void setUp() throws CoreException {
5454
project = projectCreator.getProject();
@@ -57,28 +57,27 @@ public static void setUp() throws CoreException {
5757
webXml.create(new ByteArrayInputStream(new byte[0]), true, null);
5858
resource = webXml;
5959
}
60-
61-
60+
61+
6262
@After
6363
public void tearDown() throws CoreException {
6464
if (resource != null) {
6565
resource.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
6666
}
6767
}
68-
68+
6969
@Test
7070
public void testValidate_badXml()
7171
throws IOException, CoreException, ParserConfigurationException {
7272
byte[] bytes = BAD_XML.getBytes(StandardCharsets.UTF_8);
7373
AppEngineWebXmlValidator validator = new AppEngineWebXmlValidator();
7474
validator.validate(resource, bytes);
75-
String problemMarker = "org.eclipse.core.resources.problemmarker";
76-
IMarker[] markers = resource.findMarkers(problemMarker, true, IResource.DEPTH_ZERO);
75+
IMarker[] markers = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
7776
String resultMessage = (String) markers[0].getAttribute(IMarker.MESSAGE);
7877
assertEquals("XML document structures must start and end within the same entity.",
7978
resultMessage);
8079
}
81-
80+
8281
@Test
8382
public void testValidate_noBannedElements()
8483
throws IOException, CoreException, ParserConfigurationException {
@@ -98,10 +97,10 @@ public void testValidate_withBannedElements()
9897
IMarker[] markers = resource.findMarkers(APPLICATION_MARKER, true, IResource.DEPTH_ZERO);
9998
assertEquals(1, markers.length);
10099
String message = Messages.getString("application.element");
101-
assertEquals(message, (String) markers[0].getAttribute(IMarker.MESSAGE));
100+
assertEquals(message, markers[0].getAttribute(IMarker.MESSAGE));
102101
assertEquals("line 1", markers[0].getAttribute(IMarker.LOCATION));
103102
}
104-
103+
105104
private static void createFolders(IContainer parent, IPath path) throws CoreException {
106105
if (!path.isEmpty()) {
107106
IFolder folder = parent.getFolder(new Path(path.segment(0)));

0 commit comments

Comments
 (0)