File tree Expand file tree Collapse file tree 3 files changed +59
-11
lines changed
main/java/com/uid2/client
test/java/com/uid2/client Expand file tree Collapse file tree 3 files changed +59
-11
lines changed Original file line number Diff line number Diff line change 66import java .time .Instant ;
77import java .util .ArrayList ;
88import java .util .Base64 ;
9+ import java .util .HashSet ;
910import java .util .List ;
11+ import java .util .Set ;
1012
1113
1214class KeyParser {
@@ -82,12 +84,12 @@ private static Site getSiteFromJson(JsonObject siteJson) {
8284 return null ;
8385 }
8486 JsonArray domainOrAppNamesJArray = siteJson .getAsJsonArray ("domain_names" );
85- List <String > domainOrAppNames = new ArrayList <>();
87+ Set <String > domainOrAppNamesSet = new HashSet <>();
8688 for (int i = 0 ; i < domainOrAppNamesJArray .size (); ++i ) {
87- domainOrAppNames .add (domainOrAppNamesJArray .get (i ).getAsString ());
89+ domainOrAppNamesSet .add (domainOrAppNamesJArray .get (i ).getAsString ());
8890 }
8991
90- return new Site (siteId , domainOrAppNames );
92+ return new Site (siteId , domainOrAppNamesSet );
9193 }
9294
9395 static private int getAsInt (JsonObject body , String memberName ) {
Original file line number Diff line number Diff line change 11package com .uid2 .client ;
22
3- import java .util .HashSet ;
4- import java .util .List ;
5- import java .util .Set ;
3+ import lombok .AllArgsConstructor ;
64import lombok .Getter ;
75
6+ import java .util .Set ;
7+
88@ Getter
9+ @ AllArgsConstructor
910public class Site {
1011 private final int id ;
1112
1213 private final Set <String > domainOrAppNames ;
1314
14- public Site (int id , List <String > domainOrAppNames ) {
15- this .id = id ;
16- this .domainOrAppNames = new HashSet <>(domainOrAppNames );
17- }
18-
1915 public boolean allowDomainOrAppName (String domainOrAppName ) {
2016 // Using streams because HashSet's contains() is case sensitive
2117 return domainOrAppNames .stream ().anyMatch (domainOrAppName ::equalsIgnoreCase );
Original file line number Diff line number Diff line change 1+ package com .uid2 .client ;
2+
3+ import org .junit .jupiter .api .Assertions ;
4+ import org .junit .jupiter .api .BeforeAll ;
5+ import org .junit .jupiter .params .ParameterizedTest ;
6+ import org .junit .jupiter .params .provider .CsvSource ;
7+ import org .junit .jupiter .params .provider .ValueSource ;
8+
9+ import java .util .Arrays ;
10+ import java .util .HashSet ;
11+
12+ public class SiteTests {
13+
14+ private static Site site ;
15+
16+ @ BeforeAll
17+ public static void setup () {
18+ site = new Site (101 , new HashSet <>(Arrays .asList (
19+ "example.com" ,
20+ "example.org" ,
21+ "com.123.Game.App.android" ,
22+ "123456789"
23+ )));
24+ }
25+
26+
27+ @ ParameterizedTest
28+ @ ValueSource (strings = {
29+ "example.com" ,
30+ "example.org" ,
31+ "com.123.Game.App.android" ,
32+ "123456789" ,
33+ "EXAMPLE.COM" ,
34+ "com.123.game.app.android" ,
35+ })
36+ public void testAllowDomainOrAppNameSuccess (String domainOrAppName ) {
37+ Assertions .assertTrue (site .allowDomainOrAppName (domainOrAppName ));
38+ }
39+
40+ @ ParameterizedTest
41+ @ CsvSource ({
42+ "*" ,
43+ "example" ,
44+ "example*" ,
45+ "example.net"
46+ })
47+ public void testAllowDomainOrAppNameFailure (String domainOrAppName ) {
48+ Assertions .assertFalse (site .allowDomainOrAppName (domainOrAppName ));
49+ }
50+ }
You can’t perform that action at this time.
0 commit comments