1- import com .google .gson .*;
1+ package test ;
2+
3+ import com .google .gson .JsonArray ;
4+ import com .google .gson .JsonElement ;
5+ import com .google .gson .JsonObject ;
6+ import com .google .gson .JsonPrimitive ;
27import com .lvack .championggwrapper .ChampionGGAPIFactory ;
38import com .lvack .championggwrapper .annotations .*;
49import com .lvack .championggwrapper .data .champion .HighLevelChampionData ;
510import com .lvack .championggwrapper .data .error .ErrorResponse ;
611import com .lvack .championggwrapper .data .staticdata .Role ;
712import com .lvack .championggwrapper .data .staticdata .RoleStatOrder ;
813import com .lvack .championggwrapper .data .staticdata .StatOrder ;
9- import com .lvack .championggwrapper .gson .GsonProvider ;
1014import com .lvack .championggwrapper .retrofit .APIResponse ;
1115import com .lvack .championggwrapper .retrofit .ChampionGGAPI ;
1216import okhttp3 .mockwebserver .MockResponse ;
1317import okhttp3 .mockwebserver .MockWebServer ;
1418import org .apache .commons .lang3 .ClassUtils ;
1519import org .junit .Assert ;
1620import org .junit .jupiter .api .*;
21+ import util .Constants ;
22+ import util .MockDispatcher ;
1723
1824import java .io .IOException ;
1925import java .io .PrintWriter ;
2026import java .io .StringWriter ;
2127import java .lang .annotation .Annotation ;
22- import java .lang .reflect .Field ;
2328import java .lang .reflect .Method ;
2429import java .lang .reflect .Parameter ;
2530import java .lang .reflect .ParameterizedType ;
2934
3035
3136@ DisplayName ("ChampionGGAPI tests" ) class ChampionGGTest {
32- static final Gson GSON = GsonProvider .getGsonBuilder ()
33- .registerTypeAdapter (MockResponse .class , new MockResponseDeSerializer ())
34- .create ();
3537
3638 private static ChampionGGAPI API ;
3739 private static MockWebServer webServer ;
@@ -44,7 +46,7 @@ static void initChampionGGAPI() {
4446 webServer .setDispatcher (dispatcher );
4547 ChampionGGAPIFactory .BASE_URL = webServer .url ("/" ).toString ();
4648
47- ChampionGGAPIFactory championGGAPIFactory = new ChampionGGAPIFactory (MockDispatcher .API_KEY , -1 );
49+ ChampionGGAPIFactory championGGAPIFactory = new ChampionGGAPIFactory (Constants .API_KEY , -1 );
4850 API = championGGAPIFactory .buildChampionGGAPI ();
4951 }
5052
@@ -122,12 +124,12 @@ static void deleteChampionGGAPI() throws IOException {
122124 Assert .assertNull ("success response has an error exception" , actualError );
123125
124126 String expectedResponseJson = new String (response .getBody ().clone ().readByteArray (), "UTF-8" );
125- Object expectedContent = GSON .fromJson (expectedResponseJson ,
127+ Object expectedContent = Constants . GSON .fromJson (expectedResponseJson ,
126128 ((ParameterizedType ) method .getGenericReturnType ()).getActualTypeArguments ()[0 ]);
127129 Assert .assertEquals ("response content does not match" , expectedContent , actualContent );
128130
129- JsonElement expectedJsonElement = GSON .fromJson (expectedResponseJson , JsonElement .class );
130- JsonElement actualJsonElement = GSON .fromJson (GSON .toJson (actualContent ), JsonElement .class );
131+ JsonElement expectedJsonElement = Constants . GSON .fromJson (expectedResponseJson , JsonElement .class );
132+ JsonElement actualJsonElement = Constants . GSON .fromJson (Constants . GSON .toJson (actualContent ), JsonElement .class );
131133 assertEqualJsonElements (expectedJsonElement , actualJsonElement );
132134 // TODO: find fields that may be null; assertNoNullFields(actualContent);
133135 }
@@ -148,7 +150,7 @@ static void deleteChampionGGAPI() throws IOException {
148150 Assert .assertNotNull ("api error response does not have an error response" , actualErrorResponse );
149151 Assert .assertNull ("api error response has an error exception" , actualError );
150152
151- ErrorResponse expectedErrorResponse = GSON .fromJson (new String (response .getBody ().clone ().readByteArray (), "UTF-8" ),
153+ ErrorResponse expectedErrorResponse = Constants . GSON .fromJson (new String (response .getBody ().clone ().readByteArray (), "UTF-8" ),
152154 ErrorResponse .class );
153155 Assert .assertEquals ("error response content does not match" , expectedErrorResponse , actualErrorResponse );
154156 }
@@ -185,7 +187,7 @@ void testRateLimiter() {
185187
186188 long requestDelay = 1000 ;
187189 double maxRequestsPerSecond = 1000.0 / requestDelay ;
188- ChampionGGAPIFactory factory = new ChampionGGAPIFactory (MockDispatcher .API_KEY , maxRequestsPerSecond );
190+ ChampionGGAPIFactory factory = new ChampionGGAPIFactory (Constants .API_KEY , maxRequestsPerSecond );
189191 ChampionGGAPI api = factory .buildChampionGGAPI ();
190192
191193 final int calls = 4 ;
@@ -343,7 +345,7 @@ private void assertEqualJsonElements(JsonElement expected, JsonElement actual, S
343345 @ Test
344346 void testObjectMethodOnApi () {
345347 //noinspection ResultOfMethodCallIgnored
346- new ChampionGGAPIFactory (MockDispatcher .API_KEY , 10 )
348+ new ChampionGGAPIFactory (Constants .API_KEY , 10 )
347349 .buildChampionGGAPI ().getClass ();
348350 }
349351
@@ -363,11 +365,11 @@ private String getJsonPrimitiveType(JsonPrimitive primitive) {
363365 return "unknown" ;
364366 }
365367
366- private void assertNoNullFields (Object object ) {
368+ /* private void assertNoNullFields(Object object) {
367369 assertNoNullFields(object, "");
368- }
370+ } */
369371
370- private void assertNoNullFields (Object object , String path ) {
372+ /* private void assertNoNullFields(Object object, String path) {
371373 Assert.assertNotNull("field at " + path + " is null", object);
372374 if (ClassUtils.isPrimitiveOrWrapper(object.getClass())) return;
373375 if (object instanceof String) return;
@@ -396,7 +398,7 @@ private void assertNoNullFields(Object object, String path) {
396398 }
397399 }
398400 }
399- }
401+ } */
400402
401403 private String getMethodName (Method method , Object [] args ) {
402404 return method .getDeclaringClass ().getSimpleName () + "." + method .getName () +
0 commit comments