Skip to content

Commit 71ef17e

Browse files
committed
refactor: Delete and rearrange files as necessary
1 parent df94d89 commit 71ef17e

File tree

7 files changed

+101
-655
lines changed

7 files changed

+101
-655
lines changed

src/test/java/com/ibm/cloud/sdk/core/test/WatsonServiceUnitTest.java renamed to src/test/java/com/ibm/cloud/sdk/core/test/BaseServiceUnitTest.java

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
1-
/**
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5-
* the License. You may obtain a copy of the License at
6-
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
9-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10-
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
13-
package com.ibm.cloud.sdk.core.test;
14-
15-
import java.io.IOException;
16-
17-
import org.apache.commons.lang3.StringUtils;
18-
import org.junit.After;
1+
package com.ibm.cloud.sdk.core.test.service;
192

203
import com.google.gson.Gson;
214
import com.ibm.cloud.sdk.core.http.HttpMediaType;
225
import com.ibm.cloud.sdk.core.util.GsonSingleton;
23-
246
import okhttp3.mockwebserver.MockResponse;
257
import okhttp3.mockwebserver.MockWebServer;
8+
import org.apache.commons.lang3.StringUtils;
9+
import org.junit.After;
2610

27-
/**
28-
* Utility class to Mock the Watson Services.
29-
*
30-
*/
31-
public abstract class WatsonServiceUnitTest extends WatsonServiceTest {
11+
import java.io.IOException;
3212

13+
import static com.ibm.cloud.sdk.core.http.HttpHeaders.CONTENT_TYPE;
14+
15+
public class BaseServiceUnitTest {
3316
/** The Constant DELETE. */
3417
protected static final String DELETE = "DELETE";
3518

@@ -86,5 +69,4 @@ protected String getMockWebServerUrl() {
8669
protected static MockResponse jsonResponse(Object body) {
8770
return new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(GSON.toJson(body));
8871
}
89-
9072
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* Copyright 2017 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.cloud.sdk.core.test.util;
14+
15+
import com.ibm.cloud.sdk.core.util.GsonSingleton;
16+
import org.junit.Ignore;
17+
18+
import java.io.BufferedReader;
19+
import java.io.FileInputStream;
20+
import java.io.FileNotFoundException;
21+
import java.io.IOException;
22+
import java.io.InputStream;
23+
import java.io.InputStreamReader;
24+
25+
/**
26+
* The Class TestUtils.
27+
*/
28+
@Ignore
29+
public final class TestUtils {
30+
/** The Constant DELETE. */
31+
protected static final String DELETE = "DELETE";
32+
33+
/** The Constant GET. */
34+
protected static final String GET = "GET";
35+
36+
/** The Constant POST. */
37+
protected static final String POST = "POST";
38+
39+
/** The Constant PUT. */
40+
protected static final String PUT = "PUT";
41+
42+
/**
43+
* Private constructor.
44+
*/
45+
private TestUtils() { }
46+
47+
/**
48+
* Gets the string from input stream.
49+
*
50+
* @param is the input stream
51+
* @return the string from input stream
52+
*/
53+
static String getStringFromInputStream(InputStream is) {
54+
BufferedReader br = null;
55+
final StringBuilder sb = new StringBuilder();
56+
57+
String line;
58+
try {
59+
60+
br = new BufferedReader(new InputStreamReader(is));
61+
while ((line = br.readLine()) != null) {
62+
sb.append(line);
63+
}
64+
65+
} catch (final IOException e) {
66+
e.printStackTrace();
67+
} finally {
68+
if (br != null) {
69+
try {
70+
br.close();
71+
} catch (final IOException e) {
72+
e.printStackTrace();
73+
}
74+
}
75+
}
76+
77+
return sb.toString();
78+
79+
}
80+
81+
/**
82+
* Loads fixture.
83+
*
84+
* @param <T> the return type
85+
* @param filename the file name
86+
* @param returnType the return type
87+
* @return the t
88+
* @throws FileNotFoundException the file not found exception
89+
*/
90+
public static <T> T loadFixture(String filename, Class<T> returnType) throws FileNotFoundException {
91+
String jsonString = getStringFromInputStream(new FileInputStream(filename));
92+
return GsonSingleton.getGsonWithoutPrettyPrinting().fromJson(jsonString, returnType);
93+
}
94+
}

src/test/java/com/ibm/cloud/sdk/core/test/WatsonServiceTest.java

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

0 commit comments

Comments
 (0)