Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.utils;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class CharSequenceComparatorTest {

@Test
public void testCompare() {
CharSequenceComparator comparator = CharSequenceComparator.INSTANCE;

// 1: Identify Equal tests
assertEquals(0, comparator.compare("dubbo", "dubbo"));

// 2. Alphabet test
assertTrue(comparator.compare("apple", "banana") < 0);
assertTrue(comparator.compare("banana", "apple") > 0);

// 3. Mixed types (String vs StringBuilder)
StringBuilder sb = new StringBuilder("abc");
String s = "abc";
assertEquals(0, comparator.compare(s, sb));

// case Sensitivity
assertTrue(comparator.compare("Apple", "apple") < 0);

// Length test
assertTrue(comparator.compare("dubbo", "dubbo3") < 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.utils;

import java.util.Iterator;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class ConcurrentHashSetTest {

@Test
public void iteratorTest() {
ConcurrentHashSet<String> set = new ConcurrentHashSet<>();
set.add("A");
set.add("B");

Iterator<String> it = set.iterator();
int count = 0;

while (it.hasNext()) {
it.next();
count += 1;
}
assertEquals(2, count);
}

@Test
public void sizeTest() {
ConcurrentHashSet<Integer> set = new ConcurrentHashSet<>();
set.add(1);
set.add(2);
assertEquals(2, set.size());
}

@Test
public void isEmptyTest() {
ConcurrentHashSet<String> set = new ConcurrentHashSet<>();
assertTrue(set.isEmpty()); // since I have not add anything it is true
set.add("pen");
assertFalse(set.isEmpty()); // It has sth in , so it is false if I say isEmpty
}

@Test
public void containTest() {
ConcurrentHashSet<String> set = new ConcurrentHashSet<>();
set.add("Banana");
// will find banana because it is there
assertTrue(set.contains("Banana"));
// will ignore Orange because we don't have it
assertFalse(set.contains("Orange"));
}

@Test
public void addTest() {
ConcurrentHashSet<String> set = new ConcurrentHashSet<>();
assertTrue(set.add("Apple"));
// If i add apple again , will return false since it is there
assertFalse(set.add("Apple"));
// size will retain 1
assertEquals(1, set.size());
}

@Test
public void removeTest() {
ConcurrentHashSet<String> set = new ConcurrentHashSet<>();
set.add("apple");
// True it removes because there is apple in there
assertTrue(set.remove("apple"));
// Now the set is empty
assertEquals(0, set.size());
}

@Test
public void clearTest() {
ConcurrentHashSet<String> set = new ConcurrentHashSet<>();
set.add("A");
set.add("B");

set.clear();

// now it is empty
assertEquals(0, set.size());
assertTrue(set.isEmpty());
}
}
Loading