Skip to content

Commit

Permalink
🗑️ Deprecate Zero.Companion.fromByte(Byte) method (#688)
Browse files Browse the repository at this point in the history
This method is deprecated with an error level for using the `Zero.Companion.orThrow(Byte)` method instead.
  • Loading branch information
LVMVRQUXL committed Aug 3, 2024
1 parent 5a9a59f commit e09400f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -529,32 +529,15 @@ public class Zero {
* Creates an instance of [Zero] from the specified [number], or throws
* an [IllegalArgumentException] if the [number] is other than zero.
*
* <br>
* <details>
* <summary>
* <b>Calling from Kotlin</b>
* </summary>
*
* Here's an example of calling this function from Kotlin code:
*
* SAMPLE: [org.kotools.types.ZeroCompanionCommonSample.fromByte]
* </details>
*
* <br>
* <details>
* <summary>
* <b>Calling from Java</b>
* </summary>
*
* Here's an example of calling this function from Java code:
*
* SAMPLE: [org.kotools.types.ZeroCompanionJavaSample.fromByte]
* </details>
* <br>
*
* See the [fromByteOrNull] function for returning `null` instead of
* throwing an exception in case of invalid [number].
*/
@Deprecated(
"Use the 'orThrow' method instead.",
ReplaceWith("Zero.orThrow(number)", "org.kotools.types.Zero"),
DeprecationLevel.ERROR
)
@DeprecatedAsErrorSince(KotoolsTypesVersion.Unreleased)
@JvmStatic
public fun fromByte(number: Byte): Zero {
val zero = Zero()
Expand All @@ -581,7 +564,7 @@ public class Zero {
@DeprecatedAsErrorSince(KotoolsTypesVersion.Unreleased)
@JvmSynthetic
public fun fromByteOrNull(number: Byte): Zero? = try {
this.fromByte(number)
this.orThrow(number)
} catch (exception: IllegalArgumentException) {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ import kotlin.test.assertTrue

@OptIn(ExperimentalKotoolsTypesApi::class)
class ZeroCompanionCommonSample {
@Test
fun fromByte() {
val number: Byte = 0
val isSuccess: Boolean = try {
Zero.fromByte(number)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)
}

@Test
fun orNull() {
val number: Byte = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,6 @@ import kotlin.test.assertNull

@OptIn(ExperimentalKotoolsTypesApi::class)
class ZeroCompanionTest {
@Test
fun fromByteShouldPassWithByteThatEqualsZero() {
val number: Byte = 0
Zero.fromByte(number)
}

@Test
fun fromByteShouldFailWithByteOtherThanZero() {
val number: Byte = setOf(Byte.MIN_VALUE..-1, 1..Byte.MAX_VALUE)
.random()
.random()
.toByte()
val exception: IllegalArgumentException = assertFailsWith {
Zero.fromByte(number)
}
val actual: String? = exception.message
val expected: String = InvalidZero(number)
.toString()
assertEquals(expected, actual)
}

@Test
fun orNullShouldPassWithByteThatEqualsZero() {
val number: Byte = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@

@SuppressWarnings("NewClassNamingConvention")
class ZeroCompanionJavaSample {
@Test
void fromByte() {
final byte number = 0;
boolean isSuccess;
try {
Zero.fromByte(number);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);
}

@Test
void orThrow() {
final byte number = 0;
Expand Down

0 comments on commit e09400f

Please sign in to comment.