Skip to content

Commit

Permalink
Reformatting the file. Fixes apolloconfig#3874.
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush0407 committed Mar 27, 2022
1 parent 5746275 commit 5042a88
Showing 1 changed file with 23 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,55 @@

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import com.ctrip.framework.apollo.common.exception.BeanUtilsException;

@RunWith(MockitoJUnitRunner.class)
public class BeanUtilsTest {

@InjectMocks
private BeanUtils beanUtils;
List<Integer> someList;
List<KeyClass> someAnotherList;

@Before
public void setUp() {
someList = new ArrayList<>();
someAnotherList = new ArrayList<>();
}

@Test
public void testBatchTransformListNotEmpty() {
List<Integer> someList = new ArrayList<>();
someList.add(77);
assertNotNull(BeanUtils.batchTransform(String.class, someList));
}

@Test
public void testBatchTransformListIsEmpty() {
List<Integer> someList = new ArrayList<>();
assertNotNull(BeanUtils.batchTransform(String.class, someList));
}

@Test(expected = BeanUtilsException.class)
public void testBatchTransformBeanUtilsException() {
List<Integer> someList = new ArrayList<>();
someList.add(77);
assertNotNull(BeanUtils.batchTransform(null, someList));
}

@Test
public void testBatchTransformSrcIsNull() {
List<Integer> someList = new ArrayList<>();
someList.add(null);
assertNotNull(BeanUtils.batchTransform(String.class, someList));
}

@Test
public void testMapByKeyEmptyList() {
List<Integer> someList = new ArrayList<>();
assertNotNull(BeanUtils.mapByKey(null, someList));

}

class KeyClass {
Expand All @@ -74,73 +73,54 @@ class KeyClass {

@Test
public void testMapByKeyNotEmptyList() {
List<KeyClass> someList = new ArrayList<>();
someList.add(new KeyClass());
assertNotNull(BeanUtils.mapByKey("keys", someList));

someAnotherList.add(new KeyClass());
assertNotNull(BeanUtils.mapByKey("keys", someAnotherList));
}

@Test(expected = BeanUtilsException.class)
public void testMapByKeyNotEmptyListThrowsEx() {
List<KeyClass> someList = new ArrayList<>();
someList.add(new KeyClass());
assertNotNull(BeanUtils.mapByKey("wrongKey", someList));

someAnotherList.add(new KeyClass());
assertNotNull(BeanUtils.mapByKey("wrongKey", someAnotherList));
}

@Test
public void testAggByKeyToListEmpty() {
List<KeyClass> someList = new ArrayList<>();
assertNotNull(BeanUtils.aggByKeyToList("keys", someList));

assertNotNull(BeanUtils.aggByKeyToList("keys", someAnotherList));
}

@Test
public void testAggByKeyToListNotEmpty() {
List<KeyClass> someList = new ArrayList<>();
someList.add(new KeyClass());
assertNotNull(BeanUtils.aggByKeyToList("keys", someList));

someAnotherList.add(new KeyClass());
assertNotNull(BeanUtils.aggByKeyToList("keys", someAnotherList));
}

@Test(expected = BeanUtilsException.class)
public void testAggByKeyToListNotEmptyThrowsEx() {
List<KeyClass> someList = new ArrayList<>();
someList.add(new KeyClass());
assertNotNull(BeanUtils.aggByKeyToList("wrongKey", someList));

someAnotherList.add(new KeyClass());
assertNotNull(BeanUtils.aggByKeyToList("wrongKey", someAnotherList));
}

@Test
public void testToPropertySetEmpty() {
List<KeyClass> someList = new ArrayList<>();
assertNotNull(BeanUtils.toPropertySet("keys", someList));

assertNotNull(BeanUtils.toPropertySet("keys", someAnotherList));
}

@Test
public void testToPropertySetNotEmpty() {
List<KeyClass> someList = new ArrayList<>();
someList.add(new KeyClass());
assertNotNull(BeanUtils.toPropertySet("keys", someList));

someAnotherList.add(new KeyClass());
assertNotNull(BeanUtils.toPropertySet("keys", someAnotherList));
}

@Test(expected = BeanUtilsException.class)
public void testToPropertySetNotEmptyThrowsEx() {
List<KeyClass> someList = new ArrayList<>();
someList.add(new KeyClass());
assertNotNull(BeanUtils.toPropertySet("wrongKey", someList));

someAnotherList.add(new KeyClass());
assertNotNull(BeanUtils.toPropertySet("wrongKey", someAnotherList));
}

@Test
public void testGetAndsetProperty() {
BeanUtils.setProperty(new KeyClass(), "keys", "value");
assertNull(BeanUtils.getProperty(new KeyClass(), "keys"));

}



}

0 comments on commit 5042a88

Please sign in to comment.