Skip to content

Commit

Permalink
test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
li-ukumar committed Feb 15, 2024
1 parent 5d7363b commit 547fc37
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Utf8> utf8List;
List<vs14.BuilderTester> recordList;

Map<Utf8, Utf8> utf8Map;
Map<String, vs14.BuilderTester> recordMap;

@BeforeTest
public void testCollectionView(Class<?> clazz) {

utf8List = new ArrayList<>();
recordList = new ArrayList<>();

utf8Map = new HashMap<>();
recordMap = new HashMap<>();
}

@Test
public void testStringListView() {
List<Utf8> utf8List = new ArrayList<>();
String element = "test";
List<String> listOfElements = Arrays.asList("test", "test2", "test3");
List<String> view = CollectionTransformerUtil.createStringListView(utf8List);
Expand Down Expand Up @@ -67,6 +55,7 @@ public void testStringListView() {

@Test
public void testUtf8ListView() {
List<Utf8> utf8List = new ArrayList<>();
Utf8 element = new Utf8("test");
List<Utf8> listOfElements = Arrays.asList(new Utf8("test"), new Utf8("test2"), new Utf8("test3"));
List<Utf8> view = CollectionTransformerUtil.createUtf8ListView(utf8List);
Expand Down Expand Up @@ -103,20 +92,21 @@ public void testUtf8ListView() {

@Test
public void testCharSequenceListView() {
Utf8 element = new Utf8("test");
List<Utf8> utf8List = new ArrayList<>();
String element = "test";
List<Utf8> listOfElements = Arrays.asList(new Utf8("test"), new Utf8("test2"), new Utf8("test3"));
List<CharSequence> view = CollectionTransformerUtil.createCharSequenceListView(utf8List);
// utf8 list is empty
Assert.assertEquals(utf8List.size(), 0);
// 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);
Expand All @@ -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) {
Expand All @@ -139,6 +129,7 @@ public void testCharSequenceListView() {

@Test
public void testStringMapView() {
Map<Utf8, Utf8> utf8Map = new HashMap<>();
List<String> keys = Arrays.asList("key1", "key2", "key3");
String val = "value";

Expand All @@ -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);
}
Expand All @@ -173,6 +164,7 @@ public void testStringMapView() {

@Test
public void testUtf8MapView() {
Map<Utf8, Utf8> utf8Map = new HashMap<>();
List<Utf8> keys = Arrays.asList(new Utf8("key1"), new Utf8("key2"), new Utf8("key3"));
Utf8 val = new Utf8("value");

Expand Down Expand Up @@ -206,6 +198,7 @@ public void testUtf8MapView() {

@Test
public void testCharSequenceMapView() {
Map<Utf8, Utf8> utf8Map = new HashMap<>();
List<CharSequence> keys = Arrays.asList("key1", "key2", "key3");
String val = "value";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ public boolean addAll(int index, java.util.Collection<? extends CharSequence> c)
}
return modified;
}

@Override
public boolean remove(Object o) {
return utf8List.remove(new Utf8(o.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public boolean addAll(int index, java.util.Collection<? extends String> c) {
}
return modified;
}

@Override
public boolean remove(Object o) {
return _utf8List.remove(new Utf8(o.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public boolean add(Utf8 element) {
public boolean addAll(int index, java.util.Collection<? extends Utf8> c) {
return utf8List.addAll(index, c);
}

@Override
public boolean remove(Object o) {
return utf8List.remove(o);
}
}

0 comments on commit 547fc37

Please sign in to comment.