├── microsphere-java-core └── src │ ├── test │ ├── resources │ │ ├── test.txt │ │ ├── META-INF │ │ │ ├── .sar │ │ │ ├── temp.json │ │ │ ├── test.properties │ │ │ ├── test_zh_CN.properties │ │ │ ├── logging.properties │ │ │ ├── banned-artifacts │ │ │ ├── services │ │ │ │ ├── java.net.URLStreamHandlerFactory │ │ │ │ ├── org.junit.jupiter.api.extension.Extension │ │ │ │ ├── io.microsphere.event.EventListener │ │ │ │ └── io.microsphere.metadata.ConfigurationPropertyLoader │ │ │ ├── MANIFEST.MF │ │ │ ├── maven │ │ │ │ └── io │ │ │ │ │ └── github │ │ │ │ │ └── microsphere-projects │ │ │ │ │ └── microsphere-java-core │ │ │ │ │ └── pom.properties │ │ │ ├── microsphere │ │ │ │ └── additional-configuration-properties.json │ │ │ └── System.properties │ │ ├── junit-platform.properties │ │ ├── test │ │ │ └── json │ │ │ │ ├── clean.txt │ │ │ │ ├── array.json │ │ │ │ └── data.json │ │ └── logback-test.xml │ └── java │ │ └── io │ │ └── microsphere │ │ ├── performance │ │ ├── PerformanceAction.java │ │ └── AbstractPerformanceTest.java │ │ ├── reflect │ │ ├── AbstractJavaTypeKindTest.java │ │ ├── MultipleTypeTest.java │ │ ├── ClassDefinitionTest.java │ │ └── ConstructorDefinitionTest.java │ │ ├── logging │ │ ├── NoOpLoggerTest.java │ │ ├── ACLLoggerFactoryTest.java │ │ ├── Sfl4jLoggerFactoryTest.java │ │ └── JDKLoggerFactoryTest.java │ │ ├── util │ │ ├── BaseUtilsTest.java │ │ ├── ClassLoaderUtilsPerformanceTest.java │ │ ├── ShutdownHookCallbacksThreadTest.java │ │ └── CompatibleTest.java │ │ ├── filter │ │ ├── TrueClassFilterTest.java │ │ ├── PackageNameClassFilterTest.java │ │ ├── PackageNameClassNameFilterTest.java │ │ └── FilterUtilsTest.java │ │ ├── nio │ │ └── charset │ │ │ └── CharsetUtilsTest.java │ │ ├── collection │ │ ├── EmptyIterableTest.java │ │ ├── EmptyIteratorTest.java │ │ ├── SingletonIteratorTest.java │ │ ├── LinkedListTest.java │ │ ├── ArrayEnumerationTest.java │ │ ├── SingletonEnumerationTest.java │ │ ├── EnumerationIteratorAdapterTest.java │ │ └── UnmodifiableIteratorTest.java │ │ ├── event │ │ ├── AbstractEventDispatcherTest.java │ │ ├── ListenableTest.java │ │ ├── EchoEvent.java │ │ ├── EchoEventListener.java │ │ ├── GenericEventTest.java │ │ └── EventListenerTest.java │ │ ├── io │ │ ├── filter │ │ │ ├── TrueFileFilterTest.java │ │ │ ├── IOFileFilterTest.java │ │ │ ├── DirectoryFileFilterTest.java │ │ │ └── FileExtensionFilterTest.java │ │ ├── DefaultDeserializerTest.java │ │ ├── FileWatchServiceTest.java │ │ └── event │ │ │ ├── DefaultFileChangedListener.java │ │ │ └── FileChangedEventTest.java │ │ ├── classloading │ │ ├── ErrorArtifactResourceResolverTest.java │ │ ├── ManifestArtifactResourceResolverTest.java │ │ ├── MavenArtifactResourceResolverTest.java │ │ └── BannedArtifactClassLoadingExecutorTest.java │ │ ├── convert │ │ ├── StringToDurationConverterTest.java │ │ ├── StringToStringConverterTest.java │ │ ├── StringToCharArrayConverterTest.java │ │ ├── multiple │ │ │ └── StringToMultiValueConverterTest.java │ │ └── StringToClassConverterTest.java │ │ ├── test │ │ ├── D.java │ │ ├── StringBF2.java │ │ ├── StringIntegerF1.java │ │ ├── E.java │ │ ├── StringToIntegerF1.java │ │ ├── C.java │ │ ├── StringIntegerToBoolean.java │ │ ├── StringBooleanToInteger.java │ │ ├── A.java │ │ ├── BF3.java │ │ ├── StringIntegerBooleanHashMap.java │ │ ├── StringIntegerHashMap.java │ │ ├── B.java │ │ ├── MyHashMap.java │ │ └── StringIntegerToBooleanClass.java │ │ ├── process │ │ ├── ClassicProcessIdResolverTest.java │ │ ├── VirtualMachineProcessIdResolverTest.java │ │ └── ModernProcessIdResolverTest.java │ │ ├── management │ │ └── ManagementUtilsTest.java │ │ ├── net │ │ ├── console │ │ │ └── ConsoleURLConnectionTest.java │ │ ├── test │ │ │ └── Handler.java │ │ └── DelegatingURLStreamHandlerFactoryTest.java │ │ ├── annotation │ │ ├── ImmutableTest.java │ │ ├── ExperimentalTest.java │ │ └── SinceTest.java │ │ ├── lang │ │ ├── function │ │ │ └── ThrowableSupplierTest.java │ │ └── DelegatingWrapperImpl.java │ │ ├── metadata │ │ ├── NullConfigurationPropertyLoader.java │ │ ├── ErrorConfigurationPropertyLoader.java │ │ ├── EmptyConfigurationPropertyLoader.java │ │ └── DefaultConfigurationPropertyLoader.java │ │ └── constants │ │ └── PropertyConstantsTest.java │ └── main │ ├── resources │ └── META-INF │ │ └── services │ │ ├── io.microsphere.io.Serializer │ │ ├── io.microsphere.io.Deserializer │ │ ├── io.microsphere.metadata.ConfigurationPropertyReader │ │ ├── io.microsphere.metadata.ConfigurationPropertyGenerator │ │ ├── io.microsphere.event.EventDispatcher │ │ ├── io.microsphere.metadata.ConfigurationPropertyLoader │ │ ├── io.microsphere.net.ExtendableProtocolURLStreamHandler │ │ ├── io.microsphere.process.ProcessIdResolver │ │ ├── io.microsphere.classloading.URLClassPathHandle │ │ ├── io.microsphere.logging.LoggerFactory │ │ ├── io.microsphere.classloading.ArtifactResourceResolver │ │ └── io.microsphere.convert.multiple.MultiValueConverter │ └── java │ └── io │ └── microsphere │ ├── constants │ ├── Constants.java │ ├── PathConstants.java │ ├── SeparatorConstants.java │ ├── PropertyConstants.java │ └── ProtocolConstants.java │ ├── filter │ ├── ClassFilter.java │ ├── JarEntryFilter.java │ ├── TrueClassFilter.java │ ├── Filter.java │ └── ClassFileJarEntryFilter.java │ ├── json │ └── package-info.java │ ├── convert │ ├── StringConverter.java │ ├── multiple │ │ ├── StringToSetConverter.java │ │ ├── StringToListConverter.java │ │ ├── StringToDequeConverter.java │ │ ├── StringToSortedSetConverter.java │ │ ├── StringToCollectionConverter.java │ │ ├── StringToQueueConverter.java │ │ ├── StringToNavigableSetConverter.java │ │ ├── StringToTransferQueueConverter.java │ │ ├── StringToBlockingDequeConverter.java │ │ └── StringToBlockingQueueConverter.java │ ├── StringToByteConverter.java │ ├── StringToCharArrayConverter.java │ ├── StringToLongConverter.java │ ├── StringToFloatConverter.java │ ├── StringToShortConverter.java │ ├── StringToDoubleConverter.java │ ├── StringToStringConverter.java │ ├── StringToIntegerConverter.java │ ├── ObjectToStringConverter.java │ ├── MapToPropertiesConverter.java │ ├── NumberToByteConverter.java │ ├── NumberToLongConverter.java │ ├── StringToBooleanConverter.java │ ├── NumberToCharacterConverter.java │ ├── NumberToFloatConverter.java │ ├── NumberToShortConverter.java │ ├── StringToDurationConverter.java │ ├── NumberToDoubleConverter.java │ ├── ObjectToOptionalConverter.java │ ├── NumberToIntegerConverter.java │ ├── ObjectToByteArrayConverter.java │ └── PropertiesToStringConverter.java │ ├── util │ ├── BaseUtils.java │ ├── NumberUtils.java │ └── Utils.java │ ├── annotation │ ├── Nonnull.java │ ├── Immutable.java │ └── Nullable.java │ ├── net │ └── console │ │ └── Handler.java │ ├── io │ └── filter │ │ └── TrueFileFilter.java │ ├── classloading │ ├── ClassicURLClassPathHandle.java │ ├── NoOpURLClassPathHandle.java │ └── ModernURLClassPathHandle.java │ └── event │ └── ParallelEventDispatcher.java ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── microsphere-annotation-processor └── src │ ├── main │ └── resources │ │ └── META-INF │ │ └── services │ │ └── javax.annotation.processing.Processor │ └── test │ ├── resources │ ├── META-INF │ │ └── services │ │ │ └── io.microsphere.metadata.ConfigurationPropertyLoader │ └── logback-test.xml │ └── java │ └── io │ └── microsphere │ └── annotation │ └── processor │ ├── model │ ├── StringArrayList.java │ ├── Ancestor.java │ ├── Color.java │ ├── ArrayTypeModel.java │ ├── CollectionTypeModel.java │ └── Parent.java │ └── GenericTestService.java ├── .github ├── dependabot.yml └── workflows │ └── maven-build.yml ├── .gitignore └── microsphere-java-dependencies └── pom.xml /microsphere-java-core/src/test/resources/test.txt: -------------------------------------------------------------------------------- 1 | test -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/.sar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/temp.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/test.properties: -------------------------------------------------------------------------------- 1 | name = 测试名称 -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/test_zh_CN.properties: -------------------------------------------------------------------------------- 1 | name = 测试名称 -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/junit-platform.properties: -------------------------------------------------------------------------------- 1 | junit.jupiter.extensions.autodetection.enabled = true -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsphere-projects/microsphere-java/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/logging.properties: -------------------------------------------------------------------------------- 1 | handlers = java.util.logging.ConsoleHandler 2 | 3 | .level = ALL -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/banned-artifacts: -------------------------------------------------------------------------------- 1 | org.openjdk.jmh:jmh-core:* 2 | org.openjdk.jmh:jmh-generator-annprocess:* -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/services/java.net.URLStreamHandlerFactory: -------------------------------------------------------------------------------- 1 | io.microsphere.net.StandardURLStreamHandlerFactory -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-Name: FindBugs-jsr305 3 | Bundle-Version: 3.0.2 4 | 5 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.io.Serializer: -------------------------------------------------------------------------------- 1 | io.microsphere.io.DefaultSerializer 2 | io.microsphere.io.StringSerializer -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.io.Deserializer: -------------------------------------------------------------------------------- 1 | io.microsphere.io.DefaultDeserializer 2 | io.microsphere.io.StringDeserializer -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.metadata.ConfigurationPropertyReader: -------------------------------------------------------------------------------- 1 | io.microsphere.metadata.DefaultConfigurationPropertyReader -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension: -------------------------------------------------------------------------------- 1 | io.microsphere.junit.jupiter.api.extension.UtilsTestBeforeAllExtension -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.metadata.ConfigurationPropertyGenerator: -------------------------------------------------------------------------------- 1 | io.microsphere.metadata.DefaultConfigurationPropertyGenerator -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/services/io.microsphere.event.EventListener: -------------------------------------------------------------------------------- 1 | io.microsphere.event.EchoEventListener 2 | io.microsphere.event.EchoEventListener2 -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/test/json/clean.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | * comment 1 5 | */ 6 | 7 | # comment 2 8 | 9 | // comment 3 10 | 11 | a -------------------------------------------------------------------------------- /microsphere-annotation-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | io.microsphere.annotation.processor.ConfigurationPropertyAnnotationProcessor -------------------------------------------------------------------------------- /microsphere-annotation-processor/src/test/resources/META-INF/services/io.microsphere.metadata.ConfigurationPropertyLoader: -------------------------------------------------------------------------------- 1 | io.microsphere.annotation.processor.TestConfigurationPropertyLoader -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.event.EventDispatcher: -------------------------------------------------------------------------------- 1 | io.microsphere.event.DirectEventDispatcher 2 | io.microsphere.event.ParallelEventDispatcher -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.metadata.ConfigurationPropertyLoader: -------------------------------------------------------------------------------- 1 | io.microsphere.metadata.AdditionalMetadataResourceConfigurationPropertyLoader -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.net.ExtendableProtocolURLStreamHandler: -------------------------------------------------------------------------------- 1 | io.microsphere.net.classpath.Handler 2 | io.microsphere.net.console.Handler -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/maven/io/github/microsphere-projects/microsphere-java-core/pom.properties: -------------------------------------------------------------------------------- 1 | groupId=com.google.code.findbugs 2 | artifactId=jsr305 3 | version=3.0.2 4 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.process.ProcessIdResolver: -------------------------------------------------------------------------------- 1 | io.microsphere.process.ModernProcessIdResolver 2 | io.microsphere.process.VirtualMachineProcessIdResolver 3 | io.microsphere.process.ClassicProcessIdResolver -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/test/json/array.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Mercy", 4 | "age": 18 5 | }, 6 | { 7 | "name": "mercyblitz", 8 | "age": 19 9 | }, 10 | { 11 | "name": "mz", 12 | "age": 20 13 | } 14 | ] -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.classloading.URLClassPathHandle: -------------------------------------------------------------------------------- 1 | io.microsphere.classloading.ClassicURLClassPathHandle 2 | io.microsphere.classloading.ModernURLClassPathHandle 3 | io.microsphere.classloading.NoOpURLClassPathHandle -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.logging.LoggerFactory: -------------------------------------------------------------------------------- 1 | io.microsphere.logging.Sfl4jLoggerFactory 2 | io.microsphere.logging.ACLLoggerFactory 3 | io.microsphere.logging.JDKLoggerFactory 4 | io.microsphere.logging.NoOpLoggerFactory -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.classloading.ArtifactResourceResolver: -------------------------------------------------------------------------------- 1 | io.microsphere.classloading.MavenArtifactResourceResolver 2 | io.microsphere.classloading.ManifestArtifactResourceResolver 3 | io.microsphere.classloading.ArchiveFileArtifactResourceResolver -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/test/json/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Mercy", 3 | "age": 18, 4 | "male": true, 5 | "height": 1.7, 6 | "weight": 60.0, 7 | "birthday": 1000000, 8 | "object": { 9 | "name": null, 10 | "grade": false 11 | }, 12 | "names": [ 13 | "\"", 14 | "aa" 15 | ] 16 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/services/io.microsphere.metadata.ConfigurationPropertyLoader: -------------------------------------------------------------------------------- 1 | io.microsphere.metadata.DefaultConfigurationPropertyLoader 2 | io.microsphere.metadata.EmptyConfigurationPropertyLoader 3 | io.microsphere.metadata.NullConfigurationPropertyLoader 4 | io.microsphere.metadata.ErrorConfigurationPropertyLoader -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/performance/PerformanceAction.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.performance; 2 | 3 | /** 4 | * {@link PerformanceAction} 5 | * 6 | * @author Mercy 7 | * @see PerformanceAction 8 | * @since 1.0.0 9 | */ 10 | public interface PerformanceAction { 11 | 12 | T execute(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/reflect/AbstractJavaTypeKindTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.reflect; 2 | 3 | public abstract class AbstractJavaTypeKindTest { 4 | 5 | abstract void testGetSuperType(); 6 | 7 | abstract void testGetRawType(); 8 | 9 | abstract void testGetInterfaces(); 10 | 11 | abstract void testGetGenericTypes(); 12 | } 13 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/logging/NoOpLoggerTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.logging; 2 | 3 | /** 4 | * {@link NoOpLogger} Test 5 | * 6 | * @author Mercy 7 | * @see AbstractLogger 8 | * @since 1.0.0 9 | */ 10 | class NoOpLoggerTest extends AbstractLoggerTest { 11 | 12 | @Override 13 | protected Logger createLogger() { 14 | return new NoOpLogger("No-OP"); 15 | } 16 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/constants/Constants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package io.microsphere.constants; 5 | 6 | /** 7 | * {@link Constants} 8 | * 9 | * @author Mercy 10 | * @see Constants 11 | * @since 1.0.0 12 | */ 13 | public interface Constants extends FileConstants, PathConstants, PropertyConstants, 14 | ProtocolConstants, SeparatorConstants, SymbolConstants { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ${ENCODER_PATTERN} 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /microsphere-annotation-processor/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ${ENCODER_PATTERN} 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/logging/ACLLoggerFactoryTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.logging; 2 | 3 | /** 4 | * {@link ACLLoggerFactory} Test 5 | * 6 | * @author Mercy 7 | * @see ACLLoggerFactory 8 | * @since 1.0.0 9 | */ 10 | class ACLLoggerFactoryTest extends AbstractLoggerTest { 11 | 12 | @Override 13 | protected Logger createLogger() { 14 | return new ACLLoggerFactory().createLogger(ACLLoggerFactory.class.getName()); 15 | } 16 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/logging/Sfl4jLoggerFactoryTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.logging; 2 | 3 | /** 4 | * {@link Sfl4jLoggerFactory} Test 5 | * 6 | * @author Mercy 7 | * @see Sfl4jLoggerFactory 8 | * @since 1.0.0 9 | */ 10 | class Sfl4jLoggerFactoryTest extends AbstractLoggerTest { 11 | 12 | @Override 13 | protected Logger createLogger() { 14 | return new Sfl4jLoggerFactory().createLogger(Sfl4jLoggerFactoryTest.class.getName()); 15 | } 16 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "maven" # See documentation for possible values 9 | directory: "/" 10 | schedule: 11 | interval: "daily" 12 | open-pull-requests-limit: 10 -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/util/BaseUtilsTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertThrows; 6 | 7 | /** 8 | * {@link BaseUtils} Test 9 | * 10 | * @author Mercy 11 | * @see BaseUtils 12 | * @since 1.0.0 13 | */ 14 | class BaseUtilsTest { 15 | 16 | @Test 17 | void testConstructor() { 18 | assertThrows(IllegalStateException.class, () -> new BaseUtils() { 19 | }); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/filter/TrueClassFilterTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.filter; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertTrue; 6 | 7 | /** 8 | * {@link TrueClassFilter} Test 9 | * 10 | * @author Mercy 11 | * @see TrueClassFilter 12 | * @since 1.0.0 13 | */ 14 | class TrueClassFilterTest { 15 | 16 | @Test 17 | void testAccept() { 18 | assertTrue(TrueClassFilter.INSTANCE.accept(null)); 19 | assertTrue(TrueClassFilter.INSTANCE.accept(getClass())); 20 | } 21 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/nio/charset/CharsetUtilsTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.nio.charset; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static io.microsphere.nio.charset.CharsetUtils.DEFAULT_CHARSET; 6 | import static org.junit.jupiter.api.Assertions.assertNotNull; 7 | 8 | /** 9 | * {@link CharsetUtils} Test 10 | * 11 | * @author Mercy 12 | * @see CharsetUtils 13 | * @since 1.0.0 14 | */ 15 | class CharsetUtilsTest { 16 | 17 | @Test 18 | void testConstants() { 19 | assertNotNull(DEFAULT_CHARSET); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/collection/EmptyIterableTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.collection; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static io.microsphere.collection.EmptyIterable.INSTANCE; 6 | import static org.junit.jupiter.api.Assertions.assertSame; 7 | 8 | /** 9 | * {@link EmptyIterable} Test 10 | * 11 | * @author Mercy 12 | * @see EmptyIterable 13 | * @since 1.0.0 14 | */ 15 | class EmptyIterableTest { 16 | 17 | @Test 18 | void testIterator() { 19 | assertSame(EmptyIterator.INSTANCE, INSTANCE.iterator()); 20 | } 21 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/event/AbstractEventDispatcherTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.event; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertThrows; 6 | 7 | /** 8 | * {@link AbstractEventDispatcher} Test 9 | * 10 | * @author Mercy 11 | * @see AbstractEventDispatcher 12 | * @since 1.0.0 13 | */ 14 | class AbstractEventDispatcherTest { 15 | 16 | @Test 17 | void testConstructorOnFailed() { 18 | assertThrows(NullPointerException.class, () -> new AbstractEventDispatcher(null) { 19 | }); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/io/filter/TrueFileFilterTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.io.filter; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static io.microsphere.io.filter.TrueFileFilter.INSTANCE; 6 | import static org.junit.jupiter.api.Assertions.assertTrue; 7 | 8 | /** 9 | * {@link TrueFileFilter} Test 10 | * 11 | * @author Mercy 12 | * @see TrueFileFilter 13 | * @since 1.0.0 14 | */ 15 | class TrueFileFilterTest { 16 | 17 | @Test 18 | void test() { 19 | assertTrue(INSTANCE.accept(null)); 20 | assertTrue(INSTANCE.accept(null, null)); 21 | } 22 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/classloading/ErrorArtifactResourceResolverTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.classloading; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertNull; 4 | 5 | /** 6 | * {@link ErrorArtifactResourceResolver} Test 7 | * 8 | * @author Mercy 9 | * @see ErrorArtifactResourceResolver 10 | * @since 1.0.0 11 | */ 12 | class ErrorArtifactResourceResolverTest extends StreamArtifactResourceResolverTest { 13 | 14 | @Override 15 | void assertArtifact(Artifact artifact) throws Throwable { 16 | assertNull(artifact); 17 | } 18 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/io/DefaultDeserializerTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.io; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.io.IOException; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertNull; 8 | 9 | /** 10 | * {@link DefaultDeserializer} Test 11 | * 12 | * @author Mercy 13 | * @see DefaultDeserializer 14 | * @since 1.0.0 15 | */ 16 | class DefaultDeserializerTest { 17 | 18 | private DefaultDeserializer deserializer = DefaultDeserializer.INSTANCE; 19 | 20 | @Test 21 | void testDeserializeOnNull() throws IOException { 22 | assertNull(deserializer.deserialize(null)); 23 | } 24 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/classloading/ManifestArtifactResourceResolverTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.classloading; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | 5 | /** 6 | * {@link ManifestArtifactResourceResolver} Test 7 | * 8 | * @author Mercy 9 | * @see ManifestArtifactResourceResolver 10 | * @since 1.0.0 11 | */ 12 | class ManifestArtifactResourceResolverTest extends StreamArtifactResourceResolverTest { 13 | 14 | @Override 15 | void assertArtifact(Artifact artifact) { 16 | assertEquals("FindBugs-jsr305", artifact.getArtifactId()); 17 | assertEquals(TEST_VERSION, artifact.getVersion()); 18 | } 19 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsPerformanceTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.util; 2 | 3 | import io.microsphere.performance.AbstractPerformanceTest; 4 | import org.junit.jupiter.api.Disabled; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static io.microsphere.util.ClassLoaderUtils.findLoadedClassesInClassPath; 8 | 9 | /** 10 | * {@link ClassLoaderUtils} Performance Test 11 | * 12 | * @author Mercy 13 | * @see ClassLoaderUtilsPerformanceTest 14 | * @since 1.0.0 15 | */ 16 | @Disabled 17 | class ClassLoaderUtilsPerformanceTest extends AbstractPerformanceTest { 18 | 19 | @Test 20 | void testFind() { 21 | super.execute(() -> findLoadedClassesInClassPath(TEST_CLASS_LOADER)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/performance/AbstractPerformanceTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.performance; 2 | 3 | import io.microsphere.AbstractTestCase; 4 | import org.junit.jupiter.api.Disabled; 5 | 6 | /** 7 | * {@link AbstractPerformanceTest} 8 | * 9 | * @author Mercy 10 | * @see AbstractPerformanceTest 11 | * @since 1.0.0 12 | */ 13 | @Disabled 14 | public abstract class AbstractPerformanceTest extends AbstractTestCase { 15 | 16 | protected void execute(PerformanceAction action) { 17 | long startTime = System.nanoTime(); 18 | T returnValue = action.execute(); 19 | long costTime = System.nanoTime() - startTime; 20 | log("action returns {}, it costs {} ns", action, returnValue, costTime); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/resources/META-INF/services/io.microsphere.convert.multiple.MultiValueConverter: -------------------------------------------------------------------------------- 1 | # io.microsphere.convert.multiple.MultiValueConverter 2 | io.microsphere.convert.multiple.StringToArrayConverter 3 | io.microsphere.convert.multiple.StringToBlockingDequeConverter 4 | io.microsphere.convert.multiple.StringToBlockingQueueConverter 5 | io.microsphere.convert.multiple.StringToCollectionConverter 6 | io.microsphere.convert.multiple.StringToDequeConverter 7 | io.microsphere.convert.multiple.StringToListConverter 8 | io.microsphere.convert.multiple.StringToNavigableSetConverter 9 | io.microsphere.convert.multiple.StringToQueueConverter 10 | io.microsphere.convert.multiple.StringToSetConverter 11 | io.microsphere.convert.multiple.StringToSortedSetConverter 12 | io.microsphere.convert.multiple.StringToTransferQueueConverter 13 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/filter/PackageNameClassFilterTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.filter; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertFalse; 6 | import static org.junit.jupiter.api.Assertions.assertTrue; 7 | 8 | /** 9 | * {@link PackageNameClassFilter} Test 10 | * 11 | * @author Mercy 12 | * @see PackageNameClassFilter 13 | * @since 1.0.0 14 | */ 15 | class PackageNameClassFilterTest { 16 | 17 | @Test 18 | void testAccept() { 19 | PackageNameClassFilter filter = new PackageNameClassFilter("io.microsphere", true); 20 | assertTrue(filter.accept(PackageNameClassFilterTest.class)); 21 | assertFalse(filter.accept(String.class)); 22 | assertFalse(filter.accept(null)); 23 | } 24 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/constants/PathConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package io.microsphere.constants; 5 | 6 | /** 7 | * Path Constants Definition 8 | * 9 | * @author Mercy 10 | * @see PathConstants 11 | * @since 1.0.0 12 | */ 13 | public interface PathConstants { 14 | 15 | /** 16 | * Slash char 17 | */ 18 | char SLASH_CHAR = '/'; 19 | 20 | /** 21 | * Back Slash char 22 | */ 23 | char BACK_SLASH_CHAR = '\\'; 24 | 25 | /** 26 | * Slash : "/" 27 | */ 28 | String SLASH = "/"; 29 | 30 | /** 31 | * Double Slash : "//" 32 | */ 33 | String DOUBLE_SLASH = SLASH + SLASH; 34 | 35 | /** 36 | * Back Slash : "\" 37 | */ 38 | String BACK_SLASH = "\\"; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/io/filter/IOFileFilterTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.io.filter; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.io.File; 6 | import java.util.Objects; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertFalse; 9 | import static org.junit.jupiter.api.Assertions.assertTrue; 10 | 11 | /** 12 | * {@link IOFileFilter} Test 13 | * 14 | * @author Mercy 15 | * @see IOFileFilter 16 | * @since 1.0.0 17 | */ 18 | class IOFileFilterTest { 19 | 20 | @Test 21 | void tes() { 22 | File file = new File("test"); 23 | IOFileFilter filter = f -> Objects.equals(f, file); 24 | assertTrue(filter.accept(file)); 25 | assertFalse(filter.accept(null)); 26 | assertTrue(filter.accept(file.getParentFile(), file.getName())); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/filter/PackageNameClassNameFilterTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.filter; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertFalse; 6 | import static org.junit.jupiter.api.Assertions.assertTrue; 7 | 8 | /** 9 | * {@link PackageNameClassNameFilter} Test 10 | * 11 | * @author Mercy 12 | * @see PackageNameClassNameFilter 13 | * @since 1.0.0 14 | */ 15 | class PackageNameClassNameFilterTest { 16 | 17 | @Test 18 | void testAccept() { 19 | PackageNameClassNameFilter filter = new PackageNameClassNameFilter("io.microsphere", true); 20 | assertTrue(filter.accept("io.microsphere.filter.PackageNameClassNameFilterTest")); 21 | assertFalse(filter.accept("java.lang.String")); 22 | assertFalse(filter.accept(null)); 23 | } 24 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/util/ShutdownHookCallbacksThreadTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static io.microsphere.util.ShutdownHookCallbacksThread.INSTANCE; 6 | import static io.microsphere.util.ShutdownHookUtils.addShutdownHookCallback; 7 | 8 | /** 9 | * {@link ShutdownHookCallbacksThread} Test 10 | * 11 | * @author Mercy 12 | * @see ShutdownHookCallbacksThread 13 | * @since 1.0.0 14 | */ 15 | class ShutdownHookCallbacksThreadTest { 16 | 17 | @Test 18 | void testRun() { 19 | ShutdownHookCallbacksThread thread = INSTANCE; 20 | 21 | int times = 3; 22 | for (int i = 0; i < times; i++) { 23 | addShutdownHookCallback(new ShutdownHookUtilsTest.ShutdownHookCallback(i)); 24 | } 25 | 26 | thread.run(); 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Copyright 2013-2023 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.0/apache-maven-3.9.0-bin.zip 16 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/filter/ClassFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package io.microsphere.filter; 5 | 6 | /** 7 | * A {@link Filter} for {@link Class} objects. 8 | * 9 | *

