Skip to content

BAEL-9317 Parsing JSON boolean Value in Java - improve to talk about 0/1 representation #18573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 40 commits into
base: master
Choose a base branch
from

Conversation

Deepak-Vohra
Copy link
Contributor

No description provided.

Copy link
Collaborator

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

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

I've left a few comments for you to consider.


@Test
void givenJSONString_whenParsed_correctBooleanValueReturned() {
String jsonString = "{\"name\":\"lorem ipsum\",\"active\":true,\"id\":1}";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use text blocks for JSON.

Also, consider defining a member variable template since most of these tests have the same construct:

private final String json = """
    { 
        "name": "lorem ipsum",
        "active": %s,
        "id": %d
    }""";

void givenJSONWithBooleanAs0Or1_whenParsed_correctBooleanValueReturned() {
String jsonString = "{\"name\":\"lorem ipsum\",\"active\":1,\"id\":1}";
JSONObject jsonObject = new JSONObject(jsonString);
int activeInt = jsonObject.getInt("active");
Copy link
Collaborator

Choose a reason for hiding this comment

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

From the guidelines:

when creating complex assertions, it’s a good idea to use assertj to preserve clarity - if assertions are trivial, it’s fine to stick to JUnit ones

If you do this, then the test becomes:

assertThat(jsonObject.getInt("active").isEqualTo(1);

which is quite succinct.

Comment on lines 42 to 43
assertEquals(type,"Feature");
assertEquals(geometry,"Point");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please reverse the order of the arguments. It's intended to be assertEquals(expected, actual)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reversed

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.

3 participants