Skip to content

Commit 10c898f

Browse files
regex as a json to regex as a constant class (#18)
* version 0.0.9 * changing regex as a JSON to constant static class
1 parent 7266bb3 commit 10c898f

File tree

4 files changed

+9
-43
lines changed

4 files changed

+9
-43
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.github.ericsson</groupId>
66
<artifactId>eiffel-commons-java</artifactId>
7-
<version>0.0.8</version>
7+
<version>0.0.9</version>
88
<name>eiffel commons java</name>
99
<description>A shared library for eiffel components</description>
1010

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
package com.ericsson.eiffelcommons.utils;
22

3-
import java.io.IOException;
4-
5-
import org.json.JSONObject;
6-
73
public class RegExProvider {
84

9-
private static final String REGULAR_EXPRESSIONS_PATH = "/regExs.json";
10-
11-
/**
12-
* This method returns Json Object for regular expressions
13-
*
14-
* @return JSONObject
15-
*/
16-
public static JSONObject getRegExs() throws IOException {
5+
public static final String SUBSCRIPTION_NAME = "(\\W)";
6+
public static final String NOTIFICATION_META = "^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";;
177

18-
return Utils.getResourceFileAsJsonObject(REGULAR_EXPRESSIONS_PATH);
8+
private RegExProvider() {
9+
throw new AssertionError();
1910
}
2011
}

src/main/resources/regExs.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/test/java/com/ericsson/eiffelcommons/Utilstest/RegExProviderTest.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import static org.junit.Assert.assertEquals;
44

5-
import java.io.IOException;
6-
7-
import org.json.JSONException;
85
import org.junit.Test;
96

107
import com.ericsson.eiffelcommons.utils.RegExProvider;
@@ -13,29 +10,11 @@ public class RegExProviderTest {
1310

1411
@Test
1512
public void test() {
16-
String regExForInvalidName = getValue("invalidName");
17-
String regExForValidEmail = getValue("validEmail");
1813

19-
assertEquals(regExForInvalidName, "(\\W)");
20-
assertEquals(regExForValidEmail,
21-
"^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$");
22-
}
14+
String expectedRegexForSubscriptionName = "(\\W)";
15+
String expectedRegexForEmail = "^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
2316

24-
/**
25-
* This function takes a key and returns the corresponding value from the
26-
* JSONObject
27-
*
28-
* @param String
29-
* key
30-
* @return String value
31-
*/
32-
public String getValue(String key) {
33-
String value = null;
34-
try {
35-
value = (String) RegExProvider.getRegExs().get(key);
36-
} catch (JSONException | IOException e) {
37-
e.printStackTrace();
38-
}
39-
return value;
17+
assertEquals(RegExProvider.SUBSCRIPTION_NAME, expectedRegexForSubscriptionName);
18+
assertEquals(RegExProvider.NOTIFICATION_META, expectedRegexForEmail);
4019
}
4120
}

0 commit comments

Comments
 (0)