Implementations of this interface can be used to filter classes based on specific criteria, 10 | * such as whether they are interfaces, annotations, or belong to a particular package.

11 | * 12 | *

Example Usage

13 | *
{@code
14 |  * public class MyTestClassFilter implements ClassFilter {
15 |  *     public boolean accept(Class clazz) {
16 |  *         return clazz.isAnnotation();
17 |  *     }
18 |  * }
19 |  * }
20 | * 21 | *

This example filters only annotation types.

22 | * 23 | * @author
Mercy 24 | * @see Class 25 | * @see Filter 26 | * @since 1.0.0 27 | */ 28 | @FunctionalInterface 29 | public interface ClassFilter extends Filter> { 30 | } 31 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/convert/StringToDurationConverterTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.convert; 2 | 3 | import java.time.Duration; 4 | 5 | import static io.microsphere.convert.StringToDurationConverter.INSTANCE; 6 | import static java.util.concurrent.TimeUnit.MILLISECONDS; 7 | 8 | /** 9 | * {@link StringToDurationConverter} Test 10 | * 11 | * @author Mercy 12 | * @see StringToDurationConverter 13 | * @since 1.0.0 14 | */ 15 | class StringToDurationConverterTest extends BaseConverterTest { 16 | 17 | @Override 18 | protected AbstractConverter createConverter() { 19 | return INSTANCE; 20 | } 21 | 22 | @Override 23 | protected String getSource() throws Throwable { 24 | return "PT12.345S"; 25 | } 26 | 27 | @Override 28 | protected Duration getTarget() throws Throwable { 29 | return Duration.ofSeconds(12, MILLISECONDS.toNanos(345)); 30 | } 31 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/event/ListenableTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.event; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static io.microsphere.event.Listenable.assertListener; 6 | import static org.junit.jupiter.api.Assertions.assertThrows; 7 | 8 | /** 9 | * {@link Listenable} Test 10 | * 11 | * @author Mercy 12 | * @see Listenable 13 | * @since 1.0.0 14 | */ 15 | class ListenableTest { 16 | 17 | @Test 18 | void testAssertListenerNoNull() { 19 | assertThrows(IllegalArgumentException.class, () -> assertListener(null)); 20 | } 21 | 22 | @Test 23 | void testAssertListenerOnInterface() { 24 | assertThrows(IllegalArgumentException.class, () -> assertListener(new FinalEventListener())); 25 | } 26 | 27 | 28 | static final class FinalEventListener implements EventListener { 29 | 30 | @Override 31 | public void onEvent(Event event) { 32 | 33 | } 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/filter/JarEntryFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package io.microsphere.filter; 5 | 6 | import java.util.jar.JarEntry; 7 | 8 | /** 9 | * A filter for {@link JarEntry} objects. Implementations of this interface can be used to 10 | * selectively process or ignore entries within a JAR file. 11 | * 12 | *

Example Usage

13 | *

A simple implementation might accept only entries whose names end with a ".class" 14 | * extension: 15 | * 16 | *

{@code
17 |  * JarEntryFilter classFileFilter = entry -> entry.getName().endsWith(".class");
18 |  * }
19 | * 20 | *

This interface is designed to be used in conjunction with the methods of the 21 | * {@link java.util.jar.JarFile} class and other utilities that process JAR entries. 22 | * 23 | * @author Mercy 24 | * @see JarEntry 25 | * @see Filter 26 | * @since 1.0.0 27 | */ 28 | @FunctionalInterface 29 | public interface JarEntryFilter extends Filter { 30 | } 31 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/classloading/MavenArtifactResourceResolverTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.classloading; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | import static org.junit.jupiter.api.Assertions.assertTrue; 5 | 6 | /** 7 | * {@link MavenArtifactResourceResolver} Test 8 | * 9 | * @author Mercy 10 | * @see MavenArtifactResourceResolver 11 | * @since 1.0.0 12 | */ 13 | class MavenArtifactResourceResolverTest extends StreamArtifactResourceResolverTest { 14 | 15 | @Override 16 | void assertArtifact(Artifact artifact) throws Throwable { 17 | assertTrue(artifact instanceof MavenArtifact); 18 | MavenArtifact mavenArtifact = (MavenArtifact) artifact; 19 | 20 | assertEquals(TEST_GROUP_ID, mavenArtifact.getGroupId()); 21 | assertEquals(TEST_ARTIFACT_ID, mavenArtifact.getArtifactId()); 22 | assertEquals(TEST_VERSION, mavenArtifact.getVersion()); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/logging/JDKLoggerFactoryTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.logging; 2 | 3 | import org.junit.jupiter.api.BeforeAll; 4 | 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.net.URL; 8 | import java.util.logging.LogManager; 9 | 10 | /** 11 | * {@link JDKLoggerFactory} 12 | * 13 | * @author Mercy 14 | * @see JDKLoggerFactory 15 | * @since 1.0.0 16 | */ 17 | class JDKLoggerFactoryTest extends AbstractLoggerTest { 18 | 19 | @BeforeAll 20 | static void beforeAll() throws IOException { 21 | URL resource = LoggerFactoryTest.class.getResource("/META-INF/logging.properties"); 22 | try (InputStream inputStream = resource.openStream()) { 23 | LogManager.getLogManager().readConfiguration(inputStream); 24 | } 25 | } 26 | 27 | @Override 28 | protected Logger createLogger() { 29 | return new JDKLoggerFactory().createLogger(JDKLoggerFactoryTest.class.getName()); 30 | } 31 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | # maven ignore 26 | target/ 27 | !.mvn/wrapper/* 28 | dependency-reduced-pom.xml 29 | 30 | # eclipse ignore 31 | .settings/ 32 | .project 33 | .classpath 34 | 35 | # idea ignore 36 | .idea/ 37 | .idea 38 | *.ipr 39 | *.iml 40 | *.iws 41 | 42 | # temp ignore 43 | *.log 44 | *.cache 45 | *.diff 46 | *.patch 47 | *.tmp 48 | 49 | # system ignore 50 | .DS_Store 51 | Thumbs.db 52 | *.orig 53 | 54 | # flatten ignore 55 | .flattened-pom.xml 56 | 57 | # license check result 58 | license-list 59 | 60 | # grpc compiler 61 | compiler/gradle.properties 62 | compiler/build/* 63 | compiler/.gradle/* 64 | 65 | # Tomcat 66 | .extract 67 | .java-version 68 | 69 | # others 70 | build.txt -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/D.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | /** 20 | * @author Mercy 21 | * @since 1.0.0 22 | */ 23 | public class D extends C { 24 | } 25 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/json/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Fork the source code from org.json 20 | * 21 | * @author Mercy 22 | * @since 1.0.0 23 | */ 24 | package io.microsphere.json; -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/io/FileWatchServiceTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.io; 2 | 3 | import io.microsphere.AbstractTestCase; 4 | import io.microsphere.io.event.FileChangedEvent; 5 | import io.microsphere.io.event.LoggingFileChangedListener; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.io.File; 9 | 10 | import static io.microsphere.collection.Lists.ofList; 11 | 12 | /** 13 | * {@link FileWatchService} Test 14 | * 15 | * @author Mercy 16 | * @see FileWatchService 17 | * @since 1.0.0 18 | */ 19 | class FileWatchServiceTest extends AbstractTestCase { 20 | 21 | private FileWatchService service = (file, listener, kinds) -> { 22 | log("Watching : {} , listener : {} , kinds : {}", file, listener, kinds); 23 | }; 24 | 25 | @Test 26 | void testWatch() { 27 | File file = newRandomTempFile(); 28 | service.watch(file, new LoggingFileChangedListener(), FileChangedEvent.Kind.values()); 29 | service.watch(file, ofList(new LoggingFileChangedListener()), FileChangedEvent.Kind.values()); 30 | } 31 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/collection/EmptyIteratorTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.collection; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.NoSuchElementException; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertFalse; 9 | import static org.junit.jupiter.api.Assertions.assertThrows; 10 | 11 | /** 12 | * {@link EmptyIterator} Tes 13 | * 14 | * @author Mercy 15 | * @see EmptyIterator 16 | * @since 1.0.0 17 | */ 18 | class EmptyIteratorTest { 19 | 20 | private EmptyIterator emptyIterator; 21 | 22 | @BeforeEach 23 | void setUp() { 24 | emptyIterator = new EmptyIterator(); 25 | } 26 | 27 | @Test 28 | void testHasNext() { 29 | assertFalse(emptyIterator.hasNext()); 30 | } 31 | 32 | @Test 33 | void testNext() { 34 | assertThrows(NoSuchElementException.class, emptyIterator::next); 35 | } 36 | 37 | @Test 38 | void testRemove() { 39 | assertThrows(IllegalStateException.class, emptyIterator::remove); 40 | } 41 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/StringBF2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | /** 20 | * @author Mercy 21 | * @since 1.0.0 22 | */ 23 | public interface StringBF2 extends BF3 { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/process/ClassicProcessIdResolverTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.process; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | import static org.junit.jupiter.api.Assertions.assertNotNull; 8 | import static org.junit.jupiter.api.Assertions.assertTrue; 9 | 10 | /** 11 | * {@link ClassicProcessIdResolver} Test 12 | * 13 | * @author Mercy 14 | * @see ClassicProcessIdResolver 15 | * @since 1.0.0 16 | */ 17 | class ClassicProcessIdResolverTest { 18 | 19 | private ClassicProcessIdResolver resolver; 20 | 21 | @BeforeEach 22 | void setUp() { 23 | resolver = new ClassicProcessIdResolver(); 24 | } 25 | 26 | @Test 27 | void testSupports() { 28 | assertTrue(resolver.supports()); 29 | } 30 | 31 | @Test 32 | void testCurrent() { 33 | assertNotNull(resolver.current()); 34 | } 35 | 36 | @Test 37 | void testGetPriority() { 38 | assertEquals(9, resolver.getPriority()); 39 | } 40 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/StringIntegerF1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | /** 20 | * @author Mercy 21 | * @since 1.0.0 22 | */ 23 | public interface StringIntegerF1 extends StringBF2 { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/E.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | import java.io.Serializable; 20 | 21 | /** 22 | * @author Mercy 23 | * @since 1.0.0 24 | */ 25 | public class E extends C implements Serializable { 26 | } 27 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/StringToIntegerF1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | /** 20 | * @author Mercy 21 | * @since 1.0.0 22 | */ 23 | public interface StringToIntegerF1 extends StringBF2 { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/C.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | import java.util.RandomAccess; 20 | 21 | /** 22 | * @author Mercy 23 | * @since 1.0.0 24 | */ 25 | public class C extends B implements RandomAccess { 26 | } 27 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/event/EchoEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.event; 18 | 19 | /** 20 | * Echo {@link Event} 21 | * 22 | * @since 1.0.0 23 | */ 24 | class EchoEvent extends Event { 25 | 26 | public EchoEvent(Object source) { 27 | super(source); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/StringIntegerToBoolean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | /** 20 | * @author Mercy 21 | * @since 1.0.0 22 | */ 23 | public interface StringIntegerToBoolean extends StringIntegerF1 { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/StringBooleanToInteger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | /** 20 | * @author Mercy 21 | * @since 1.0.0 22 | */ 23 | public interface StringBooleanToInteger extends StringToIntegerF1 { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/A.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | import java.io.Serializable; 20 | 21 | /** 22 | * A for testing 23 | * 24 | * @author Mercy 25 | * @since 1.0.0 26 | */ 27 | public class A implements Serializable { 28 | } 29 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/BF3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | import java.util.function.BiFunction; 20 | 21 | /** 22 | * @author Mercy 23 | * @since 1.0.0 24 | */ 25 | public interface BF3 extends BiFunction { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/StringIntegerBooleanHashMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | /** 20 | * @author Mercy 21 | * @since 1.0.0 22 | */ 23 | public class StringIntegerBooleanHashMap extends MyHashMap { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/constants/SeparatorConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package io.microsphere.constants; 5 | 6 | 7 | import java.io.File; 8 | 9 | import static io.microsphere.constants.PathConstants.SLASH; 10 | import static io.microsphere.constants.SymbolConstants.EXCLAMATION; 11 | import static java.io.File.pathSeparator; 12 | import static java.io.File.separator; 13 | import static java.lang.System.lineSeparator; 14 | 15 | /** 16 | * Separator Constants 17 | *

18 | * 19 | * @author Mercy 20 | * @since 1.0.0 21 | */ 22 | public interface SeparatorConstants { 23 | 24 | /** 25 | * Archive Entry Separator : "!/" 26 | */ 27 | String ARCHIVE_ENTRY_SEPARATOR = EXCLAMATION + SLASH; 28 | 29 | /** 30 | * File Separator : {@link File#separator} 31 | */ 32 | String FILE_SEPARATOR = separator; 33 | 34 | /** 35 | * Path Separator : {@link File#pathSeparator} 36 | */ 37 | String PATH_SEPARATOR = pathSeparator; 38 | 39 | /** 40 | * Line Separator : {@link System#lineSeparator()} 41 | */ 42 | String LINE_SEPARATOR = lineSeparator(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/process/VirtualMachineProcessIdResolverTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.process; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | import static org.junit.jupiter.api.Assertions.assertNotNull; 8 | import static org.junit.jupiter.api.Assertions.assertTrue; 9 | 10 | /** 11 | * {@link VirtualMachineProcessIdResolver} Test 12 | * 13 | * @author Mercy 14 | * @see VirtualMachineProcessIdResolver 15 | * @since 1.0.0 16 | */ 17 | class VirtualMachineProcessIdResolverTest { 18 | 19 | private VirtualMachineProcessIdResolver resolver; 20 | 21 | @BeforeEach 22 | void setUp() { 23 | this.resolver = new VirtualMachineProcessIdResolver(); 24 | } 25 | 26 | @Test 27 | void testSupports() { 28 | assertTrue(resolver.supports()); 29 | } 30 | 31 | @Test 32 | void testCurrent() { 33 | assertNotNull(resolver.current()); 34 | } 35 | 36 | @Test 37 | void testGetPriority() { 38 | assertEquals(5, resolver.getPriority()); 39 | } 40 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/StringIntegerHashMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | import java.util.HashMap; 20 | 21 | /** 22 | * @author Mercy 23 | * @since 1.0.0 24 | */ 25 | public class StringIntegerHashMap extends HashMap { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/StringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | /** 20 | * A class to covert {@link String} to the target-typed value 21 | * 22 | * @see Converter 23 | * @since 1.0.0 24 | */ 25 | @FunctionalInterface 26 | public interface StringConverter extends Converter { 27 | } 28 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/B.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | /** 20 | * B 21 | * 22 | * @author Mercy 23 | * @since 1.0.0 24 | */ 25 | public class B extends A implements Comparable { 26 | @Override 27 | public int compareTo(B o) { 28 | return 0; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/io/event/DefaultFileChangedListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.io.event; 18 | 19 | /** 20 | * Default {@link FileChangedListener} 21 | * 22 | * @author Mercy 23 | * @see FileChangedListener 24 | * @since 1.0.0 25 | */ 26 | public class DefaultFileChangedListener implements FileChangedListener { 27 | } 28 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/filter/TrueClassFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package io.microsphere.filter; 5 | 6 | /** 7 | * A {@link ClassFilter} implementation that always returns {@code true}. 8 | *

9 | * This class is a singleton and provides a consistent filtering behavior 10 | * across the application lifecycle. It is typically used when all classes 11 | * need to be accepted without any filtering logic. 12 | *

13 | * 14 | *

Example Usage

15 | *
{@code
16 |  * // Get the singleton instance
17 |  * ClassFilter filter = TrueClassFilter.INSTANCE;
18 |  *
19 |  * // Test against any Class object
20 |  * boolean result = filter.accept(String.class); // returns true
21 |  * }
22 | * 23 | * @author Mercy 24 | * @see ClassFilter 25 | * @since 1.0.0 26 | */ 27 | public class TrueClassFilter implements ClassFilter { 28 | 29 | /** 30 | * Singleton {@link TrueClassFilter} instance 31 | */ 32 | public static final TrueClassFilter INSTANCE = new TrueClassFilter(); 33 | 34 | private TrueClassFilter() { 35 | 36 | } 37 | 38 | @Override 39 | public boolean accept(Class filteredObject) { 40 | return true; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/MyHashMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | import java.io.Serializable; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | /** 24 | * @author Mercy 25 | * @since 1.0.0 26 | */ 27 | public class MyHashMap extends HashMap implements Map { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/model/StringArrayList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.microsphere.annotation.processor.model; 19 | 20 | import java.util.ArrayList; 21 | 22 | /** 23 | * String type {@link ArrayList} 24 | * 25 | * @author Mercy 26 | * @see ArrayList 27 | * @since 1.0.0 28 | */ 29 | public class StringArrayList extends ArrayList { 30 | } 31 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/util/BaseUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.util; 18 | 19 | /** 20 | * Base Utilities class 21 | * 22 | * @author Mercy 23 | * @since 1.0.0 24 | */ 25 | @Deprecated 26 | public abstract class BaseUtils { 27 | 28 | protected BaseUtils() throws IllegalStateException { 29 | throw new IllegalStateException("Not Supported!"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/management/ManagementUtilsTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.management; 2 | 3 | import io.microsphere.AbstractTestCase; 4 | import io.microsphere.process.ProcessIdResolver; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.util.List; 8 | 9 | import static io.microsphere.management.ManagementUtils.getCurrentProcessId; 10 | import static io.microsphere.process.ProcessIdResolver.UNKNOWN_PROCESS_ID; 11 | import static io.microsphere.util.ServiceLoaderUtils.loadServicesList; 12 | import static org.junit.jupiter.api.Assertions.assertTrue; 13 | 14 | /** 15 | * {@link ManagementUtils} Test 16 | * 17 | * @author Mercy 18 | * @see ManagementUtils 19 | * @since 1.0.0 20 | */ 21 | class ManagementUtilsTest extends AbstractTestCase { 22 | 23 | @Test 24 | void testGetCurrentProcessId() { 25 | long currentProcessId = getCurrentProcessId(); 26 | assertTrue(currentProcessId > 0); 27 | } 28 | 29 | @Test 30 | void testLog() { 31 | List resolvers = loadServicesList(ProcessIdResolver.class); 32 | for (ProcessIdResolver resolver : resolvers) { 33 | ManagementUtils.log(resolver, UNKNOWN_PROCESS_ID); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/model/Ancestor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.annotation.processor.model; 18 | 19 | import java.io.Serializable; 20 | 21 | /** 22 | * Ancestor 23 | */ 24 | public class Ancestor implements Serializable { 25 | 26 | private boolean z; 27 | 28 | public boolean isZ() { 29 | return z; 30 | } 31 | 32 | public void setZ(boolean z) { 33 | this.z = z; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/net/console/ConsoleURLConnectionTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.net.console; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.IOException; 7 | import java.net.URL; 8 | 9 | import static java.net.Proxy.NO_PROXY; 10 | import static org.junit.jupiter.api.Assertions.assertSame; 11 | 12 | /** 13 | * {@link ConsoleURLConnection} Test 14 | * 15 | * @author Mercy 16 | * @see ConsoleURLConnection 17 | * @since 1.0.0 18 | */ 19 | class ConsoleURLConnectionTest { 20 | 21 | private ConsoleURLConnection connection; 22 | 23 | @BeforeEach 24 | void setUp() throws IOException { 25 | Handler handler = new Handler(); 26 | this.connection = (ConsoleURLConnection) handler.openConnection(new URL("console://localhost:12345/abc"), NO_PROXY); 27 | } 28 | 29 | @Test 30 | void testConnect() throws IOException { 31 | connection.connect(); 32 | } 33 | 34 | @Test 35 | void testGetInputStream() throws IOException { 36 | assertSame(System.in, connection.getInputStream()); 37 | } 38 | 39 | @Test 40 | void testGetOutputStream() throws IOException { 41 | assertSame(System.out, connection.getOutputStream()); 42 | } 43 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/util/NumberUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.microsphere.util; 19 | 20 | /** 21 | * The utilities class for {@link Number nummber} 22 | * 23 | * @author Mercy 24 | * @see Number 25 | * @see Integer 26 | * @see Long 27 | * @see Float 28 | * @see Double 29 | * @since 1.0.0 30 | */ 31 | public abstract class NumberUtils implements Utils { 32 | 33 | 34 | private NumberUtils() { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/event/EchoEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.event; 18 | 19 | import java.io.Serializable; 20 | 21 | /** 22 | * {@link EchoEvent} {@link EventListener} 23 | * 24 | * @since 1.0.0 25 | */ 26 | public class EchoEventListener extends AbstractEventListener implements Serializable { 27 | 28 | @Override 29 | public void handleEvent(EchoEvent event) { 30 | println("EchoEventListener : " + event); 31 | } 32 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/io/event/FileChangedEventTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.io.event; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.io.File; 6 | 7 | import static io.microsphere.io.event.FileChangedEvent.Kind.CREATED; 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.api.Assertions.assertSame; 10 | import static org.junit.jupiter.api.Assertions.assertThrows; 11 | 12 | /** 13 | * {@link FileChangedEvent} Test 14 | * 15 | * @author Mercy 16 | * @see FileChangedEvent 17 | * @since 1.0.0 18 | */ 19 | class FileChangedEventTest { 20 | 21 | @Test 22 | void test() { 23 | File file = new File("new"); 24 | FileChangedEvent event = new FileChangedEvent(file, CREATED); 25 | assertSame(file, event.getFile()); 26 | assertSame(file, event.getSource()); 27 | assertEquals(CREATED, event.getKind()); 28 | assertEquals("FileChangedEvent{kind=CREATED, file=new}", event.toString()); 29 | } 30 | 31 | @Test 32 | void testOnFailed() { 33 | assertThrows(IllegalArgumentException.class, () -> new FileChangedEvent(null, CREATED)); 34 | assertThrows(IllegalArgumentException.class, () -> new FileChangedEvent(new File(""), null)); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/microsphere/additional-configuration-properties.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "microsphere.artifact-id.manifest-attribute-names", 4 | "type": "java.lang.String[]", 5 | "defaultValue": "Bundle-Name,Automatic-Module-Name,Implementation-Title", 6 | "required": false, 7 | "description": "The attribute names in the 'META-INF\/MANIFEST' resource are retrieved as the artifact id", 8 | "metadata": { 9 | "sources": [ 10 | "system-properties" 11 | ], 12 | "targets": [], 13 | "declaredClass": "io.microsphere.classloading.ManifestArtifactResourceResolver", 14 | "declaredField": "ARTIFACT_ID_ATTRIBUTE_NAMES_PROPERTY_NAME" 15 | } 16 | }, 17 | { 18 | "name": "microsphere.artifact-version.manifest-attribute-names", 19 | "type": "java.lang.String[]", 20 | "defaultValue": "Bundle-Version,Implementation-Version", 21 | "required": false, 22 | "description": "The attribute names in the 'META-INF\/MANIFEST' resource are retrieved as the artifact version", 23 | "metadata": { 24 | "sources": [ 25 | "system-properties" 26 | ], 27 | "targets": [], 28 | "declaredClass": "io.microsphere.classloading.ManifestArtifactResourceResolver", 29 | "declaredField": "VERSION_ATTRIBUTE_NAMES_PROPERTY_NAME" 30 | } 31 | } 32 | ] -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/test/StringIntegerToBooleanClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.test; 18 | 19 | /** 20 | * {@link StringIntegerToBoolean} Class 21 | * 22 | * @author Mercy 23 | * @see StringIntegerToBoolean 24 | * @since 1.0.0 25 | */ 26 | public class StringIntegerToBooleanClass implements StringIntegerToBoolean { 27 | 28 | @Override 29 | public Boolean apply(String s, Integer integer) { 30 | return true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/annotation/Nonnull.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.microsphere.annotation; 18 | 19 | 20 | import javax.annotation.meta.TypeQualifierNickname; 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.Retention; 23 | 24 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 25 | 26 | /** 27 | * A common Microsphere annotation to declare that annotated elements cannot be {@code null}. 28 | * 29 | * @author Mercy 30 | * @see javax.annotation.Nonnull 31 | * @since 1.0.0 32 | */ 33 | @Documented 34 | @Retention(RUNTIME) 35 | @javax.annotation.Nonnull 36 | @TypeQualifierNickname 37 | public @interface Nonnull { 38 | } 39 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/multiple/StringToSetConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert.multiple; 18 | 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | 22 | /** 23 | * The class to convert {@link String} to {@link Set}-based value 24 | * 25 | * @since 1.0.0 26 | */ 27 | public class StringToSetConverter extends StringToIterableConverter { 28 | 29 | @Override 30 | protected Set createMultiValue(int size, Class multiValueType) { 31 | return new HashSet(size); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/filter/Filter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package io.microsphere.filter; 5 | 6 | /** 7 | * The {@code Filter} interface represents a generic filtering mechanism that can be applied to objects of type {@code T}. 8 | *

9 | * Implementations of this interface define the logic to determine whether a given object should be accepted or filtered out. 10 | * This interface is typically used in scenarios where conditional processing or selection of objects is required. 11 | *

12 | * 13 | *

Example Usage

14 | *
{@code
15 |  * public class EvenNumberFilter implements Filter {
16 |  *     public boolean accept(Integer number) {
17 |  *         return number % 2 == 0;
18 |  *     }
19 |  * }
20 |  *
21 |  * // Usage
22 |  * Filter filter = new EvenNumberFilter();
23 |  * System.out.println(filter.accept(4));  // Output: true
24 |  * System.out.println(filter.accept(5));  // Output: false
25 |  * }
26 | * 27 | * @param the type of object that this filter can evaluate 28 | * @author
Mercy 29 | * @since 1.0.0 30 | */ 31 | @FunctionalInterface 32 | public interface Filter { 33 | 34 | /** 35 | * Does accept filtered object? 36 | * 37 | * @param filteredObject filtered object 38 | * @return 39 | */ 40 | boolean accept(T filteredObject); 41 | } 42 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/multiple/StringToListConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert.multiple; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | * The class to convert {@link String} to {@link List}-based value 24 | * 25 | * @since 1.0.0 26 | */ 27 | public class StringToListConverter extends StringToIterableConverter { 28 | 29 | @Override 30 | protected List createMultiValue(int size, Class multiValueType) { 31 | return new ArrayList(size); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/multiple/StringToDequeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert.multiple; 18 | 19 | import java.util.ArrayDeque; 20 | import java.util.Deque; 21 | 22 | /** 23 | * The class to convert {@link String} to {@link Deque}-based value 24 | * 25 | * @since 1.0.0 26 | */ 27 | public class StringToDequeConverter extends StringToIterableConverter { 28 | 29 | @Override 30 | protected Deque createMultiValue(int size, Class multiValueType) { 31 | return new ArrayDeque(size); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/GenericTestService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.annotation.processor; 18 | 19 | 20 | import java.util.EventListener; 21 | 22 | /** 23 | * {@link TestService} Implementation 24 | * 25 | * @author Mercy 26 | * @since 1.0.0 27 | */ 28 | public class GenericTestService extends DefaultTestService implements TestService, EventListener { 29 | @Override 30 | public String echo(String message) { 31 | return "[ECHO] " + message; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/multiple/StringToSortedSetConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert.multiple; 18 | 19 | import java.util.SortedSet; 20 | import java.util.TreeSet; 21 | 22 | /** 23 | * The class to convert {@link String} to {@link SortedSet}-based value 24 | * 25 | * @since 1.0.0 26 | */ 27 | public class StringToSortedSetConverter extends StringToIterableConverter { 28 | 29 | @Override 30 | protected SortedSet createMultiValue(int size, Class multiValueType) { 31 | return new TreeSet(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/net/test/Handler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.net.test; 18 | 19 | import io.microsphere.net.ExtendableProtocolURLStreamHandler; 20 | 21 | /** 22 | * Test {@link ExtendableProtocolURLStreamHandler} 23 | * 24 | * @author Mercy 25 | * @since 1.0.0 26 | */ 27 | public class Handler extends ExtendableProtocolURLStreamHandler { 28 | 29 | public Handler() { 30 | super(); 31 | } 32 | 33 | public Handler(String protocol) { 34 | super(protocol); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/annotation/ImmutableTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.microsphere.annotation; 19 | 20 | import org.junit.jupiter.api.Test; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertNotNull; 23 | 24 | /** 25 | * {@link Immutable} Test 26 | * 27 | * @author Mercy 28 | * @see Immutable 29 | * @since 1.0.0 30 | */ 31 | @Immutable 32 | class ImmutableTest { 33 | 34 | @Test 35 | void test() { 36 | assertNotNull(ImmutableTest.class.getAnnotation(Immutable.class)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/reflect/MultipleTypeTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.reflect; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static io.microsphere.reflect.MultipleType.of; 7 | import static java.util.Objects.hash; 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.api.Assertions.assertNotEquals; 10 | 11 | /** 12 | * {@link MultipleType} Test 13 | * 14 | * @author Mercy 15 | * @since 1.0.0 16 | */ 17 | class MultipleTypeTest { 18 | 19 | private MultipleType multipleType; 20 | 21 | @BeforeEach 22 | void setUp() { 23 | this.multipleType = of(String.class, Object.class); 24 | } 25 | 26 | @Test 27 | void testHashCode() { 28 | assertEquals(hash(String.class, Object.class), multipleType.hashCode()); 29 | } 30 | 31 | @Test 32 | void testEquals() { 33 | assertEquals(of(String.class, Object.class), multipleType); 34 | assertEquals(of(String.class, Object.class, Integer.class), of(String.class, Object.class, Integer.class)); 35 | assertNotEquals(of(String.class, Object.class, Integer.class), multipleType); 36 | } 37 | 38 | @Test 39 | void testToString() { 40 | assertEquals("MultipleType : [class java.lang.String, class java.lang.Object]", multipleType.toString()); 41 | } 42 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/multiple/StringToCollectionConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert.multiple; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Collection; 21 | 22 | /** 23 | * The class to convert {@link String} to {@link Collection}-based value 24 | * 25 | * @since 1.0.0 26 | */ 27 | public class StringToCollectionConverter extends StringToIterableConverter { 28 | 29 | @Override 30 | protected Collection createMultiValue(int size, Class multiValueType) { 31 | return new ArrayList(size); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/multiple/StringToQueueConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert.multiple; 18 | 19 | import java.util.ArrayDeque; 20 | import java.util.Deque; 21 | import java.util.Queue; 22 | 23 | /** 24 | * The class to convert {@link String} to {@link Deque}-based value 25 | * 26 | * @since 1.0.0 27 | */ 28 | public class StringToQueueConverter extends StringToIterableConverter { 29 | 30 | @Override 31 | protected Queue createMultiValue(int size, Class multiValueType) { 32 | return new ArrayDeque(size); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/collection/SingletonIteratorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.collection; 18 | 19 | import java.util.Iterator; 20 | 21 | import static io.microsphere.collection.CollectionUtils.singletonIterator; 22 | 23 | /** 24 | * {@link SingletonIterator} Test 25 | * 26 | * @author Mercy 27 | * @since 1.0.0 28 | */ 29 | class SingletonIteratorTest extends ReadOnlyIteratorTest { 30 | 31 | @Override 32 | protected Iterator createIterator() { 33 | return singletonIterator(TEST_ELEMENT); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/constants/PropertyConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.constants; 18 | 19 | /** 20 | * The property constants for Microsphere Core 21 | * 22 | * @author Mercy 23 | * @since 1.0.0 24 | */ 25 | public interface PropertyConstants { 26 | 27 | /** 28 | * The property name of "enabled" 29 | */ 30 | String ENABLED_PROPERTY_NAME = "enabled"; 31 | 32 | /** 33 | * The property name prefix of microsphere 34 | */ 35 | String MICROSPHERE_PROPERTY_NAME_PREFIX = "microsphere."; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/lang/function/ThrowableSupplierTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.lang.function; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertThrows; 22 | 23 | /** 24 | * {@link ThrowableSupplier} Test 25 | * 26 | * @since 1.0.0 27 | */ 28 | class ThrowableSupplierTest { 29 | 30 | @Test 31 | void testExecute() { 32 | assertThrows(RuntimeException.class, () -> ThrowableSupplier.execute(() -> { 33 | throw new Exception("Hello,World"); 34 | }), "Hello,World"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/reflect/ClassDefinitionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.reflect; 18 | 19 | import java.util.List; 20 | 21 | import static java.util.Collections.emptyList; 22 | 23 | /** 24 | * {@link ClassDefinition} Test 25 | * 26 | * @author Mercy 27 | * @see ClassDefinition 28 | * @since 1.0.0 29 | */ 30 | class ClassDefinitionTest extends AbstractReflectiveDefinitionTest { 31 | 32 | @Override 33 | protected List getTailConstructorArguments() { 34 | return emptyList(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/annotation/Immutable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | 22 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 23 | 24 | /** 25 | * Marker annotation to indicate that the annotated element is immutable, this means that its state cannot be seen to 26 | * change by callers. 27 | * 28 | * @author Mercy 29 | * @since 1.0.0 30 | */ 31 | @Documented 32 | @Retention(RUNTIME) 33 | public @interface Immutable { 34 | } 35 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/classloading/BannedArtifactClassLoadingExecutorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.classloading; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | /** 22 | * {@link BannedArtifactClassLoadingExecutor} Test 23 | * 24 | * @author Mercy 25 | * @since 1.0.0 26 | */ 27 | class BannedArtifactClassLoadingExecutorTest { 28 | 29 | private BannedArtifactClassLoadingExecutor detector = new BannedArtifactClassLoadingExecutor(); 30 | 31 | @Test 32 | void testDetect() { 33 | detector.execute(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/lang/DelegatingWrapperImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.lang; 18 | 19 | /** 20 | * DelegatingWrapper Implementation 21 | * 22 | * @author Mercy 23 | * @see DelegatingWrapper 24 | * @since 1.0.0 25 | */ 26 | class DelegatingWrapperImpl implements DelegatingWrapper { 27 | 28 | private final Object delegate; 29 | 30 | DelegatingWrapperImpl(Object delegate) { 31 | this.delegate = delegate; 32 | } 33 | 34 | @Override 35 | public Object getDelegate() { 36 | return delegate; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/collection/LinkedListTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.microsphere.collection; 19 | 20 | import java.util.LinkedList; 21 | import java.util.List; 22 | 23 | import static io.microsphere.collection.ListUtils.newLinkedList; 24 | 25 | /** 26 | * {@link LinkedList} Test 27 | * 28 | * @author Mercy 29 | * @see List 30 | * @since 1.0.0 31 | */ 32 | class LinkedListTest extends MutableDequeTest> { 33 | @Override 34 | protected LinkedList newInstance() { 35 | return newLinkedList(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/annotation/ExperimentalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.annotation; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertNull; 22 | 23 | /** 24 | * {@link Experimental} Test 25 | * 26 | * @author Mercy 27 | * @see Experimental 28 | * @since 1.0.0 29 | */ 30 | @Experimental(description = "ExperimentalTest") 31 | class ExperimentalTest { 32 | 33 | @Test 34 | void test() { 35 | assertNull(ExperimentalTest.class.getAnnotation(Experimental.class)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/multiple/StringToNavigableSetConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert.multiple; 18 | 19 | import java.util.NavigableSet; 20 | import java.util.SortedSet; 21 | import java.util.TreeSet; 22 | 23 | /** 24 | * The class to convert {@link String} to {@link SortedSet}-based value 25 | * 26 | * @since 1.0.0 27 | */ 28 | public class StringToNavigableSetConverter extends StringToIterableConverter { 29 | 30 | @Override 31 | protected NavigableSet createMultiValue(int size, Class multiValueType) { 32 | return new TreeSet(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/collection/ArrayEnumerationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.microsphere.collection; 19 | 20 | 21 | import java.util.Enumeration; 22 | 23 | import static io.microsphere.collection.EnumerationUtils.ofEnumeration; 24 | 25 | /** 26 | * {@link ArrayEnumeration} Test 27 | * 28 | * @author Mercy 29 | * @see ArrayEnumeration 30 | * @since 1.0.0 31 | */ 32 | class ArrayEnumerationTest extends AbstractEnumerationTest { 33 | 34 | @Override 35 | protected Enumeration createEnumeration() { 36 | return ofEnumeration(values); 37 | } 38 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/annotation/Nullable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.microsphere.annotation; 18 | 19 | import javax.annotation.meta.TypeQualifierNickname; 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.Retention; 22 | 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | import static javax.annotation.meta.When.MAYBE; 25 | 26 | /** 27 | * A common Microsphere annotation to declare that annotated elements can be {@code null} under 28 | * some circumstance. 29 | * 30 | * @author Mercy 31 | * @see javax.annotation.Nonnull 32 | * @since 1.0.0 33 | */ 34 | @Documented 35 | @Retention(RUNTIME) 36 | @javax.annotation.Nonnull(when = MAYBE) 37 | @TypeQualifierNickname 38 | public @interface Nullable { 39 | } 40 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/io/filter/DirectoryFileFilterTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.io.filter; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | 8 | import static io.microsphere.io.filter.DirectoryFileFilter.INSTANCE; 9 | import static io.microsphere.util.SystemUtils.JAVA_HOME; 10 | import static io.microsphere.util.SystemUtils.JAVA_IO_TMPDIR; 11 | import static io.microsphere.util.SystemUtils.USER_DIR; 12 | import static java.io.File.createTempFile; 13 | import static org.junit.jupiter.api.Assertions.assertFalse; 14 | import static org.junit.jupiter.api.Assertions.assertTrue; 15 | 16 | /** 17 | * {@link DirectoryFileFilter} Test 18 | * 19 | * @author Mercy 20 | * @see DirectoryFileFilter 21 | * @since 1.0.0 22 | */ 23 | class DirectoryFileFilterTest { 24 | 25 | @Test 26 | void testAcceptOnNull() { 27 | assertFalse(INSTANCE.accept(null)); 28 | } 29 | 30 | @Test 31 | void testAcceptOnDirectory() { 32 | assertTrue(INSTANCE.accept(new File(JAVA_HOME))); 33 | assertTrue(INSTANCE.accept(new File(USER_DIR))); 34 | assertTrue(INSTANCE.accept(new File(JAVA_IO_TMPDIR))); 35 | } 36 | 37 | @Test 38 | void testAcceptOnFile() throws IOException { 39 | File testFile = createTempFile("test", "txt"); 40 | assertFalse(INSTANCE.accept(testFile)); 41 | testFile.deleteOnExit(); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/multiple/StringToTransferQueueConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert.multiple; 18 | 19 | import java.util.concurrent.LinkedTransferQueue; 20 | import java.util.concurrent.TransferQueue; 21 | 22 | /** 23 | * The class to convert {@link String} to {@link TransferQueue}-based value 24 | * 25 | * @since 1.0.0 26 | */ 27 | public class StringToTransferQueueConverter extends StringToIterableConverter { 28 | 29 | @Override 30 | protected TransferQueue createMultiValue(int size, Class multiValueType) { 31 | return new LinkedTransferQueue(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/metadata/NullConfigurationPropertyLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.microsphere.metadata; 19 | 20 | import io.microsphere.beans.ConfigurationProperty; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * Null {@link ConfigurationPropertyLoader} 26 | * 27 | * @author Mercy 28 | * @see ConfigurationPropertyLoader 29 | * @since 1.0.0 30 | */ 31 | public class NullConfigurationPropertyLoader implements ConfigurationPropertyLoader { 32 | @Override 33 | public List load() throws Throwable { 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/multiple/StringToBlockingDequeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert.multiple; 18 | 19 | import java.util.concurrent.BlockingDeque; 20 | import java.util.concurrent.LinkedBlockingDeque; 21 | 22 | /** 23 | * The class to convert {@link String} to {@link BlockingDeque}-based value 24 | * 25 | * @since 1.0.0 26 | */ 27 | public class StringToBlockingDequeConverter extends StringToIterableConverter { 28 | 29 | @Override 30 | protected BlockingDeque createMultiValue(int size, Class multiValueType) { 31 | return new LinkedBlockingDeque(size); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/filter/ClassFileJarEntryFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package io.microsphere.filter; 5 | 6 | import java.util.jar.JarEntry; 7 | 8 | import static io.microsphere.constants.FileConstants.CLASS_EXTENSION; 9 | 10 | /** 11 | * A {@link JarEntryFilter} implementation that filters only Java class files in a JAR. 12 | * 13 | *

This filter checks whether a given {@link JarEntry} represents a Java class file by: 14 | *

    15 | *
  • Ensuring it is not a directory
  • 16 | *
  • Checking if its name ends with the ".class" extension
  • 17 | *
18 | * 19 | *

Example Usage

20 | *
{@code
21 |  * JarFile jarFile = new JarFile("example.jar");
22 |  * Enumeration entries = jarFile.stream()
23 |  *     .filter(ClassFileJarEntryFilter.INSTANCE::accept)
24 |  *     .iterator();
25 |  * }
26 | * 27 | * @author Mercy 28 | * @see JarEntryFilter 29 | * @see JarEntry 30 | * @since 1.0.0 31 | */ 32 | public class ClassFileJarEntryFilter implements JarEntryFilter { 33 | 34 | /** 35 | * {@link ClassFileJarEntryFilter} Singleton instance 36 | */ 37 | public static final ClassFileJarEntryFilter INSTANCE = new ClassFileJarEntryFilter(); 38 | 39 | protected ClassFileJarEntryFilter() { 40 | 41 | } 42 | 43 | @Override 44 | public boolean accept(JarEntry jarEntry) { 45 | return !jarEntry.isDirectory() && jarEntry.getName().endsWith(CLASS_EXTENSION); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/metadata/ErrorConfigurationPropertyLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.microsphere.metadata; 19 | 20 | import io.microsphere.beans.ConfigurationProperty; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * Error {@link ConfigurationPropertyLoader} 26 | * 27 | * @author Mercy 28 | * @see ConfigurationPropertyLoader 29 | * @since 1.0.0 30 | */ 31 | public class ErrorConfigurationPropertyLoader implements ConfigurationPropertyLoader { 32 | @Override 33 | public List load() throws Throwable { 34 | throw new Throwable("For testing purpose only"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLStreamHandlerFactoryTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.net; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static io.microsphere.constants.ProtocolConstants.FILE_PROTOCOL; 7 | import static org.junit.jupiter.api.Assertions.assertNotNull; 8 | import static org.junit.jupiter.api.Assertions.assertSame; 9 | import static org.junit.jupiter.api.Assertions.assertThrows; 10 | 11 | /** 12 | * {@link DelegatingURLStreamHandlerFactory Test} 13 | * 14 | * @author Mercy 15 | * @see DelegatingURLStreamHandlerFactory 16 | * @since 1.0.0 17 | */ 18 | class DelegatingURLStreamHandlerFactoryTest { 19 | 20 | private StandardURLStreamHandlerFactory delegate; 21 | 22 | private DelegatingURLStreamHandlerFactory factory; 23 | 24 | @BeforeEach 25 | void setUp() { 26 | this.delegate = new StandardURLStreamHandlerFactory(); 27 | this.factory = new DelegatingURLStreamHandlerFactory(this.delegate); 28 | } 29 | 30 | @Test 31 | void testConstructorOnNull() { 32 | assertThrows(IllegalArgumentException.class, () -> new DelegatingURLStreamHandlerFactory(null)); 33 | } 34 | 35 | @Test 36 | void testCreateURLStreamHandler() { 37 | assertNotNull(this.factory.createURLStreamHandler(FILE_PROTOCOL)); 38 | } 39 | 40 | @Test 41 | void testGetDelegate() { 42 | assertSame(this.delegate, this.factory.getDelegate()); 43 | } 44 | } -------------------------------------------------------------------------------- /microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/model/Color.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.annotation.processor.model; 18 | 19 | /** 20 | * Color enumeration 21 | * 22 | * @since 1.0.0 23 | */ 24 | public enum Color { 25 | 26 | RED(1), 27 | YELLOW(2), 28 | BLUE(3); 29 | 30 | private final int value; 31 | 32 | Color(int value) { 33 | this.value = value; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "Color{" + 39 | "value=" + value + 40 | "} " + super.toString(); 41 | } 42 | 43 | public int getValue() { 44 | return value; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/StringToByteConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import static java.lang.Byte.valueOf; 20 | 21 | /** 22 | * The class to convert {@link String} to {@link Byte} 23 | * 24 | * @since 1.0.0 25 | */ 26 | public class StringToByteConverter extends AbstractConverter implements StringConverter { 27 | 28 | /** 29 | * Singleton instance of {@link StringToByteConverter}. 30 | */ 31 | public static final StringToByteConverter INSTANCE = new StringToByteConverter(); 32 | 33 | @Override 34 | protected Byte doConvert(String source) { 35 | return valueOf(source); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/StringToCharArrayConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | 20 | /** 21 | * The class to convert {@link String} to char[] 22 | * 23 | * @since 1.0.0 24 | */ 25 | public class StringToCharArrayConverter extends AbstractConverter implements StringConverter { 26 | 27 | /** 28 | * Singleton instance of {@link StringToCharArrayConverter}. 29 | */ 30 | public static final StringToCharArrayConverter INSTANCE = new StringToCharArrayConverter(); 31 | 32 | @Override 33 | protected char[] doConvert(String source) { 34 | return source.toCharArray(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/StringToLongConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import static java.lang.Long.valueOf; 20 | 21 | /** 22 | * The class to convert {@link String} to {@link Long} 23 | * 24 | * @since 1.0.0 25 | */ 26 | public class StringToLongConverter extends AbstractConverter implements StringConverter { 27 | 28 | /** 29 | * Singleton instance of {@link StringToLongConverter}. 30 | */ 31 | public static final StringToLongConverter INSTANCE = new StringToLongConverter(); 32 | 33 | @Override 34 | protected Long doConvert(String source) { 35 | return valueOf(source); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/multiple/StringToBlockingQueueConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert.multiple; 18 | 19 | import java.util.concurrent.ArrayBlockingQueue; 20 | import java.util.concurrent.BlockingDeque; 21 | import java.util.concurrent.BlockingQueue; 22 | 23 | /** 24 | * The class to convert {@link String} to {@link BlockingDeque}-based value 25 | * 26 | * @since 1.0.0 27 | */ 28 | public class StringToBlockingQueueConverter extends StringToIterableConverter { 29 | 30 | @Override 31 | protected BlockingQueue createMultiValue(int size, Class multiValueType) { 32 | return new ArrayBlockingQueue(size); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/collection/SingletonEnumerationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.collection; 18 | 19 | import java.util.Iterator; 20 | 21 | import static io.microsphere.collection.CollectionUtils.singletonEnumeration; 22 | import static io.microsphere.collection.CollectionUtils.toIterator; 23 | 24 | /** 25 | * {@link SingletonEnumeration} Test 26 | * 27 | * @author Mercy 28 | * @since 1.0.0 29 | */ 30 | class SingletonEnumerationTest extends ReadOnlyIteratorTest { 31 | 32 | @Override 33 | protected Iterator createIterator() { 34 | return toIterator(singletonEnumeration(TEST_ELEMENT)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/net/console/Handler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.net.console; 18 | 19 | import io.microsphere.net.ExtendableProtocolURLStreamHandler; 20 | 21 | import java.io.IOException; 22 | import java.net.Proxy; 23 | import java.net.URL; 24 | import java.net.URLConnection; 25 | 26 | /** 27 | * "console" protocol Handler 28 | * 29 | * @author Mercy 30 | * @since 1.0.0 31 | */ 32 | public class Handler extends ExtendableProtocolURLStreamHandler { 33 | 34 | @Override 35 | public URLConnection openConnection(URL url, Proxy proxy) throws IOException { 36 | return new ConsoleURLConnection(url); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/StringToFloatConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import static java.lang.Float.valueOf; 20 | 21 | /** 22 | * The class to convert {@link String} to {@link Float} 23 | * 24 | * @since 1.0.0 25 | */ 26 | public class StringToFloatConverter extends AbstractConverter implements StringConverter { 27 | 28 | /** 29 | * Singleton instance of {@link StringToFloatConverter}. 30 | */ 31 | public static final StringToFloatConverter INSTANCE = new StringToFloatConverter(); 32 | 33 | @Override 34 | protected Float doConvert(String source) { 35 | return valueOf(source); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/StringToShortConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import static java.lang.Short.valueOf; 20 | 21 | /** 22 | * The class to convert {@link String} to {@link Short} 23 | * 24 | * @since 1.0.0 25 | */ 26 | public class StringToShortConverter extends AbstractConverter implements StringConverter { 27 | 28 | /** 29 | * Singleton instance of {@link StringToShortConverter}. 30 | */ 31 | public static final StringToShortConverter INSTANCE = new StringToShortConverter(); 32 | 33 | @Override 34 | protected Short doConvert(String source) { 35 | return valueOf(source); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/collection/EnumerationIteratorAdapterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.collection; 18 | 19 | import io.microsphere.AbstractTestCase; 20 | import org.junit.jupiter.api.Test; 21 | 22 | import java.util.Iterator; 23 | 24 | import static io.microsphere.collection.CollectionUtils.singletonIterator; 25 | 26 | /** 27 | * {@link EnumerationIteratorAdapter} Test 28 | * 29 | * @author Mercy 30 | * @since 1.0.0 31 | */ 32 | class EnumerationIteratorAdapterTest extends AbstractTestCase { 33 | 34 | @Test 35 | void test() { 36 | Iterator iterator = singletonIterator(TEST_ELEMENT); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/collection/UnmodifiableIteratorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.collection; 18 | 19 | import java.util.Iterator; 20 | 21 | import static io.microsphere.collection.CollectionUtils.singletonIterator; 22 | import static io.microsphere.collection.CollectionUtils.unmodifiableIterator; 23 | 24 | /** 25 | * {@link UnmodifiableIterator} Test 26 | * 27 | * @author Mercy 28 | * @since 1.0.0 29 | */ 30 | class UnmodifiableIteratorTest extends ReadOnlyIteratorTest { 31 | 32 | @Override 33 | protected Iterator createIterator() { 34 | return unmodifiableIterator(singletonIterator(TEST_ELEMENT)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/metadata/EmptyConfigurationPropertyLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.microsphere.metadata; 19 | 20 | import io.microsphere.beans.ConfigurationProperty; 21 | 22 | import java.util.List; 23 | 24 | import static java.util.Collections.emptyList; 25 | 26 | /** 27 | * Empty {@link ConfigurationPropertyLoader} 28 | * 29 | * @author Mercy 30 | * @see ConfigurationPropertyLoader 31 | * @since 1.0.0 32 | */ 33 | public class EmptyConfigurationPropertyLoader implements ConfigurationPropertyLoader { 34 | @Override 35 | public List load() throws Throwable { 36 | return emptyList(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/model/ArrayTypeModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.annotation.processor.model; 18 | 19 | /** 20 | * Array Type Model 21 | * 22 | * @since 1.0.0 23 | */ 24 | public class ArrayTypeModel { 25 | 26 | private int[] integers; // Primitive type array 27 | 28 | private String[] strings; // Simple type array 29 | 30 | private PrimitiveTypeModel[] primitiveTypeModels; // Complex type array 31 | 32 | private Model[] models; // Hierarchical Complex type array 33 | 34 | private Color[] colors; // Enum type array 35 | 36 | } 37 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/StringToDoubleConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import static java.lang.Double.valueOf; 20 | 21 | /** 22 | * The class to convert {@link String} to {@link Double} 23 | * 24 | * @since 1.0.0 25 | */ 26 | public class StringToDoubleConverter extends AbstractConverter implements StringConverter { 27 | 28 | /** 29 | * Singleton instance of {@link StringToDoubleConverter}. 30 | */ 31 | public static final StringToDoubleConverter INSTANCE = new StringToDoubleConverter(); 32 | 33 | @Override 34 | protected Double doConvert(String source) { 35 | return valueOf(source); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/StringToStringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import static java.lang.String.valueOf; 20 | 21 | /** 22 | * The class to convert {@link String} to {@link String} 23 | * 24 | * @since 1.0.0 25 | */ 26 | public class StringToStringConverter extends AbstractConverter implements StringConverter { 27 | 28 | /** 29 | * Singleton instance of {@link StringToStringConverter}. 30 | */ 31 | public static final StringToStringConverter INSTANCE = new StringToStringConverter(); 32 | 33 | @Override 34 | protected String doConvert(String source) { 35 | return valueOf(source); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/constants/ProtocolConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package io.microsphere.constants; 5 | 6 | import static io.microsphere.constants.FileConstants.EAR; 7 | import static io.microsphere.constants.FileConstants.JAR; 8 | import static io.microsphere.constants.FileConstants.WAR; 9 | import static io.microsphere.constants.FileConstants.ZIP; 10 | 11 | /** 12 | * Protocol Constants Definition 13 | * 14 | * @author Mercy 15 | * @see ProtocolConstants 16 | * @since 1.0.0 17 | */ 18 | public interface ProtocolConstants { 19 | 20 | /** 21 | * File protocol 22 | */ 23 | String FILE_PROTOCOL = "file"; 24 | 25 | /** 26 | * HTTP protocol 27 | */ 28 | String HTTP_PROTOCOL = "http"; 29 | 30 | /** 31 | * HTTPS protocol 32 | */ 33 | String HTTPS_PROTOCOL = "https"; 34 | 35 | /** 36 | * FTP protocol 37 | */ 38 | String FTP_PROTOCOL = "ftp"; 39 | 40 | /** 41 | * Zip protocol 42 | */ 43 | String ZIP_PROTOCOL = ZIP; 44 | 45 | /** 46 | * Jar protocol 47 | */ 48 | String JAR_PROTOCOL = JAR; 49 | 50 | /** 51 | * War protocol 52 | */ 53 | String WAR_PROTOCOL = WAR; 54 | 55 | /** 56 | * Ear protocol 57 | */ 58 | String EAR_PROTOCOL = EAR; 59 | 60 | /** 61 | * Class-Path Protocol 62 | */ 63 | String CLASSPATH_PROTOCOL = "classpath"; 64 | 65 | /** 66 | * Console Protocol 67 | */ 68 | String CONSOLE_PROTOCOL = "console"; 69 | } 70 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/annotation/SinceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.annotation; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | /** 24 | * {@link Since @Since} Test 25 | * 26 | * @author Mercy 27 | * @see Since 28 | * @since 1.0.0 29 | */ 30 | @Since(module = "microsphere-java-core", value = "1.0.0") 31 | class SinceTest { 32 | 33 | @Test 34 | void test() { 35 | Since since = SinceTest.class.getAnnotation(Since.class); 36 | assertEquals("microsphere-java-core", since.module()); 37 | assertEquals("1.0.0", since.value()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/StringToIntegerConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import static java.lang.Integer.valueOf; 20 | 21 | /** 22 | * The class to convert {@link String} to {@link Integer} 23 | * 24 | * @since 1.0.0 25 | */ 26 | public class StringToIntegerConverter extends AbstractConverter implements StringConverter { 27 | 28 | /** 29 | * Singleton instance of {@link StringToIntegerConverter}. 30 | */ 31 | public static final StringToIntegerConverter INSTANCE = new StringToIntegerConverter(); 32 | 33 | @Override 34 | protected Integer doConvert(String source) { 35 | return valueOf(source); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/event/GenericEventTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.event; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | import static org.junit.jupiter.api.Assertions.assertTrue; 23 | 24 | /** 25 | * {@link GenericEvent} Test 26 | * 27 | * @since 1.0.0 28 | */ 29 | class GenericEventTest { 30 | 31 | @Test 32 | void test() { 33 | 34 | long timestamp = System.currentTimeMillis(); 35 | GenericEvent event = new GenericEvent("Hello,World"); 36 | 37 | assertEquals("Hello,World", event.getSource()); 38 | assertTrue(event.getTimestamp() >= timestamp); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/ObjectToStringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.microsphere.convert; 19 | 20 | /** 21 | * The {@link Converter} for {@link Object} to {@link String} 22 | * 23 | * @author Mercy 24 | * @see Converter 25 | * @since 1.0.0 26 | */ 27 | public class ObjectToStringConverter extends AbstractConverter { 28 | 29 | /** 30 | * Singleton instance of {@link ObjectToStringConverter}. 31 | */ 32 | public static final ObjectToStringConverter INSTANCE = new ObjectToStringConverter(); 33 | 34 | @Override 35 | protected String doConvert(Object source) { 36 | return source.toString(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /.github/workflows/maven-build.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Maven Build 10 | 11 | on: 12 | push: 13 | branches: [ "dev" ] 14 | pull_request: 15 | branches: [ "main" , "dev" , "release" ] 16 | 17 | jobs: 18 | build: 19 | runs-on: ubuntu-latest 20 | strategy: 21 | matrix: 22 | java: [ '8', '11' , '17' , '21' , '25' ] 23 | steps: 24 | - name: Checkout Source 25 | uses: actions/checkout@v4 26 | 27 | - name: Setup JDK ${{ matrix.Java }} 28 | uses: actions/setup-java@v4 29 | with: 30 | distribution: 'temurin' 31 | java-version: ${{ matrix.java }} 32 | cache: maven 33 | 34 | - name: Build with Maven 35 | run: mvn 36 | --batch-mode 37 | --update-snapshots 38 | --file pom.xml 39 | -Drevision=0.0.1-SNAPSHOT 40 | test 41 | --activate-profiles test,coverage 42 | 43 | - name: Upload coverage reports to Codecov 44 | uses: codecov/codecov-action@v5 45 | with: 46 | token: ${{ secrets.CODECOV_TOKEN }} 47 | slug: microsphere-projects/microsphere-java -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/process/ModernProcessIdResolverTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.process; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static io.microsphere.util.Version.Operator.GE; 7 | import static io.microsphere.util.VersionUtils.JAVA_VERSION_9; 8 | import static io.microsphere.util.VersionUtils.testCurrentJavaVersion; 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | import static org.junit.jupiter.api.Assertions.assertNotNull; 11 | import static org.junit.jupiter.api.Assertions.assertThrows; 12 | 13 | /** 14 | * {@link ModernProcessIdResolver} Test 15 | * 16 | * @author Mercy 17 | * @see ModernProcessIdResolver 18 | * @since 1.0.0 19 | */ 20 | class ModernProcessIdResolverTest { 21 | 22 | private ModernProcessIdResolver resolver; 23 | 24 | private static final boolean isGEJava9 = testCurrentJavaVersion(GE, JAVA_VERSION_9); 25 | 26 | @BeforeEach 27 | void setUp() { 28 | resolver = new ModernProcessIdResolver(); 29 | } 30 | 31 | @Test 32 | void testSupports() { 33 | assertEquals(isGEJava9, resolver.supports()); 34 | } 35 | 36 | @Test 37 | void testCurrent() { 38 | if (isGEJava9) { 39 | assertNotNull(resolver.current()); 40 | } else { 41 | assertThrows(NullPointerException.class, resolver::current); 42 | } 43 | } 44 | 45 | @Test 46 | void testGetPriority() { 47 | assertEquals(1, resolver.getPriority()); 48 | } 49 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/convert/StringToStringConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import static io.microsphere.convert.StringToStringConverter.INSTANCE; 20 | 21 | /** 22 | * {@link StringToStringConverter} Test 23 | * 24 | * @since 1.0.0 25 | */ 26 | class StringToStringConverterTest extends BaseConverterTest { 27 | 28 | @Override 29 | protected AbstractConverter createConverter() { 30 | return INSTANCE; 31 | } 32 | 33 | @Override 34 | protected String getSource() throws Throwable { 35 | return "1"; 36 | } 37 | 38 | @Override 39 | protected String getTarget() throws Throwable { 40 | return "1"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-dependencies/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | io.github.microsphere-projects 7 | microsphere-java-parent 8 | ${revision} 9 | ../microsphere-java-parent/pom.xml 10 | 11 | 4.0.0 12 | 13 | io.github.microsphere-projects 14 | microsphere-java-dependencies 15 | ${revision} 16 | pom 17 | 18 | Microsphere :: Java :: Dependencies 19 | Microsphere Java Dependencies 20 | 21 | 22 | 23 | 24 | 25 | io.github.microsphere-projects 26 | microsphere-annotation-processor 27 | ${revision} 28 | 29 | 30 | 31 | io.github.microsphere-projects 32 | microsphere-java-core 33 | ${revision} 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/MapToPropertiesConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | 20 | import java.util.Map; 21 | import java.util.Properties; 22 | 23 | /** 24 | * The {@link Map} To {@link Properties} {@link Converter} 25 | * 26 | * @author Mercy 27 | * @since 1.0.0 28 | */ 29 | public class MapToPropertiesConverter extends AbstractConverter { 30 | 31 | public static final MapToPropertiesConverter INSTANCE = new MapToPropertiesConverter(); 32 | 33 | @Override 34 | public Properties doConvert(Map source) { 35 | Properties properties = new Properties(); 36 | properties.putAll(source); 37 | return properties; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/convert/StringToCharArrayConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import static io.microsphere.convert.StringToCharArrayConverter.INSTANCE; 20 | 21 | /** 22 | * {@link StringToCharArrayConverter} Test 23 | * 24 | * @since 1.0.0 25 | */ 26 | class StringToCharArrayConverterTest extends BaseConverterTest { 27 | 28 | @Override 29 | protected AbstractConverter createConverter() { 30 | return INSTANCE; 31 | } 32 | 33 | @Override 34 | protected String getSource() throws Throwable { 35 | return "123"; 36 | } 37 | 38 | @Override 39 | protected char[] getTarget() throws Throwable { 40 | return new char[]{'1', '2', '3'}; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/NumberToByteConverter.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Licensed to the Apache Software Foundation (ASF) under one or more 4 | * contributor license agreements. See the NOTICE file distributed with 5 | * this work for additional information regarding copyright ownership. 6 | * The ASF licenses this file to You under the Apache License, Version 2.0 7 | * (the "License"); you may not use this file except in compliance with 8 | * the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package io.microsphere.convert; 20 | 21 | /** 22 | * The {@link Converter} for {@link Number} to {@link Byte} 23 | * 24 | * @author Mercy 25 | * @see Converter 26 | * @since 1.0.0 27 | */ 28 | public class NumberToByteConverter extends AbstractConverter { 29 | 30 | /** 31 | * Singleton instance of {@link NumberToByteConverter}. 32 | */ 33 | public static final NumberToByteConverter INSTANCE = new NumberToByteConverter(); 34 | 35 | @Override 36 | protected Byte doConvert(Number source) { 37 | if (source instanceof Byte) { 38 | return (Byte) source; 39 | } 40 | return source.byteValue(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/NumberToLongConverter.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Licensed to the Apache Software Foundation (ASF) under one or more 4 | * contributor license agreements. See the NOTICE file distributed with 5 | * this work for additional information regarding copyright ownership. 6 | * The ASF licenses this file to You under the Apache License, Version 2.0 7 | * (the "License"); you may not use this file except in compliance with 8 | * the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package io.microsphere.convert; 20 | 21 | /** 22 | * The {@link Converter} for {@link Number} to {@link Long} 23 | * 24 | * @author Mercy 25 | * @see Converter 26 | * @since 1.0.0 27 | */ 28 | public class NumberToLongConverter extends AbstractConverter { 29 | 30 | /** 31 | * Singleton instance of {@link NumberToLongConverter}. 32 | */ 33 | public static final NumberToLongConverter INSTANCE = new NumberToLongConverter(); 34 | 35 | @Override 36 | protected Long doConvert(Number source) { 37 | if (source instanceof Long) { 38 | return (Long) source; 39 | } 40 | return source.longValue(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/StringToBooleanConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import static io.microsphere.util.CharSequenceUtils.isNotEmpty; 20 | import static java.lang.Boolean.valueOf; 21 | 22 | /** 23 | * The class to convert {@link String} to {@link Boolean} 24 | * 25 | * @since 1.0.0 26 | */ 27 | public class StringToBooleanConverter extends AbstractConverter implements StringConverter { 28 | 29 | /** 30 | * Singleton instance of {@link StringToBooleanConverter}. 31 | */ 32 | public static final StringToBooleanConverter INSTANCE = new StringToBooleanConverter(); 33 | 34 | @Override 35 | protected Boolean doConvert(String source) { 36 | return isNotEmpty(source) ? valueOf(source) : null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/io/filter/FileExtensionFilterTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.io.filter; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | import static io.microsphere.io.filter.FileExtensionFilter.of; 10 | import static io.microsphere.util.SystemUtils.JAVA_HOME; 11 | import static io.microsphere.util.SystemUtils.JAVA_IO_TMPDIR; 12 | import static io.microsphere.util.SystemUtils.USER_DIR; 13 | import static java.io.File.createTempFile; 14 | import static org.junit.jupiter.api.Assertions.assertFalse; 15 | import static org.junit.jupiter.api.Assertions.assertTrue; 16 | 17 | /** 18 | * {@link FileExtensionFilter} Test 19 | * 20 | * @author Mercy 21 | * @see FileExtensionFilter 22 | * @since 1.0.0 23 | */ 24 | class FileExtensionFilterTest { 25 | 26 | private FileExtensionFilter instance; 27 | 28 | @BeforeEach 29 | void setUp() { 30 | instance = of("txt"); 31 | } 32 | 33 | @Test 34 | void testAcceptOnNull() { 35 | assertFalse(instance.accept(null)); 36 | } 37 | 38 | @Test 39 | void testAcceptOnDirectory() { 40 | assertFalse(instance.accept(new File(JAVA_HOME))); 41 | assertFalse(instance.accept(new File(USER_DIR))); 42 | assertFalse(instance.accept(new File(JAVA_IO_TMPDIR))); 43 | } 44 | 45 | @Test 46 | void testAcceptOnFile() throws IOException { 47 | File testFile = createTempFile("test", ".txt"); 48 | assertTrue(instance.accept(testFile)); 49 | testFile.deleteOnExit(); 50 | } 51 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/constants/PropertyConstantsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.constants; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static io.microsphere.constants.PropertyConstants.ENABLED_PROPERTY_NAME; 22 | import static io.microsphere.constants.PropertyConstants.MICROSPHERE_PROPERTY_NAME_PREFIX; 23 | import static org.junit.jupiter.api.Assertions.assertEquals; 24 | 25 | /** 26 | * {@link PropertyConstants} Test 27 | * 28 | * @author Mercy 29 | * @see PropertyConstants 30 | * @since 1.0.0 31 | */ 32 | class PropertyConstantsTest { 33 | 34 | @Test 35 | void test() { 36 | assertEquals("enabled", ENABLED_PROPERTY_NAME); 37 | assertEquals("microsphere.", MICROSPHERE_PROPERTY_NAME_PREFIX); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/NumberToCharacterConverter.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Licensed to the Apache Software Foundation (ASF) under one or more 4 | * contributor license agreements. See the NOTICE file distributed with 5 | * this work for additional information regarding copyright ownership. 6 | * The ASF licenses this file to You under the Apache License, Version 2.0 7 | * (the "License"); you may not use this file except in compliance with 8 | * the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package io.microsphere.convert; 20 | 21 | import static java.lang.Character.valueOf; 22 | 23 | /** 24 | * The {@link Converter} for {@link Number} to {@link Character} 25 | * 26 | * @author Mercy 27 | * @see Converter 28 | * @since 1.0.0 29 | */ 30 | public class NumberToCharacterConverter extends AbstractConverter { 31 | 32 | /** 33 | * Singleton instance of {@link NumberToCharacterConverter}. 34 | */ 35 | public static final NumberToCharacterConverter INSTANCE = new NumberToCharacterConverter(); 36 | 37 | @Override 38 | protected Character doConvert(Number source) { 39 | return valueOf((char) source.intValue()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/NumberToFloatConverter.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Licensed to the Apache Software Foundation (ASF) under one or more 4 | * contributor license agreements. See the NOTICE file distributed with 5 | * this work for additional information regarding copyright ownership. 6 | * The ASF licenses this file to You under the Apache License, Version 2.0 7 | * (the "License"); you may not use this file except in compliance with 8 | * the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package io.microsphere.convert; 20 | 21 | /** 22 | * The {@link Converter} for {@link Number} to {@link Float} 23 | * 24 | * @author Mercy 25 | * @see Converter 26 | * @since 1.0.0 27 | */ 28 | public class NumberToFloatConverter extends AbstractConverter { 29 | 30 | /** 31 | * Singleton instance of {@link NumberToFloatConverter}. 32 | */ 33 | public static final NumberToFloatConverter INSTANCE = new NumberToFloatConverter(); 34 | 35 | @Override 36 | protected Float doConvert(Number source) { 37 | if (source instanceof Float) { 38 | return (Float) source; 39 | } 40 | return source.floatValue(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/NumberToShortConverter.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Licensed to the Apache Software Foundation (ASF) under one or more 4 | * contributor license agreements. See the NOTICE file distributed with 5 | * this work for additional information regarding copyright ownership. 6 | * The ASF licenses this file to You under the Apache License, Version 2.0 7 | * (the "License"); you may not use this file except in compliance with 8 | * the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package io.microsphere.convert; 20 | 21 | /** 22 | * The {@link Converter} for {@link Number} to {@link Short} 23 | * 24 | * @author Mercy 25 | * @see Converter 26 | * @since 1.0.0 27 | */ 28 | public class NumberToShortConverter extends AbstractConverter { 29 | 30 | /** 31 | * Singleton instance of {@link NumberToShortConverter}. 32 | */ 33 | public static final NumberToShortConverter INSTANCE = new NumberToShortConverter(); 34 | 35 | @Override 36 | protected Short doConvert(Number source) { 37 | if (source instanceof Short) { 38 | return (Short) source; 39 | } 40 | return source.shortValue(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/reflect/ConstructorDefinitionTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.reflect; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.List; 6 | 7 | import static io.microsphere.util.ArrayUtils.ofArray; 8 | import static java.util.Collections.singletonList; 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | import static org.junit.jupiter.api.Assertions.assertNotNull; 11 | 12 | /** 13 | * {@link ConstructorDefinition} Test 14 | * 15 | * @author Mercy 16 | * @see ConstructorDefinition 17 | * @since 1.0.0 18 | */ 19 | class ConstructorDefinitionTest extends AbstractExecutableDefinitionTest { 20 | 21 | @Override 22 | protected String getClassName() { 23 | return TestData.class.getName(); 24 | } 25 | 26 | @Override 27 | protected List getTailConstructorArguments() { 28 | return singletonList(ofArray("java.lang.String")); 29 | } 30 | 31 | @Test 32 | void testGetConstructor() { 33 | for (ConstructorDefinition definition : definitions) { 34 | assertNotNull(definition.getConstructor()); 35 | } 36 | } 37 | 38 | @Test 39 | void testNewInstance() { 40 | for (ConstructorDefinition definition : definitions) { 41 | TestData testData = definition.newInstance("test"); 42 | assertEquals("test", testData.name); 43 | } 44 | } 45 | 46 | public static class TestData { 47 | 48 | private String name; 49 | 50 | public TestData(String name) { 51 | this.name = name; 52 | } 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/StringToDurationConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import java.time.Duration; 20 | 21 | import static java.time.Duration.parse; 22 | 23 | /** 24 | * The class to convert {@link String} to {@link Duration} 25 | * 26 | * @author Mercy 27 | * @since 1.0.0 28 | */ 29 | public class StringToDurationConverter extends AbstractConverter implements StringConverter { 30 | 31 | /** 32 | * Singleton instance of {@link StringToDurationConverter}. 33 | */ 34 | public static final StringToDurationConverter INSTANCE = new StringToDurationConverter(); 35 | 36 | @Override 37 | protected Duration doConvert(String source) { 38 | return parse(source); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/io/filter/TrueFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.io.filter; 18 | 19 | import java.io.File; 20 | 21 | /** 22 | * {@link IOFileFilter} implementation always returns true 23 | * 24 | * @author Mercy 25 | * @see IOFileFilter 26 | * @since 1.0.0 27 | */ 28 | public class TrueFileFilter implements IOFileFilter { 29 | 30 | /** 31 | * Singleton instance 32 | */ 33 | public static final TrueFileFilter INSTANCE = new TrueFileFilter(); 34 | 35 | protected TrueFileFilter() { 36 | } 37 | 38 | @Override 39 | public boolean accept(File file) { 40 | return true; 41 | } 42 | 43 | @Override 44 | public boolean accept(File dir, String name) { 45 | return true; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/NumberToDoubleConverter.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Licensed to the Apache Software Foundation (ASF) under one or more 4 | * contributor license agreements. See the NOTICE file distributed with 5 | * this work for additional information regarding copyright ownership. 6 | * The ASF licenses this file to You under the Apache License, Version 2.0 7 | * (the "License"); you may not use this file except in compliance with 8 | * the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package io.microsphere.convert; 20 | 21 | /** 22 | * The {@link Converter} for {@link Number} to {@link Double} 23 | * 24 | * @author Mercy 25 | * @see Converter 26 | * @since 1.0.0 27 | */ 28 | public class NumberToDoubleConverter extends AbstractConverter { 29 | 30 | /** 31 | * Singleton instance of {@link NumberToDoubleConverter}. 32 | */ 33 | public static final NumberToDoubleConverter INSTANCE = new NumberToDoubleConverter(); 34 | 35 | @Override 36 | protected Double doConvert(Number source) { 37 | if (source instanceof Double) { 38 | return (Double) source; 39 | } 40 | return source.doubleValue(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/ObjectToOptionalConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import java.util.Optional; 20 | 21 | import static java.util.Optional.ofNullable; 22 | 23 | /** 24 | * The class to convert {@link Object} to {@link Optional} 25 | * 26 | * @since 1.0.0 27 | */ 28 | public class ObjectToOptionalConverter implements Converter { 29 | 30 | /** 31 | * Singleton instance of {@link ObjectToOptionalConverter}. 32 | */ 33 | public static final ObjectToOptionalConverter INSTANCE = new ObjectToOptionalConverter(); 34 | 35 | @Override 36 | public Optional convert(Object source) { 37 | return ofNullable(source); 38 | } 39 | 40 | @Override 41 | public int getPriority() { 42 | return MIN_PRIORITY; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/resources/META-INF/System.properties: -------------------------------------------------------------------------------- 1 | java.version = Java Runtime Environment version 2 | java.vendor = Java Runtime Environment vendor 3 | java.vendor.url = Java vendor URL 4 | java.home = Java installation directory 5 | java.vm.specification.version = Java Virtual Machine specification version 6 | java.vm.specification.vendor = Java Virtual Machine specification vendor 7 | java.vm.specification.name = Java Virtual Machine specification name 8 | java.vm.version = Java Virtual Machine implementation version 9 | java.vm.vendor = Java Virtual Machine implementation vendor 10 | java.vm.name = Java Virtual Machine implementation name 11 | java.specification.version = Java Runtime Environment specification version 12 | java.specification.vendor = Java Runtime Environment specification vendor 13 | java.specification.name = Java Runtime Environment specification name 14 | java.class.version = Java class format version number 15 | java.class.path = Java class path 16 | java.library.path = List of paths to search when loading libraries 17 | java.io.tmpdir = Default temp file path 18 | java.compiler = Name of JIT compiler to use 19 | java.ext.dirs = Path of extension directory or directories Deprecated. This property, and the mechanism which implements it, may be removed in a future release. 20 | os.name = Operating system name 21 | os.arch = Operating system architecture 22 | os.version = Operating system version 23 | file.separator = File separator ("/" on UNIX) 24 | path.separator = Path separator (":" on UNIX) 25 | line.separator = Line separator ("\\n" on UNIX) 26 | user.name = User's account name 27 | user.home = User's home directory 28 | user.dir = User's current working directory -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/NumberToIntegerConverter.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Licensed to the Apache Software Foundation (ASF) under one or more 4 | * contributor license agreements. See the NOTICE file distributed with 5 | * this work for additional information regarding copyright ownership. 6 | * The ASF licenses this file to You under the Apache License, Version 2.0 7 | * (the "License"); you may not use this file except in compliance with 8 | * the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package io.microsphere.convert; 20 | 21 | /** 22 | * The {@link Converter} for {@link Number} to {@link Integer} 23 | * 24 | * @author Mercy 25 | * @see Converter 26 | * @since 1.0.0 27 | */ 28 | public class NumberToIntegerConverter extends AbstractConverter { 29 | 30 | /** 31 | * Singleton instance of {@link NumberToIntegerConverter}. 32 | */ 33 | public static final NumberToIntegerConverter INSTANCE = new NumberToIntegerConverter(); 34 | 35 | @Override 36 | protected Integer doConvert(Number source) { 37 | if (source instanceof Integer) { 38 | return (Integer) source; 39 | } 40 | return source.intValue(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/classloading/ClassicURLClassPathHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.classloading; 18 | 19 | /** 20 | * Classic {@link URLClassPathHandle} for {@link sun.misc.URLClassPath} since JDK 1 to 8 21 | * 22 | * @author Mercy 23 | * @see sun.misc.URLClassPath 24 | * @see ModernURLClassPathHandle 25 | * @see URLClassPathHandle 26 | * @since 1.0.0 27 | */ 28 | public class ClassicURLClassPathHandle extends AbstractURLClassPathHandle { 29 | 30 | public ClassicURLClassPathHandle() { 31 | super(); 32 | } 33 | 34 | @Override 35 | protected String getURLClassPathClassName() { 36 | return "sun.misc.URLClassPath"; 37 | } 38 | 39 | @Override 40 | protected String getUrlsFieldName() { 41 | return "urls"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/classloading/NoOpURLClassPathHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.classloading; 18 | 19 | import java.net.URL; 20 | 21 | import static io.microsphere.net.URLUtils.EMPTY_URL_ARRAY; 22 | 23 | /** 24 | * No-Operation {@link URLClassPathHandle} 25 | * 26 | * @author Mercy 27 | * @see URLClassPathHandle 28 | * @since 1.0.0 29 | */ 30 | public class NoOpURLClassPathHandle implements URLClassPathHandle { 31 | 32 | @Override 33 | public boolean supports() { 34 | return true; 35 | } 36 | 37 | @Override 38 | public URL[] getURLs(ClassLoader classLoader) { 39 | return EMPTY_URL_ARRAY; 40 | } 41 | 42 | @Override 43 | public boolean removeURL(ClassLoader classLoader, URL url) { 44 | return false; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/util/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.util; 18 | 19 | /** 20 | * A marker interface serving as a base for utility classes within the MicroSphere framework. 21 | *

22 | * This interface is intended to be extended by utility classes that provide static methods 23 | * for common operations. It helps in organizing utility classes under a common type hierarchy. 24 | *

25 | * 26 | *

Example Usage

27 | *
28 |  * public final class MyUtils implements Utils {
29 |  *     private MyUtils() {}
30 |  *
31 |  *     public static void doSomething() {
32 |  *         // Utility logic here
33 |  *     }
34 |  * }
35 |  * 
36 | * 37 | * @author
Mercy 38 | * @see BaseUtils 39 | * @since 1.0.0 40 | */ 41 | public interface Utils { 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToMultiValueConverterTest.java: -------------------------------------------------------------------------------- 1 | package io.microsphere.convert.multiple; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static io.microsphere.util.ArrayUtils.EMPTY_STRING_ARRAY; 7 | import static io.microsphere.util.ArrayUtils.ofArray; 8 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; 9 | 10 | /** 11 | * {@link StringToMultiValueConverter} Test 12 | * 13 | * @author Mercy 14 | * @see StringToMultiValueConverter 15 | * @since 16 | */ 17 | class StringToMultiValueConverterTest { 18 | 19 | private StringToMultiValueConverter converter; 20 | 21 | @BeforeEach 22 | void setUp() { 23 | converter = new StringToMultiValueConverter() { 24 | @Override 25 | public boolean accept(Class sourceType, Class multiValueType) { 26 | return false; 27 | } 28 | 29 | @Override 30 | public Object convert(String[] segments, int size, Class targetType, Class elementType) { 31 | return segments; 32 | } 33 | }; 34 | } 35 | 36 | @Test 37 | void testConvert() { 38 | String source = ""; 39 | assertArrayEquals(EMPTY_STRING_ARRAY, (String[]) converter.convert(source, null, null)); 40 | 41 | source = "a,b,c"; 42 | assertArrayEquals(ofArray("a", "b", "c"), (String[]) converter.convert(source, null, null)); 43 | } 44 | 45 | @Test 46 | void testConvertOnNull() { 47 | assertArrayEquals(null, (String[]) converter.convert(null, null, null)); 48 | } 49 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/event/ParallelEventDispatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.event; 18 | 19 | import java.util.concurrent.Executor; 20 | import java.util.concurrent.ForkJoinPool; 21 | 22 | import static java.util.concurrent.ForkJoinPool.commonPool; 23 | 24 | /** 25 | * Parallel {@link EventDispatcher} implementation. 26 | *

27 | * The default constructor uses {@link ForkJoinPool#commonPool() JDK common thread pool}. 28 | * 29 | * @author Mercy 30 | * @see ForkJoinPool#commonPool() 31 | * @since 1.0.0 32 | */ 33 | public class ParallelEventDispatcher extends AbstractEventDispatcher { 34 | 35 | public ParallelEventDispatcher() { 36 | this(commonPool()); 37 | } 38 | 39 | public ParallelEventDispatcher(Executor executor) { 40 | super(executor); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/convert/StringToClassConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import static io.microsphere.convert.StringToClassConverter.INSTANCE; 20 | 21 | /** 22 | * {@link StringToClassConverter} Test 23 | * 24 | * @author Mercy 25 | * @since 1.0.0 26 | */ 27 | class StringToClassConverterTest extends BaseConverterTest { 28 | 29 | @Override 30 | protected AbstractConverter createConverter() { 31 | return INSTANCE; 32 | } 33 | 34 | @Override 35 | protected String getSource() throws Throwable { 36 | return "io.microsphere.convert.StringToClassConverter"; 37 | } 38 | 39 | @Override 40 | protected Class getTarget() throws Throwable { 41 | return StringToClassConverter.class; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/classloading/ModernURLClassPathHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.classloading; 18 | 19 | /** 20 | * Modern {@link URLClassPathHandle} for {@link jdk.internal.loader.URLClassPath} since JDK 9 21 | * 22 | * @author Mercy 23 | * @see jdk.internal.loader.URLClassPath 24 | * @see ClassicURLClassPathHandle 25 | * @see URLClassPathHandle 26 | * @since 1.0.0 27 | */ 28 | public class ModernURLClassPathHandle extends AbstractURLClassPathHandle { 29 | 30 | public ModernURLClassPathHandle() { 31 | super(); 32 | } 33 | 34 | @Override 35 | protected String getURLClassPathClassName() { 36 | return "jdk.internal.loader.URLClassPath"; 37 | } 38 | 39 | @Override 40 | protected String getUrlsFieldName() { 41 | return "unopenedUrls"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/metadata/DefaultConfigurationPropertyLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.microsphere.metadata; 19 | 20 | import io.microsphere.beans.ConfigurationProperty; 21 | 22 | import java.util.List; 23 | 24 | import static io.microsphere.collection.Lists.ofList; 25 | import static io.microsphere.constants.PropertyConstants.MICROSPHERE_PROPERTY_NAME_PREFIX; 26 | 27 | /** 28 | * Default {@link ConfigurationPropertyLoader} 29 | * 30 | * @author Mercy 31 | * @see ConfigurationPropertyLoader 32 | * @since 1.0.0 33 | */ 34 | public class DefaultConfigurationPropertyLoader implements ConfigurationPropertyLoader { 35 | @Override 36 | public List load() throws Throwable { 37 | return ofList(new ConfigurationProperty(MICROSPHERE_PROPERTY_NAME_PREFIX + "test")); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/event/EventListenerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.event; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static io.microsphere.event.EventListener.findEventType; 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | 24 | 25 | /** 26 | * {@link EventListener} Test 27 | * 28 | * @since 1.0.0 29 | */ 30 | class EventListenerTest { 31 | 32 | @Test 33 | void testFindEventHierarchicalTypes() { 34 | assertEquals(EchoEvent.class, findEventType(new EchoEventListener())); 35 | assertEquals(Event.class, findEventType(new EchoEventListener2())); 36 | 37 | assertEquals(EchoEvent.class, findEventType(EchoEventListener.class)); 38 | assertEquals(Event.class, findEventType(EchoEventListener2.class)); 39 | } 40 | 41 | @Test 42 | void testOnEvent() { 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/filter/FilterUtilsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package io.microsphere.filter; 5 | 6 | import io.microsphere.AbstractTestCase; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import java.util.List; 10 | 11 | import static java.util.Arrays.asList; 12 | import static org.junit.jupiter.api.Assertions.assertEquals; 13 | 14 | /** 15 | * {@link FilterUtils} Test Case 16 | * 17 | * @author Mercy 18 | * @see FilterUtilsTest 19 | * @since 1.0.0 20 | */ 21 | class FilterUtilsTest extends AbstractTestCase { 22 | 23 | @Test 24 | void testFilter() { 25 | List integerList = asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); 26 | 27 | List result = FilterUtils.filter(integerList, FilterOperator.AND, new Filter() { 28 | @Override 29 | public boolean accept(Integer filteredObject) { 30 | return filteredObject % 2 == 0; 31 | } 32 | }); 33 | 34 | assertEquals(asList(0, 2, 4, 6, 8), result); 35 | 36 | result = FilterUtils.filter(integerList, new Filter() { 37 | @Override 38 | public boolean accept(Integer filteredObject) { 39 | return filteredObject % 2 == 0; 40 | } 41 | }); 42 | 43 | assertEquals(asList(0, 2, 4, 6, 8), result); 44 | 45 | result = FilterUtils.filter(integerList, FilterOperator.OR, new Filter() { 46 | @Override 47 | public boolean accept(Integer filteredObject) { 48 | return filteredObject % 2 == 1; 49 | } 50 | }); 51 | 52 | assertEquals(asList(1, 3, 5, 7, 9), result); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/ObjectToByteArrayConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import io.microsphere.io.DefaultSerializer; 20 | 21 | import java.io.Serializable; 22 | 23 | /** 24 | * The class coverts the {@link Object} instance to be {@link byte[] byte array} object. 25 | * 26 | * @author Mercy 27 | * @see Serializable 28 | * @since 1.0.0 29 | */ 30 | public class ObjectToByteArrayConverter extends AbstractConverter { 31 | 32 | /** 33 | * Singleton instance of {@link ObjectToByteArrayConverter} 34 | */ 35 | public static final ObjectToByteArrayConverter INSTANCE = new ObjectToByteArrayConverter(); 36 | 37 | @Override 38 | protected byte[] doConvert(Object source) throws Throwable { 39 | return DefaultSerializer.INSTANCE.serialize(source); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/model/CollectionTypeModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.annotation.processor.model; 18 | 19 | import java.util.Collection; 20 | import java.util.Deque; 21 | import java.util.List; 22 | import java.util.Queue; 23 | import java.util.Set; 24 | 25 | /** 26 | * {@link Collection} Type Model 27 | * 28 | * @since 1.0.0 29 | */ 30 | public class CollectionTypeModel { 31 | 32 | private Collection strings; // The composite element is simple type 33 | 34 | private List colors; // The composite element is Enum type 35 | 36 | private Queue primitiveTypeModels; // The composite element is POJO type 37 | 38 | private Deque models; // The composite element is hierarchical POJO type 39 | 40 | private Set modelArrays; // The composite element is hierarchical POJO type 41 | 42 | } 43 | -------------------------------------------------------------------------------- /microsphere-java-core/src/main/java/io/microsphere/convert/PropertiesToStringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.convert; 18 | 19 | import java.io.StringWriter; 20 | import java.util.Properties; 21 | 22 | /** 23 | * The {@link Properties} To {@link String} {@link Converter} 24 | * 25 | * @author Mercy 26 | * @since 1.0.0 27 | */ 28 | public class PropertiesToStringConverter extends AbstractConverter { 29 | 30 | /** 31 | * Singleton instance of {@link PropertiesToStringConverter}. 32 | */ 33 | public static final PropertiesToStringConverter INSTANCE = new PropertiesToStringConverter(); 34 | 35 | @Override 36 | protected String doConvert(Properties source) throws Throwable { 37 | StringWriter writer = new StringWriter(); 38 | source.store(writer, "Generated by Microsphere"); 39 | return writer.toString(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/model/Parent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.annotation.processor.model; 18 | 19 | /** 20 | * Parent 21 | */ 22 | public class Parent extends Ancestor { 23 | 24 | private byte b; 25 | 26 | private short s; 27 | 28 | private int i; 29 | 30 | private long l; 31 | 32 | public byte getB() { 33 | return b; 34 | } 35 | 36 | public void setB(byte b) { 37 | this.b = b; 38 | } 39 | 40 | public short getS() { 41 | return s; 42 | } 43 | 44 | public void setS(short s) { 45 | this.s = s; 46 | } 47 | 48 | public int getI() { 49 | return i; 50 | } 51 | 52 | public void setI(int i) { 53 | this.i = i; 54 | } 55 | 56 | public long getL() { 57 | return l; 58 | } 59 | 60 | public void setL(long l) { 61 | this.l = l; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /microsphere-java-core/src/test/java/io/microsphere/util/CompatibleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.microsphere.util; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static io.microsphere.util.Compatible.of; 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | 24 | /** 25 | * {@link Compatible} Test 26 | * 27 | * @author Mercy 28 | * @since 1.0.0 29 | */ 30 | class CompatibleTest { 31 | 32 | private Compatible compatible = of(Test.class) 33 | .on("<", "4.13", version -> "<") 34 | .on("=", "4.13", version -> "=") 35 | .on(">", "4.2", version -> ">") 36 | .on(">=", "4.13.2", version -> ">="); 37 | 38 | @Test 39 | void testGet() { 40 | assertEquals(">=", compatible.get()); 41 | } 42 | 43 | @Test 44 | void testAccept() { 45 | compatible.accept(r -> assertEquals(">=", r)); 46 | } 47 | } 48 | --------------------------------------------------------------------------------