Skip to content

Commit

Permalink
TMBuilder TMJP check class unit tests updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
byarger-ebay committed Aug 16, 2023
1 parent edafd7c commit 75dd695
Show file tree
Hide file tree
Showing 10 changed files with 451 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ public void failWithBoolNotNull() {
softAssert.assertAll();
}

@Test(groups = unitTest)
public void passWithBoolNull() {

SoftAssert softAssert = new SoftAssert();

DocumentContext jsonPathDocument = JsonPath.using(config).parse("{\"foo\":null}");
TMJPBooleanCheck check = new TMJPBooleanCheck();
check.checkIsNull(true);
check.processJsonPath("$.foo", softAssert, jsonPathDocument);

softAssert.assertAll();
}

@Test(expectedExceptions = AssertionError.class, groups = "unitTest")
public void failWithBoolNull() {

SoftAssert softAssert = new SoftAssert();

DocumentContext jsonPathDocument = JsonPath.using(config).parse("{\"foo\":true}");
TMJPBooleanCheck check = new TMJPBooleanCheck();
check.checkIsNull(true);
check.processJsonPath("$.foo", softAssert, jsonPathDocument);

softAssert.assertAll();
}

@Test(groups = unitTest)
public void passWithCorrectValueCheck() {

Expand Down Expand Up @@ -110,22 +136,41 @@ public void kotlinThinModelExportCheck() {
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("JPBooleanCheck().isEqualTo(true)")));
}

@Test(groups = unitTest)
public void thinModelExportCheckNull() {

ThinModelSerializer serializer = new TMJPBooleanCheck().checkIsNull(true).isEqualTo(true);
String serialized = serializer.getJavaStatements();
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("new JPBooleanCheck().isEqualTo(true).checkIsNull(true)")));
}

@Test(groups = unitTest)
public void kotlinThinModelExportCheckNull() {

ThinModelSerializer serializer = new TMJPBooleanCheck().checkIsNull(true).isEqualTo(true);
String serialized = serializer.getKotlinStatements();
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("JPBooleanCheck().isEqualTo(true).checkIsNull(true)")));
}

@Test(groups = unitTest)
public void convertDefaultJPBooleanCheckToTMJPBooleanCheck() {

JPBooleanCheck original = new JPBooleanCheck();
TMJPBooleanCheck clone = new TMJPBooleanCheck(original);

assertThat("Clone MUST have equal check field set to null.", clone.getExpectedValue(), is(nullValue()));
assertThat("Clone MUST have null check set to expected.", clone.isNullExpected(), is(equalTo(false)));
}

@Test(groups = unitTest)
public void convertJPBooleanCheckToTMJPBooleanCheck() {

JPBooleanCheck original = new JPBooleanCheck().isEqualTo(true);
original.checkIsNull(true);
TMJPBooleanCheck clone = new TMJPBooleanCheck(original);

assertThat("Clone MUST have equal check field set to expected.", clone.getExpectedValue(), is(equalTo(true)));
assertThat("Clone MUST have null check set to expected.", clone.isNullExpected(), is(equalTo(true)));
}

@Test(groups = unitTest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ public void failWithDoubleNull() {
softAssert.assertAll();
}

@Test(expectedExceptions = AssertionError.class, groups = "unitTest")
public void failWithDoubleNotNull() {

SoftAssert softAssert = new SoftAssert();

DocumentContext jsonPathDocument = JsonPath.using(config).parse("{\"foo\":2.0}");
TMJPDoubleCheck check = new TMJPDoubleCheck();
check.checkIsNull(true);
check.processJsonPath("$.foo", softAssert, jsonPathDocument);

softAssert.assertAll();
}

@Test(groups = "unitTest")
public void passWithDoubleNull() {

SoftAssert softAssert = new SoftAssert();

DocumentContext jsonPathDocument = JsonPath.using(config).parse("{\"foo\":null}");
TMJPDoubleCheck check = new TMJPDoubleCheck();
check.checkIsNull(true);
check.processJsonPath("$.foo", softAssert, jsonPathDocument);

softAssert.assertAll();
}

@Test(groups = unitTest)
public void passWithValueMatch() {

Expand Down Expand Up @@ -122,22 +148,40 @@ public void kotlinThinModelExportCheck() {
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("JPDoubleCheck().isEqualTo(3.014159)")));
}

