Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
exclude module: "groovy-all"
}
implementation 'junit:junit:4.12'
implementation("com.squareup.okhttp3:okhttp:4.4.0")

}

Expand Down
35 changes: 35 additions & 0 deletions src/test/java/com/github/speechrank/rest/GetConferencesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.speechrank.rest;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;

public class GetConferencesTest {

@Test
public void conferences() throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url("https://76ea5e2c-c86f-4a27-baf2-c1667b6a1f35.mock.pstmn.io/api/conferences")
.method("GET", null)
.build();
Response response = client.newCall(request).execute();

//check is content-type is application/json
assertEquals("text/html; charset=utf-8", response.header("content-type"));

//check if status code is 200
assertEquals(200, response.code());

//check responseBody
String responseBody = response.body().string();
assertEquals("[{\"year\":\"2019\",\"conferences\":[{\"id\":\"12\",\"name\":\"DevConf\",\"presentations\":25},{\"id\":\"31\",\"name\":\"Boiling Frogs\",\"presentations\":25},{\"id\":\"41\",\"name\":\"Scalar\",\"presentations\":16},{\"id\":\"51\",\"name\":\"Confitura\",\"presentations\":25}]},{\"year\":\"2018\",\"conferences\":[{\"id\":\"21\",\"name\":\"Boiling Frogs\",\"presentations\":25},{\"id\":\"51\",\"name\":\"Confitura\",\"presentations\":25}]},{\"year\":\"2017\",\"conferences\":[{\"id\":\"11\",\"name\":\"DevConf\",\"presentations\":25}]}]", responseBody);
//TODO: powyzsza asercje napewno da sie ulepszyc, ale jeszcze nie wiem jak :)
}
}