diff --git a/avro-builder/tests/tests-allavro/src/test/java/com/linkedin/avroutil1/compatibility/collectiontransformer/CollectionViewTest.java b/avro-builder/tests/tests-allavro/src/test/java/com/linkedin/avroutil1/compatibility/collectiontransformer/CollectionViewTest.java index b3e19c0f..fde87bd2 100644 --- a/avro-builder/tests/tests-allavro/src/test/java/com/linkedin/avroutil1/compatibility/collectiontransformer/CollectionViewTest.java +++ b/avro-builder/tests/tests-allavro/src/test/java/com/linkedin/avroutil1/compatibility/collectiontransformer/CollectionViewTest.java @@ -1,3 +1,8 @@ +/* + * Copyright 2024 LinkedIn Corp. + * Licensed under the BSD 2-Clause License (the "License"). + * See License in the project root for license information. + */ package com.linkedin.avroutil1.compatibility.collectiontransformer; import java.util.ArrayList; @@ -7,30 +12,13 @@ import java.util.Map; import org.apache.avro.util.Utf8; import org.testng.Assert; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class CollectionViewTest { - - List utf8List; - List recordList; - - Map utf8Map; - Map recordMap; - - @BeforeTest - public void testCollectionView(Class clazz) { - - utf8List = new ArrayList<>(); - recordList = new ArrayList<>(); - - utf8Map = new HashMap<>(); - recordMap = new HashMap<>(); - } - @Test public void testStringListView() { + List utf8List = new ArrayList<>(); String element = "test"; List listOfElements = Arrays.asList("test", "test2", "test3"); List view = CollectionTransformerUtil.createStringListView(utf8List); @@ -67,6 +55,7 @@ public void testStringListView() { @Test public void testUtf8ListView() { + List utf8List = new ArrayList<>(); Utf8 element = new Utf8("test"); List listOfElements = Arrays.asList(new Utf8("test"), new Utf8("test2"), new Utf8("test3")); List view = CollectionTransformerUtil.createUtf8ListView(utf8List); @@ -103,7 +92,8 @@ public void testUtf8ListView() { @Test public void testCharSequenceListView() { - Utf8 element = new Utf8("test"); + List utf8List = new ArrayList<>(); + String element = "test"; List listOfElements = Arrays.asList(new Utf8("test"), new Utf8("test2"), new Utf8("test3")); List view = CollectionTransformerUtil.createCharSequenceListView(utf8List); // utf8 list is empty @@ -111,12 +101,12 @@ public void testCharSequenceListView() { // view should be empty Assert.assertEquals(view.size(), 0); - // add a utf8 to the view + // add to the view view.add(element); // view should have 1 element Assert.assertTrue(view.contains(element)); - // utf8 list should contain the same element - Assert.assertTrue(utf8List.contains(element)); + // utf8 list should contain the same element in Utf8 form + Assert.assertTrue(utf8List.contains(new Utf8(element))); // remove the element from the view view.remove(element); @@ -129,7 +119,7 @@ public void testCharSequenceListView() { view.addAll(listOfElements); // view should have 3 elements for (Utf8 u : listOfElements) { - Assert.assertTrue(view.contains(u)); + Assert.assertTrue(view.contains(String.valueOf(u))); } // utf8 list should contain the same 3 elements for (Utf8 u : listOfElements) { @@ -139,6 +129,7 @@ public void testCharSequenceListView() { @Test public void testStringMapView() { + Map utf8Map = new HashMap<>(); List keys = Arrays.asList("key1", "key2", "key3"); String val = "value"; @@ -163,7 +154,7 @@ public void testStringMapView() { Assert.assertTrue(utf8Map.containsKey(new Utf8(key))); } - // remove from view + // remove from map for (String key : keys) { map.remove(key); } @@ -173,6 +164,7 @@ public void testStringMapView() { @Test public void testUtf8MapView() { + Map utf8Map = new HashMap<>(); List keys = Arrays.asList(new Utf8("key1"), new Utf8("key2"), new Utf8("key3")); Utf8 val = new Utf8("value"); @@ -206,6 +198,7 @@ public void testUtf8MapView() { @Test public void testCharSequenceMapView() { + Map utf8Map = new HashMap<>(); List keys = Arrays.asList("key1", "key2", "key3"); String val = "value"; diff --git a/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/CharSequenceListView.java b/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/CharSequenceListView.java index dfc1e920..000c7dfb 100644 --- a/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/CharSequenceListView.java +++ b/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/CharSequenceListView.java @@ -55,4 +55,9 @@ public boolean addAll(int index, java.util.Collection c) } return modified; } + + @Override + public boolean remove(Object o) { + return utf8List.remove(new Utf8(o.toString())); + } } diff --git a/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/StringListView.java b/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/StringListView.java index 0c630131..8fba353f 100644 --- a/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/StringListView.java +++ b/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/StringListView.java @@ -56,4 +56,9 @@ public boolean addAll(int index, java.util.Collection c) { } return modified; } + + @Override + public boolean remove(Object o) { + return _utf8List.remove(new Utf8(o.toString())); + } } diff --git a/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/Utf8ListView.java b/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/Utf8ListView.java index f822a753..c3724f6b 100644 --- a/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/Utf8ListView.java +++ b/helper/helper/src/main/java/com/linkedin/avroutil1/compatibility/collectiontransformer/Utf8ListView.java @@ -50,4 +50,9 @@ public boolean add(Utf8 element) { public boolean addAll(int index, java.util.Collection c) { return utf8List.addAll(index, c); } + + @Override + public boolean remove(Object o) { + return utf8List.remove(o); + } }