@Test(groups = unitTest)
public void thinModelExportCheckNull() {

ThinModelSerializer serializer = new TMJPDoubleCheck().checkIsNull(true).isEqualTo(3.014159000);
String serialized = serializer.getJavaStatements();
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("new JPDoubleCheck().isEqualTo(3.014159).checkIsNull(true)")));
}

@Test(groups = unitTest)
public void kotlinThinModelExportCheckNull() {

ThinModelSerializer serializer = new TMJPDoubleCheck().checkIsNull(true).isEqualTo(3.014159000);
String serialized = serializer.getKotlinStatements();
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("JPDoubleCheck().isEqualTo(3.014159).checkIsNull(true)")));
}

@Test(groups = unitTest)
public void convertDefaultJPDoubleCheckToTMJPDoubleCheck() {

JPDoubleCheck original = new JPDoubleCheck();
TMJPDoubleCheck clone = new TMJPDoubleCheck(original);

assertThat("Clone MUST have equal check field set to null.", clone.getExpectedValue(), is(nullValue()));
assertThat("Clone MUST have equal null check set to expected.", clone.isNullExpected(), is(equalTo(false)));
}

@Test(groups = unitTest)
public void convertJPDoubleCheckToTMJPDoubleCheck() {

JPDoubleCheck original = new JPDoubleCheck().isEqualTo(5.5);
JPDoubleCheck original = new JPDoubleCheck().checkIsNull(true).isEqualTo(5.5);
TMJPDoubleCheck clone = new TMJPDoubleCheck(original);

assertThat("Clone MUST have equal check field set to expected.", clone.getExpectedValue(), is(equalTo(5.5)));
assertThat("Clone MUST have equal null check set to expected.", clone.isNullExpected(), is(equalTo(true)));
}

@Test(groups = unitTest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ public void passWithIntegerNotNull() {
softAssert.assertAll();
}

@Test(groups = "unitTest")
public void passWithIntegerNull() {

SoftAssert softAssert = new SoftAssert();

DocumentContext jsonPathDocument = JsonPath.using(config).parse("{\"foo\":null}");
TMJPIntegerCheck check = new TMJPIntegerCheck();
check.checkIsNull(true);
check.processJsonPath("$.foo", softAssert, jsonPathDocument);

softAssert.assertAll();
}

@Test(expectedExceptions = AssertionError.class, groups = "unitTest")
public void failWithIntegerNotNull() {

SoftAssert softAssert = new SoftAssert();

DocumentContext jsonPathDocument = JsonPath.using(config).parse("{\"foo\":2}");
TMJPIntegerCheck check = new TMJPIntegerCheck();
check.checkIsNull(true);
check.processJsonPath("$.foo", softAssert, jsonPathDocument);

softAssert.assertAll();
}

@Test(expectedExceptions = AssertionError.class, groups = "unitTest")
public void failWithIntegerMismatch() {

Expand Down Expand Up @@ -110,22 +136,40 @@ public void kotlinThinModelExportCheck() {
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("JPIntegerCheck().isEqualTo(42)")));
}

@Test(groups = unitTest)
public void thinModelExportCheckNull() {

ThinModelSerializer serializer = new TMJPIntegerCheck().checkIsNull(true).isEqualTo(42);
String serialized = serializer.getJavaStatements();
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("new JPIntegerCheck().isEqualTo(42).checkIsNull(true)")));
}

@Test(groups = unitTest)
public void kotlinThinModelExportCheckNull() {

ThinModelSerializer serializer = new TMJPIntegerCheck().checkIsNull(true).isEqualTo(42);
String serialized = serializer.getKotlinStatements();
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("JPIntegerCheck().isEqualTo(42).checkIsNull(true)")));
}

@Test(groups = unitTest)
public void convertDefaultJPIntegerCheckToTMJPIntegerCheck() {

JPIntegerCheck original = new JPIntegerCheck();
TMJPIntegerCheck clone = new TMJPIntegerCheck(original);

assertThat("Clone MUST have equal check field set to null.", clone.getExpectedValue(), is(nullValue()));
assertThat("Clone MUST have null check set to false.", clone.isNullExpected(), is(equalTo(false)));
}

