Skip to content

Added classes for testing API with Jackson#5

Open
rusakov66 wants to merge 1 commit into
masterfrom
Jackson
Open

Added classes for testing API with Jackson#5
rusakov66 wants to merge 1 commit into
masterfrom
Jackson

Conversation

@rusakov66

Copy link
Copy Markdown
Owner

First code with Jackson. Nogami ne beite

@rusakov66 rusakov66 force-pushed the Jackson branch 2 times, most recently from bbaca89 to 2296d2d Compare June 27, 2019 08:23
Comment thread src/test/java/ApiStructure.java Outdated
@@ -0,0 +1,34 @@
public class ApiStructure {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to User

Comment thread src/test/java/ApiStructure.java Outdated
@@ -0,0 +1,34 @@
public class ApiStructure {
public String login = "rusakov6699";
public long id = 16705398;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all fields -> private (use getters)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread src/test/java/ApiStructure.java Outdated
public String login = "rusakov6699";
public long id = 16705398;
public String node_id = "MDQ6VXNlcjE2NzA1Mzk4";
public String avatar_url = "https://avatars1.githubusercontent.com/u/16705398?v=4";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to assign a value to this fields

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were removed

Comment thread src/test/java/ApiTestWithJackson.java Outdated
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.jupiter.api.Assertions.assertAll;

public class ApiTestWithJackson {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename (e.g GetUserJacksonTest)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread src/test/java/ApiTestWithJackson.java Outdated
@Test
public void getRequestFromGithubTest() throws IOException {
ObjectMapper mapper = new ObjectMapper();
String stringURL = "https://api.github.com/users/rusakov66";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract as a constant

Comment thread src/test/java/ApiTestWithJackson.java Outdated
String stringURL = "https://api.github.com/users/rusakov66";
Response response = get(stringURL);
JSONObject jsonResponse = new JSONObject(response.asString());
System.out.println(jsonResponse);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we repeated 100 times about system.out

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for SOP's - there were my debugging points ....

Comment thread src/test/java/ApiTestWithJackson.java Outdated
System.out.println(jsonResponse);
ObjectMapper objectMapper = new ObjectMapper();
String jsonResponseAsString = jsonResponse.toString();
System.out.println(jsonResponseAsString);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we repeated 100 times about system.out

Comment thread src/test/java/ApiTestWithJackson.java Outdated
String jsonResponseAsString = jsonResponse.toString();
System.out.println(jsonResponseAsString);
ApiStructure jsonResponseAsObject = objectMapper.readValue(jsonResponseAsString, ApiStructure.class);
String statusLine = response.getStatusLine();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not statusLine, but StatusCode

Comment thread src/test/java/ApiTestWithJackson.java Outdated
System.out.println(jsonResponseAsString);
ApiStructure jsonResponseAsObject = objectMapper.readValue(jsonResponseAsString, ApiStructure.class);
String statusLine = response.getStatusLine();
System.out.println("statusLine" + statusLine);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we repeated 100 times about system.out

Comment thread src/test/java/ApiTestWithJackson.java Outdated
String statusLine = response.getStatusLine();
System.out.println("statusLine" + statusLine);
assertAll(
() -> assertThat(jsonResponseAsObject.login, is("rusakov667")),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsonResponseAsObject - it is not json.
rename

Comment thread pom.xml Outdated
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version to a property

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants