-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
211 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,14 @@ | |
*/ | ||
package org.apache.ibatis.reflection.property; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* @author <a href="[email protected]">mawen12</a> | ||
* | ||
* @see PropertyTokenizer | ||
*/ | ||
class PropertyTokenizerTest { | ||
|
@@ -39,9 +40,8 @@ void shouldParsePropertySuccessfully() { | |
assertFalse(tokenizer.hasNext()); | ||
assertNull(tokenizer.getIndex()); | ||
|
||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(tokenizer::remove) | ||
.withMessage("Remove is not supported, as it has no meaning in the context of properties."); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(tokenizer::remove) | ||
.withMessage("Remove is not supported, as it has no meaning in the context of properties."); | ||
} | ||
|
||
@Test | ||
|
@@ -56,9 +56,8 @@ void shouldParsePropertyWhichContainsDelimSuccessfully() { | |
|
||
assertNull(tokenizer.getIndex()); | ||
|
||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(tokenizer::remove) | ||
.withMessage("Remove is not supported, as it has no meaning in the context of properties."); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(tokenizer::remove) | ||
.withMessage("Remove is not supported, as it has no meaning in the context of properties."); | ||
} | ||
|
||
@Test | ||
|
@@ -73,8 +72,7 @@ void shouldParsePropertyWhichContainsIndexSuccessfully() { | |
assertFalse(tokenizer.hasNext()); | ||
assertNull(tokenizer.getChildren()); | ||
|
||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(tokenizer::remove) | ||
.withMessage("Remove is not supported, as it has no meaning in the context of properties."); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(tokenizer::remove) | ||
.withMessage("Remove is not supported, as it has no meaning in the context of properties."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,24 +15,25 @@ | |
*/ | ||
package org.apache.ibatis.reflection.wrapper; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.ibatis.domain.blog.Author; | ||
import org.apache.ibatis.domain.misc.RichType; | ||
import org.apache.ibatis.reflection.SystemMetaObject; | ||
import org.apache.ibatis.reflection.property.PropertyTokenizer; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* @author <a href="[email protected]">mawen12</a> | ||
* | ||
* @see BeanWrapper | ||
*/ | ||
class BeanWrapperUnitTest extends ObjectWrapperBaseTest { | ||
|
@@ -71,10 +72,12 @@ void shouldGetWhichContainsDelim() { | |
@Test | ||
void shouldGetWhichContainsIndex() { | ||
richType.setRichList(Arrays.asList(1L, "abc")); | ||
richType.setRichMap(new HashMap<String, Object>(){{ | ||
put("key1", "value1"); | ||
put("key2", "value2"); | ||
}}); | ||
richType.setRichMap(new HashMap<String, Object>() { | ||
{ | ||
put("key1", "value1"); | ||
put("key2", "value2"); | ||
} | ||
}); | ||
|
||
assertEquals("abc", wrapper.get(new PropertyTokenizer("richList[1]"))); | ||
assertEquals("value2", wrapper.get(new PropertyTokenizer("richMap[key2]"))); | ||
|
@@ -199,15 +202,13 @@ void shouldInstantiatePropertyValue() { | |
@Test | ||
@Override | ||
void shouldAddElement() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.add("1")); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.add("1")); | ||
} | ||
|
||
@Test | ||
@Override | ||
void shouldAddAll() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.addAll(new ArrayList<>())); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.addAll(new ArrayList<>())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,10 @@ | |
*/ | ||
package org.apache.ibatis.reflection.wrapper; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
@@ -28,12 +32,9 @@ | |
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* @author <a href="[email protected]">mawen12</a> | ||
* | ||
* @see CollectionWrapper | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
|
@@ -56,64 +57,55 @@ void setup() { | |
@Test | ||
@Override | ||
void shouldGet() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.get(tokenizer)); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.get(tokenizer)); | ||
} | ||
|
||
@Test | ||
@Override | ||
void shouldSet() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.set(tokenizer, null)); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.set(tokenizer, null)); | ||
} | ||
|
||
@Test | ||
@Override | ||
void shouldFindProperty() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.findProperty("abc", true)); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.findProperty("abc", true)); | ||
} | ||
|
||
@Test | ||
@Override | ||
void shouldGetGetterNames() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.getGetterNames()); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.getGetterNames()); | ||
} | ||
|
||
@Test | ||
@Override | ||
void shouldGetSetterNames() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.getSetterNames()); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.getSetterNames()); | ||
} | ||
|
||
@Test | ||
@Override | ||
void shouldGetGetterType() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.getGetterType("abc")); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.getGetterType("abc")); | ||
} | ||
|
||
@Test | ||
@Override | ||
void shouldGetSetterType() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.getSetterType("abc")); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.getSetterType("abc")); | ||
} | ||
|
||
@Test | ||
@Override | ||
void shouldHasGetter() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.hasGetter("abc")); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.hasGetter("abc")); | ||
} | ||
|
||
@Test | ||
@Override | ||
void shouldHasSetter() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.hasSetter("abc")); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.hasSetter("abc")); | ||
} | ||
|
||
@Test | ||
|
@@ -126,7 +118,7 @@ void shouldIsCollection() { | |
@Override | ||
void shouldInstantiatePropertyValue() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.instantiatePropertyValue("abc", tokenizer, null)); | ||
.isThrownBy(() -> wrapper.instantiatePropertyValue("abc", tokenizer, null)); | ||
} | ||
|
||
@Test | ||
|
@@ -140,11 +132,13 @@ void shouldAddElement() { | |
@Test | ||
@Override | ||
void shouldAddAll() { | ||
List<Object> list = new ArrayList<>() {{ | ||
add("1"); | ||
add("2"); | ||
add("3"); | ||
}}; | ||
List<Object> list = new ArrayList<>() { | ||
{ | ||
add("1"); | ||
add("2"); | ||
add("3"); | ||
} | ||
}; | ||
wrapper.addAll(list); | ||
|
||
verify(collection).addAll(list); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,12 @@ | |
*/ | ||
package org.apache.ibatis.reflection.wrapper; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
|
@@ -30,12 +36,9 @@ | |
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* @author <a href="[email protected]">mawen12</a> | ||
* | ||
* @see MapWrapper | ||
*/ | ||
class MapWrapperUnitTest extends ObjectWrapperBaseTest { | ||
|
@@ -99,9 +102,11 @@ void shouldSet() { | |
void shouldSetWhichContainsDelim() { | ||
wrapper.set(new PropertyTokenizer("author.id"), 1); | ||
|
||
verify(map).put("author", new HashMap<>() {{ | ||
put("id", 1); | ||
}}); | ||
verify(map).put("author", new HashMap<>() { | ||
{ | ||
put("id", 1); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
|
@@ -123,10 +128,12 @@ void shouldFindProperty() { | |
@Test | ||
@Override | ||
void shouldGetGetterNames() { | ||
Set<String> sets = new HashSet<>() {{ | ||
add("key1"); | ||
add("key2"); | ||
}}; | ||
Set<String> sets = new HashSet<>() { | ||
{ | ||
add("key1"); | ||
add("key2"); | ||
} | ||
}; | ||
when(map.keySet()).thenReturn(sets); | ||
|
||
String[] getterNames = wrapper.getGetterNames(); | ||
|
@@ -138,10 +145,12 @@ void shouldGetGetterNames() { | |
@Test | ||
@Override | ||
void shouldGetSetterNames() { | ||
Set<String> sets = new HashSet<>() {{ | ||
add("key1"); | ||
add("key2"); | ||
}}; | ||
Set<String> sets = new HashSet<>() { | ||
{ | ||
add("key1"); | ||
add("key2"); | ||
} | ||
}; | ||
when(map.keySet()).thenReturn(sets); | ||
|
||
String[] setterNames = wrapper.getSetterNames(); | ||
|
@@ -219,22 +228,21 @@ void shouldIsCollection() { | |
@Test | ||
@Override | ||
void shouldInstantiatePropertyValue() { | ||
MetaObject result = wrapper.instantiatePropertyValue("abc", new PropertyTokenizer("key"), SystemMetaObject.DEFAULT_OBJECT_FACTORY); | ||
MetaObject result = wrapper.instantiatePropertyValue("abc", new PropertyTokenizer("key"), | ||
SystemMetaObject.DEFAULT_OBJECT_FACTORY); | ||
|
||
assertFalse(result.hasGetter("key")); | ||
} | ||
|
||
@Test | ||
@Override | ||
void shouldAddElement() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.add("1")); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.add("1")); | ||
} | ||
|
||
@Test | ||
@Override | ||
void shouldAddAll() { | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> wrapper.addAll(new ArrayList<>())); | ||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.addAll(new ArrayList<>())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
|
||
/** | ||
* @author <a href="[email protected]">mawen12</a> | ||
* | ||
* @see ObjectWrapper | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
|
Oops, something went wrong.