diff --git a/pom.xml b/pom.xml
index 8f6a1a6..775d26b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,6 +63,19 @@
4.12
test
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.10
+
+
+
+ org.mockito
+ mockito-core
+ 4.8.0
+ test
+
+
\ No newline at end of file
diff --git a/src/main/java/second/junit/HttpQueryClass.java b/src/main/java/second/junit/HttpQueryClass.java
new file mode 100644
index 0000000..6f57750
--- /dev/null
+++ b/src/main/java/second/junit/HttpQueryClass.java
@@ -0,0 +1,45 @@
+package second.junit;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+import java.io.IOException;
+
+public class HttpQueryClass {
+
+ public String query() {
+ String result = "none";
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpGet request = new HttpGet("https://api.gios.gov.pl/pjp-api/rest/station/findAll");
+
+ // add request headers
+ request.addHeader("custom-key", "programming");
+
+ try (CloseableHttpResponse response = httpclient.execute(request)) {
+
+ // Get HttpResponse Status
+ System.out.println(response.getStatusLine().toString());
+
+ HttpEntity entity = response.getEntity();
+ Header headers = entity.getContentType();
+ System.out.println(headers);
+
+ if (entity != null) {
+ // return it as a String
+ result = EntityUtils.toString(entity);
+ System.out.println(result);
+ }
+ } catch (ClientProtocolException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return result;
+ }
+}
diff --git a/src/main/java/second/junit/Main.java b/src/main/java/second/junit/Main.java
new file mode 100644
index 0000000..cae3e9d
--- /dev/null
+++ b/src/main/java/second/junit/Main.java
@@ -0,0 +1,10 @@
+package second.junit;
+
+public class Main {
+
+ public static void main(final String... args) {
+ ProcessQuery processQuery = new ProcessQuery(new HttpQueryClass());
+ System.out.println(processQuery.process());
+ }
+
+}
diff --git a/src/main/java/second/junit/ProcessQuery.java b/src/main/java/second/junit/ProcessQuery.java
new file mode 100644
index 0000000..cb31f22
--- /dev/null
+++ b/src/main/java/second/junit/ProcessQuery.java
@@ -0,0 +1,17 @@
+package second.junit;
+
+import java.util.Locale;
+
+public class ProcessQuery {
+
+ HttpQueryClass queryClass;
+
+ public ProcessQuery(HttpQueryClass queryClass) {
+ this.queryClass = queryClass;
+ }
+
+ public String process() {
+ return queryClass.query().toUpperCase();
+ }
+
+}
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index 6225f22..d0e7050 100644
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -1,5 +1,5 @@
# Root logger option
-log4j.rootLogger=DEBUG, stdout, file
+log4j.rootLogger=INFO, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
diff --git a/src/main/resources/test b/src/main/resources/test
deleted file mode 100644
index a229f18..0000000
--- a/src/main/resources/test
+++ /dev/null
@@ -1 +0,0 @@
-test resource file
\ No newline at end of file
diff --git a/src/test/java/second/junit/AdvanceMathTest.java b/src/test/java/second/junit/AdvanceMathTest.java
index a622ab5..a7b3946 100644
--- a/src/test/java/second/junit/AdvanceMathTest.java
+++ b/src/test/java/second/junit/AdvanceMathTest.java
@@ -1,4 +1,3 @@
-
package second.junit;
import org.junit.Assert;
@@ -20,7 +19,7 @@ public class AdvanceMathTest {
@Test
public void additionTest() {
Integer a = math.addition(1, 4);
- assertTrue(a == 5);
+ Assert.assertTrue(a == 5);
}
@Test
diff --git a/src/test/java/second/junit/MockTest.java b/src/test/java/second/junit/MockTest.java
new file mode 100644
index 0000000..7d08161
--- /dev/null
+++ b/src/test/java/second/junit/MockTest.java
@@ -0,0 +1,32 @@
+package second.junit;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+
+public class MockTest {
+
+ HttpQueryClass httpQueryClass;
+
+ @Before
+ public void setUp() {
+ System.out.println("Run setUp");
+ httpQueryClass = Mockito.mock(HttpQueryClass.class);
+ }
+
+ @Test
+ public void mockTestExample() {
+ Mockito.when(httpQueryClass.query()).thenReturn("test");
+
+ ProcessQuery processQuery = new ProcessQuery(httpQueryClass);
+
+ String result = processQuery.process();
+ assertThat(result).isEqualTo("TEST");
+ }
+
+}