Skip to content

Commit

Permalink
Merge pull request #2787 from doom15/master
Browse files Browse the repository at this point in the history
No need to compare format when compare Quantity
  • Loading branch information
k8s-ci-robot authored Sep 11, 2023
2 parents 2d69ad6 + 4e82823 commit e2128a9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public boolean equals(Object o) {

Quantity otherQuantity = (Quantity) o;

return ObjectUtils.compare(this.number, otherQuantity.number) == 0
&& Objects.equals(this.format, otherQuantity.format);
return ObjectUtils.compare(this.number, otherQuantity.number) == 0;
}

public static class QuantityAdapter extends TypeAdapter<Quantity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,35 @@
import static org.junit.Assert.assertThat;

import java.math.BigDecimal;

import org.junit.Assert;
import org.junit.Test;

public class QuantityFormatterTest {

@Test
public void testEqualsAfterSerialAndDeSerial() {
testSerialDeSerial("0.5Gi");
testSerialDeSerial("0.5G");
testSerialDeSerial("1Gi");
testSerialDeSerial("1G");
testSerialDeSerial("500Mi");
testSerialDeSerial("500M");
testSerialDeSerial("500m");
testSerialDeSerial("0.5");
testSerialDeSerial("1");
}

private static void testSerialDeSerial(String value) {
Quantity quantity = Quantity.fromString(value);
// simulate the serialize-method
String suffixedString = quantity.toSuffixedString();
// simulate the deserialize-method, @see io.kubernetes.client.custom.Quantity.QuantityAdapter
Quantity deSerial = Quantity.fromString(suffixedString);

Assert.assertEquals(quantity,deSerial);
}

@Test
public void testParsePlain() {
final Quantity quantity = new QuantityFormatter().parse("1");
Expand Down

0 comments on commit e2128a9

Please sign in to comment.