Skip to content

Commit

Permalink
Improve java docs and use @ParameterizedTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Gutierrez authored and Manuel Gutierrez committed Aug 1, 2022
1 parent 692f8f5 commit 33d0319
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,7 @@ public SELF hasPackage(Package aPackage) {
* assertThat(chart.class).isPrimitive();
*
* // this assertion fails as objects are not primitive data types:
* assertThat(Object.class).isPrimitive(); ;
* </code></pre>
* assertThat(Object.class).isPrimitive(); </code></pre>
*
* @return {@code this} assertions object
* @throws AssertionError if {@code actual} is {@code null}.
Expand All @@ -835,7 +834,7 @@ public SELF isPrimitive() {
* <p>
* Example
* <pre><code class='java'> // this assertions succeeds as objects are not primitive data types:
* assertThat(Object.class).isNotPrimitive(); ;
* assertThat(Object.class).isNotPrimitive();
*
* // these assertions fail:
* assertThat(byte.class).isNotPrimitive();
Expand All @@ -845,7 +844,7 @@ public SELF isPrimitive() {
* assertThat(float.class).isNotPrimitive();
* assertThat(double.class).isNotPrimitive();
* assertThat(boolean.class).isNotPrimitive();
* assertThat(chart.class).isNotPrimitive();
* assertThat(chart.class).isNotPrimitive(); </code></pre>
* @return {@code this} assertions object
* @throws AssertionError if {@code actual} is {@code null}.
* @throws AssertionError if the actual {@code Class} is a primitive data type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2022 the original author or authors.
*/
package org.assertj.core.error;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2022 the original author or authors.
*/
package org.assertj.core.api.classes;

import static org.mockito.Mockito.verify;
Expand All @@ -6,11 +18,11 @@
import org.assertj.core.api.ClassAssertBaseTest;

/**
* * Tests for <code>{@link ClassAssert#isNotPrimitive()} ()} ()}</code>.
* *
* * @author Manuel Gutierrez
* Tests for <code>{@link ClassAssert#isNotPrimitive()} ()} ()}</code>.
*
* @author Manuel Gutierrez
*/
public class ClassAssert_isNotPrimitive_Test extends ClassAssertBaseTest {
class ClassAssert_isNotPrimitive_Test extends ClassAssertBaseTest {

@Override
protected ClassAssert invoke_api_method() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2022 the original author or authors.
*/
package org.assertj.core.api.classes;

import static org.mockito.Mockito.verify;
Expand All @@ -6,9 +18,9 @@
import org.assertj.core.api.ClassAssertBaseTest;

/**
* * Tests for <code>{@link ClassAssert#isPrimitive()} ()}</code>.
* *
* * @author Manuel Gutierrez
* Tests for <code>{@link ClassAssert#isPrimitive()} ()}</code>.
*
* @author Manuel Gutierrez
*/
class ClassAssert_isPrimitive_Test extends ClassAssertBaseTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2022 the original author or authors.
*/
package org.assertj.core.internal.classes;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -10,6 +22,8 @@
import org.assertj.core.api.AssertionInfo;
import org.assertj.core.internal.ClassesBaseTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Tests for
Expand Down Expand Up @@ -37,82 +51,14 @@ void should_fail_if_actual_is_null() {
then(assertionError).hasMessage(actualIsNull());
}

@Test
void should_fail_if_actual_has_byte_type() {
// GIVEN
actual = byte.class;
//WHEN
AssertionError assertionError = expectAssertionError(() -> assertThat(actual).isNotPrimitive());
//THEN
then(assertionError).hasMessage(shouldNotBePrimitive(actual).create());
}

@Test
void should_fail_if_actual_has_short_type() {
// GIVEN
actual = short.class;
// WHEN
AssertionError assertionError = expectAssertionError(() -> assertThat(actual).isNotPrimitive());
// THEN
then(assertionError).hasMessage(shouldNotBePrimitive(actual).create());
}

@Test
void should_fail_if_actual_has_int_type() {
actual = int.class;
// WHEN
AssertionError assertionError = expectAssertionError(() -> assertThat(actual).isNotPrimitive());
// THEN
then(assertionError).hasMessage(shouldNotBePrimitive(actual).create());
}

@Test
void should_fail_if_actual_has_long_type() {
// GIVEN
actual = long.class;
// WHEN
AssertionError assertionError = expectAssertionError(() -> assertThat(actual).isNotPrimitive());
// THEN
then(assertionError).hasMessage(shouldNotBePrimitive(actual).create());
}

@Test
void should_fail_if_actual_has_float_type() {
// GIVEN
actual = float.class;
// WHEN
AssertionError assertionError = expectAssertionError(() -> assertThat(actual).isNotPrimitive());
// THEN
then(assertionError).hasMessage(shouldNotBePrimitive(actual).create());
}

@Test
void should_fail_if_actual_has_double_type() {
// GIVEN
actual = double.class;
// WHEN
AssertionError assertionError = expectAssertionError(() -> assertThat(actual).isNotPrimitive());
// THEN
then(assertionError).hasMessage(shouldNotBePrimitive(actual).create());
}

@Test
void should_fail_if_actual_has_boolean_type() {
// GIVEN
actual = boolean.class;
@ParameterizedTest
@ValueSource(classes = { byte.class, short.class, int.class, long.class, float.class, double.class, boolean.class,
char.class })
void should_fail_if_actual_is_a_primitive_type(Class<?> primitiveClass) {
// WHEN
AssertionError assertionError = expectAssertionError(() -> assertThat(actual).isNotPrimitive());
AssertionError assertionError = expectAssertionError(() -> assertThat(primitiveClass).isNotPrimitive());
// THEN
then(assertionError).hasMessage(shouldNotBePrimitive(actual).create());
then(assertionError).hasMessage(shouldNotBePrimitive(primitiveClass).create());
}

@Test
void should_fail_if_actual_has_char_type() {
// GIVEN
actual = char.class;
// WHEN
AssertionError assertionError = expectAssertionError(() -> assertThat(actual).isNotPrimitive());
// THEN
then(assertionError).hasMessage(shouldNotBePrimitive(actual).create());
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2022 the original author or authors.
*/
package org.assertj.core.internal.classes;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -10,6 +22,8 @@
import org.assertj.core.api.AssertionInfo;
import org.assertj.core.internal.ClassesBaseTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Tests for
Expand All @@ -19,68 +33,12 @@
*/
class Classes_assertIsPrimitive_Test extends ClassesBaseTest {

@Test
void should_pass_if_actual_has_byte_type() {
// GIVEN
actual = byte.class;
// WHEN/THEN
classes.assertIsPrimitive(someInfo(), actual);
}

@Test
void should_pass_if_actual_has_short_type() {
// GIVEN
actual = short.class;
// WHEN/THEN
classes.assertIsPrimitive(someInfo(), actual);
}

@Test
void should_pass_if_actual_has_int_type() {
// GIVEN
actual = int.class;
// WHEN/THEN
classes.assertIsPrimitive(someInfo(), actual);
}

@Test
void should_pass_if_actual_has_long_type() {
// GIVEN
actual = long.class;
// WHEN/THEN
classes.assertIsPrimitive(someInfo(), actual);
}

@Test
void should_pass_if_actual_has_float_type() {
// GIVEN
actual = float.class;
// WHEN/THEN
classes.assertIsPrimitive(someInfo(), actual);
}

@Test
void should_pass_if_actual_has_double_type() {
// GIVEN
actual = double.class;
// WHEN/THEN
classes.assertIsPrimitive(someInfo(), actual);
}

@Test
void should_pass_if_actual_has_boolean_type() {
// GIVEN
actual = boolean.class;
// WHEN/THEN
classes.assertIsPrimitive(someInfo(), actual);
}

@Test
void should_pass_if_actual_has_char_type() {
// GIVEN
actual = char.class;
@ParameterizedTest
@ValueSource(classes = { byte.class, short.class, int.class, long.class, float.class, double.class, boolean.class,
char.class })
void should_pass_if_actual_is_a_primitive_type(Class<?> primitiveClass) {
// WHEN/THEN
classes.assertIsPrimitive(someInfo(), actual);
classes.assertIsPrimitive(someInfo(), primitiveClass);
}

@Test
Expand Down

0 comments on commit 33d0319

Please sign in to comment.