@Test(groups = unitTest)
public void convertJPIntegerCheckToTMJPIntegerCheck() {

JPIntegerCheck original = new JPIntegerCheck().isEqualTo(5);
JPIntegerCheck original = new JPIntegerCheck().checkIsNull(true).isEqualTo(5);
TMJPIntegerCheck clone = new TMJPIntegerCheck(original);

assertThat("Clone MUST have equal check field set to expected.", clone.getExpectedValue(), is(equalTo(5)));
assertThat("Clone MUST have null check set to true.", clone.isNullExpected(), is(equalTo(true)));
}

@Test(groups = unitTest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ public void failWithNullArray() {
softAssert.assertAll();
}

@Test(expectedExceptions = AssertionError.class, groups = "unitTest")
public void failWithNonNullArray() {

SoftAssert softAssert = new SoftAssert();

DocumentContext jsonPathDocument = JsonPath.using(config).parse("{\"foo\":[{\"bar\":\"A\"}]}");
TMJPJsonArrayCheck check = new TMJPJsonArrayCheck();
check.checkIsNull(true);
check.processJsonPath("$.foo", softAssert, jsonPathDocument);

softAssert.assertAll();
}

@Test(groups = "unitTest")
public void passWithNullArray() {

SoftAssert softAssert = new SoftAssert();

DocumentContext jsonPathDocument = JsonPath.using(config).parse("{\"foo\":null}");
TMJPJsonArrayCheck check = new TMJPJsonArrayCheck();
check.checkIsNull(true);
check.processJsonPath("$.foo", softAssert, jsonPathDocument);

softAssert.assertAll();
}

@Test(expectedExceptions = AssertionError.class, groups = "unitTest")
public void failWithClassCastException() {

Expand Down Expand Up @@ -181,6 +207,22 @@ public void kotlinThinModelExportCheck() {
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("JPJsonArrayCheck().hasLength(3).hasMinLength(1).hasMaxLength(4)")));
}

@Test(groups = unitTest)
public void thinModelExportCheckNull() {

ThinModelSerializer serializer = new TMJPJsonArrayCheck().checkIsNull(true).hasLength(3).hasMinLength(1).hasMaxLength(4);
String serialized = serializer.getJavaStatements();
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("new JPJsonArrayCheck().hasLength(3).hasMinLength(1).hasMaxLength(4).checkIsNull(true)")));
}

@Test(groups = unitTest)
public void kotlinThinModelExportCheckNull() {

ThinModelSerializer serializer = new TMJPJsonArrayCheck().checkIsNull(true).hasLength(3).hasMinLength(1).hasMaxLength(4);
String serialized = serializer.getKotlinStatements();
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("JPJsonArrayCheck().hasLength(3).hasMinLength(1).hasMaxLength(4).checkIsNull(true)")));
}

