Skip to content

Commit

Permalink
check style issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmeline1101 committed Feb 17, 2024
1 parent eb0372d commit fa8d10b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 22 deletions.
Binary file not shown.
Binary file added documentation/images/.Interface.gif.icloud
Binary file not shown.
Binary file added documentation/images/.Schema_Topic.gif.icloud
Binary file not shown.
Binary file removed documentation/images/Connector_Topic_Consumer.gif
Binary file not shown.
Binary file removed documentation/images/Interface.gif
Binary file not shown.
Binary file removed documentation/images/Schema_Topic.gif
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,67 +1,91 @@
package com.provectus.kafka.ui.serdes.builtin;

import static org.assertj.core.api.Assertions.assertThat;
//Introducing JUnit's assertion library for test verification
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.google.common.primitives.Longs;
// Longs utility class in Guava library, used to handle conversion between long and byte
import com.google.common.primitives.Longs;
import com.provectus.kafka.ui.serde.api.DeserializeResult;
import com.provectus.kafka.ui.serde.api.Serde;
import com.provectus.kafka.ui.serdes.PropertyResolverImpl;
import com.provectus.kafka.ui.serdes.RecordHeadersImpl;
import org.apache.kafka.common.header.internals.RecordHeaders;
import org.junit.jupiter.api.BeforeEach; //JUnit's BeforeEach annotation is used to specify the method to be executed before each test method
import org.junit.jupiter.api.Test; //JUnit's Test annotation, used to mark test methods
import static org.junit.jupiter.api.Assertions.*;//Introducing JUnit's assertion library for test verification
import com.google.common.primitives.Longs; //Longs utility class in Guava library, used to handle conversion between long and byte
//JUnit's BeforeEach annotation is used to specify the method to be executed before each test method
import org.junit.jupiter.api.BeforeEach;
//JUnit's Test annotation, used to mark test methods
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;


class Int64SerdeTest {

private Int64Serde serde;//Test object
class Int64SerdeTest {
private Int64Serde serde; //Test object
//Initialization method executed before each test method is executed

@BeforeEach //Initialization method executed before each test method is executed
@BeforeEach
void init() {
serde = new Int64Serde();// Instantiate the test object
serde.configure(//original one
// Instantiate the test object
serde = new Int64Serde();
//original one
serde.configure(
PropertyResolverImpl.empty(),
PropertyResolverImpl.empty(),
PropertyResolverImpl.empty()
);
}

@Test
void testSerializeValidLong() {
String topic = "testSerializeValidLong";
String value = "1234567890"; //Define the value to be serialized
byte[] expected = Longs.toByteArray(Long.parseLong(value)); // expected byte sequence
byte[] actual = serde.serializer(topic, Serde.Target.VALUE).serialize(value); //Perform serialization operation
assertArrayEquals(expected, actual, "Serialization of a valid long should match expected bytes."); //Verify serialization results
//Define the value to be serialized
String value = "1234567890";
// expected byte sequence
byte[] expected = Longs.toByteArray(Long.parseLong(value));
//Perform serialization operation
byte[] actual = serde.serializer(topic, Serde.Target.VALUE).serialize(value);
//Verify serialization results
assertArrayEquals(expected, actual,
"Serialization of a valid long should match expected bytes.");
}

@Test
void testDeserializeValidBytes() {
String topic = "testDeserializeValidBytes";
long value = 1234567890L; //Define the value to be deserialized
byte[] bytes = Longs.toByteArray(value); // Convert long value to byte sequence
DeserializeResult result = serde.deserializer(topic, Serde.Target.VALUE).deserialize(null, bytes); //Perform deserialization operation
assertEquals(String.valueOf(value), result.getResult(), "Deserialization should match the original long value as a string."); //Verify deserialization results
//Define the value to be deserialized
long value = 1234567890L;
// Convert long value to byte sequence
byte[] bytes = Longs.toByteArray(value);
//Perform deserialization operation
DeserializeResult result = serde.deserializer(topic, Serde.Target.VALUE).deserialize(null, bytes);
//Verify deserialization results
assertEquals(String.valueOf(value), result.getResult(),
"Deserialization should match the original long value as a string.");
}

@Test
void testSerializeInvalidInputThrowsException() {
String topic = "testSerializeInvalidInputThrowsExceptio";
String invalidInput = "not a number";
assertThrows(NumberFormatException.class, () -> serde.serializer(topic, Serde.Target.VALUE).serialize(invalidInput),////Exception thrown when validating invalid input during serialization
"Serialization of invalid input should throw NumberFormatException.");
//Exception thrown when validating invalid input during serialization
assertThrows(NumberFormatException.class, () ->
serde.serializer(topic, Serde.Target.VALUE).serialize(invalidInput),
"Serialization of invalid input should throw NumberFormatException.");
}

@Test
void testDeserializeInvalidBytesThrowsException() {
String topic = "testDeserializeInvalidBytesThrowsException";
byte[] invalidBytes = new byte[]{1, 2, 3, 4}; // invalid: Less than 8 bytes required for a long
// invalid: Less than 8 bytes required for a long
byte[] invalidBytes = new byte[]{1, 2, 3, 4};
//Exception thrown when verifying deserialization of invalid byte sequence
assertThrows(IllegalArgumentException.class, () -> serde.deserializer(topic, Serde.Target.VALUE).deserialize(null, invalidBytes),//
"Deserialization of invalid bytes should throw IllegalArgumentException.");
assertThrows(IllegalArgumentException.class, ()
-> serde.deserializer(topic, Serde.Target.VALUE).deserialize(null, invalidBytes),
"Deserialization of invalid bytes should throw IllegalArgumentException.");
}

@ParameterizedTest
Expand Down

0 comments on commit fa8d10b

Please sign in to comment.