@Test(groups = unitTest)
public void convertDefaultJPJsonArrayCheckToTMJPJsonArrayCheck() {

Expand All @@ -190,16 +232,18 @@ public void convertDefaultJPJsonArrayCheckToTMJPJsonArrayCheck() {
assertThat("Clone MUST have expected length set to null.", clone.getExpectedLength(), is(nullValue()));
assertThat("Clone MUST have max length set to null.", clone.getMaxLength(), is(nullValue()));
assertThat("Clone MUST have min length set to null.", clone.getMinLength(), is(nullValue()));
assertThat("Clone MUST have null check set to false.", clone.isNullExpected(), is(equalTo(false)));
}

@Test(groups = unitTest)
public void convertJPJsonArrayCheckToTMJPJsonArrayCheck() {

JPJsonArrayCheck original = new JPJsonArrayCheck().hasLength(3).hasMaxLength(5).hasMinLength(1);
JPJsonArrayCheck original = new JPJsonArrayCheck().checkIsNull(true).hasLength(3).hasMaxLength(5).hasMinLength(1);
TMJPJsonArrayCheck clone = new TMJPJsonArrayCheck(original);

assertThat("Clone MUST have expected length set to expected.", clone.getExpectedLength(), is(equalTo(3)));
assertThat("Clone MUST have max length set to expected.", clone.getMaxLength(), is(equalTo(5)));
assertThat("Clone MUST have min length set to expected.", clone.getMinLength(), is(equalTo(1)));
assertThat("Clone MUST have null check set to true.", clone.isNullExpected(), is(equalTo(true)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ public void failWithNullObject() {
softAssert.assertAll();
}

@Test(expectedExceptions = AssertionError.class, groups = "unitTest")
public void failWithNonNullObject() {

SoftAssert softAssert = new SoftAssert();

DocumentContext jsonPathDocument = JsonPath.using(config).parse("{\"foo\":{\"first\":\"A\",\"second\":2,\"third\":true}}");
TMJPJsonObjectCheck check = new TMJPJsonObjectCheck();
check.checkIsNull(true);
check.processJsonPath("$.foo", softAssert, jsonPathDocument);

softAssert.assertAll();
}

@Test(groups = "unitTest")
public void passWithNullObject() {

SoftAssert softAssert = new SoftAssert();

DocumentContext jsonPathDocument = JsonPath.using(config).parse("{\"foo\":null}");
TMJPJsonObjectCheck check = new TMJPJsonObjectCheck();
check.checkIsNull(true);
check.processJsonPath("$.foo", softAssert, jsonPathDocument);

softAssert.assertAll();
}

@Test(expectedExceptions = AssertionError.class, groups = "unitTest")
public void failWithClassCastException() {

Expand Down Expand Up @@ -228,6 +254,22 @@ public void kotlinThinModelExportCheck() {
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("JPJsonObjectCheck()")));
}

@Test(groups = unitTest)
public void thinModelExportCheckNull() {

ThinModelSerializer serializer = new TMJPJsonObjectCheck().checkIsNull(true);
String serialized = serializer.getJavaStatements();
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("new JPJsonObjectCheck().checkIsNull(true)")));
}

@Test(groups = unitTest)
public void kotlinThinModelExportCheckNull() {

ThinModelSerializer serializer = new TMJPJsonObjectCheck().checkIsNull(true);
String serialized = serializer.getKotlinStatements();
MatcherAssert.assertThat("Serialized variant must match expected.", serialized, Matchers.is(Matchers.equalTo("JPJsonObjectCheck().checkIsNull(true)")));
}

@Test(groups = unitTest)
public void convertDefaultJPJsonObjectCheckToTMJPJsonObjectCheck() {

Expand All @@ -239,6 +281,7 @@ public void convertDefaultJPJsonObjectCheckToTMJPJsonObjectCheck() {
assertThat("Clone MUST have contains keys set to null.", clone.getContainsKeys(), is(nullValue()));
assertThat("Clone MUST have expected map set to null.", clone.getExpectedMap(), is(nullValue()));
assertThat("Clone MUST have contains map set to null.", clone.getContainsMap(), is(nullValue()));
assertThat("Clone MUST have null check set to false.", clone.isNullExpected(), is(equalTo(false)));
}

@Test(groups = unitTest)
Expand All @@ -252,13 +295,14 @@ public void convertJPJsonObjectCheckToTMJPJsonObjectCheck() {
HashMap<String, Object> containsMap = new HashMap<>();
containsMap.put("CONTAINS", "VALUE");

JPJsonObjectCheck original = new JPJsonObjectCheck().hasNumberOfKeys(3).keysAreEqualTo(expectedKeys).keysContain(containsKeys).isEqualTo(expectedMap).contains(containsMap);
JPJsonObjectCheck original = new JPJsonObjectCheck().checkIsNull(true).hasNumberOfKeys(3).keysAreEqualTo(expectedKeys).keysContain(containsKeys).isEqualTo(expectedMap).contains(containsMap);
TMJPJsonObjectCheck clone = new TMJPJsonObjectCheck(original);

assertThat("Clone MUST have expected number of keys set to expected.", clone.getExpectedNumberOfKeys(), is(equalTo(3)));
assertThat("Clone MUST have expected keys set to expected.", clone.getExpectedKeys(), is(equalTo(expectedKeys)));
assertThat("Clone MUST have contains keys set to expected.", clone.getContainsKeys(), is(equalTo(containsKeys)));
assertThat("Clone MUST have expected map set to expected.", clone.getExpectedMap(), is(equalTo(expectedMap)));
assertThat("Clone MUST have contains map set to expected.", clone.getContainsMap(), is(equalTo(containsMap)));
assertThat("Clone MUST have null check set to true.", clone.isNullExpected(), is(equalTo(true)));
}
}
Loading

0 comments on commit 75dd695

Please sign in to comment.