├── .github └── workflows │ └── maven.yml ├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── RELEASE-NOTES.md ├── pom.xml ├── src ├── main │ ├── java │ │ └── org │ │ │ └── meanbean │ │ │ ├── bean │ │ │ ├── info │ │ │ │ ├── BeanInformation.java │ │ │ │ ├── BeanInformationException.java │ │ │ │ ├── BeanInformationFactory.java │ │ │ │ ├── JavaBeanInformation.java │ │ │ │ ├── JavaBeanInformationFactory.java │ │ │ │ ├── PropertyDescriptorPropertyInformation.java │ │ │ │ └── PropertyInformation.java │ │ │ └── util │ │ │ │ ├── BasicBeanPopulator.java │ │ │ │ ├── BeanPopulationException.java │ │ │ │ ├── BeanPopulator.java │ │ │ │ ├── BeanPropertyValuesFactory.java │ │ │ │ └── PropertyInformationFilter.java │ │ │ ├── factories │ │ │ ├── ArrayFactoryLookup.java │ │ │ ├── BasicNewObjectInstanceFactory.java │ │ │ ├── CollectionFactoryLookup.java │ │ │ ├── ConcurrentFactoryPlugin.java │ │ │ ├── FactoryCollection.java │ │ │ ├── FactoryCollectionPlugin.java │ │ │ ├── FactoryCollectionRepository.java │ │ │ ├── FactoryLookup.java │ │ │ ├── FactoryRepository.java │ │ │ ├── NoSuchFactoryException.java │ │ │ ├── ObjectCreationException.java │ │ │ ├── ObjectFactoryPlugin.java │ │ │ ├── OptionalFactoryLookup.java │ │ │ ├── PrimitiveFactoryPlugin.java │ │ │ ├── basic │ │ │ │ ├── BigDecimalFactory.java │ │ │ │ ├── BigIntegerFactory.java │ │ │ │ ├── BooleanFactory.java │ │ │ │ ├── ByteFactory.java │ │ │ │ ├── CharacterFactory.java │ │ │ │ ├── DateFactory.java │ │ │ │ ├── DoubleFactory.java │ │ │ │ ├── EnumFactory.java │ │ │ │ ├── EnumFactoryLookup.java │ │ │ │ ├── FloatFactory.java │ │ │ │ ├── IntegerFactory.java │ │ │ │ ├── LongFactory.java │ │ │ │ ├── RandomFactoryBase.java │ │ │ │ ├── ShortFactory.java │ │ │ │ └── StringFactory.java │ │ │ ├── beans │ │ │ │ ├── BeanCreationException.java │ │ │ │ └── PopulatedBeanFactory.java │ │ │ ├── equivalent │ │ │ │ ├── EquivalentEnumFactory.java │ │ │ │ └── EquivalentPopulatedBeanFactory.java │ │ │ ├── io │ │ │ │ └── FileFactory.java │ │ │ ├── net │ │ │ │ ├── NetFactoryPlugin.java │ │ │ │ └── UrlFactory.java │ │ │ ├── time │ │ │ │ ├── RandomClock.java │ │ │ │ └── TimePlugin.java │ │ │ └── util │ │ │ │ ├── BasicFactoryLookupStrategy.java │ │ │ │ ├── FactoryLookupStrategy.java │ │ │ │ └── LocaleFactory.java │ │ │ ├── lang │ │ │ ├── EquivalentFactory.java │ │ │ └── Factory.java │ │ │ ├── logging │ │ │ ├── $Logger.java │ │ │ └── $LoggerFactory.java │ │ │ ├── test │ │ │ ├── BeanPropertyTester.java │ │ │ ├── BeanTestException.java │ │ │ ├── BeanTester.java │ │ │ ├── BeanTesterBuilder.java │ │ │ ├── BeanVerifier.java │ │ │ ├── BeanVerifierImpl.java │ │ │ ├── Configuration.java │ │ │ ├── ConfigurationBuilder.java │ │ │ ├── EqualsMethodContractVerifier.java │ │ │ ├── EqualsMethodPropertySignificanceVerifier.java │ │ │ ├── EqualsMethodTester.java │ │ │ ├── HashCodeMethodTester.java │ │ │ ├── InsignificantObjectPropertyEqualityConsistentAsserter.java │ │ │ ├── ObjectPropertyEqualityConsistentAsserter.java │ │ │ ├── PropertyBasedEqualsMethodPropertySignificanceVerifier.java │ │ │ ├── SignificantObjectPropertyEqualityConsistentAsserter.java │ │ │ ├── ToStringMethodTester.java │ │ │ ├── VerifierSettings.java │ │ │ ├── VerifierSettingsEditor.java │ │ │ ├── Warning.java │ │ │ └── internal │ │ │ │ ├── $EqualsBuilder.java │ │ │ │ ├── EqualityTest.java │ │ │ │ ├── NoopSideEffectDetector.java │ │ │ │ ├── SideEffectDetector.java │ │ │ │ ├── SideEffectDetectorFactory.java │ │ │ │ └── SideEffectDetectorImpl.java │ │ │ └── util │ │ │ ├── AssertionUtils.java │ │ │ ├── ClassPath.java │ │ │ ├── ClassPathUtils.java │ │ │ ├── Order.java │ │ │ ├── PropertyNameFinder.java │ │ │ ├── RandomValueGenerator.java │ │ │ ├── RandomValueSampler.java │ │ │ ├── ServiceDefinition.java │ │ │ ├── ServiceFactory.java │ │ │ ├── ServiceLoader.java │ │ │ ├── SimpleRandomValueGenerator.java │ │ │ ├── Types.java │ │ │ ├── ValidationHelper.java │ │ │ └── reflect │ │ │ ├── JavaVersion.java │ │ │ ├── PreJava9ReflectionAccessor.java │ │ │ ├── ReflectionAccessor.java │ │ │ └── UnsafeReflectionAccessor.java │ └── javadoc │ │ └── overview.html └── test │ ├── java │ └── org │ │ └── meanbean │ │ ├── bean │ │ ├── info │ │ │ ├── BeanInformationExceptionTest.java │ │ │ ├── JavaBeanInformationFactoryTest.java │ │ │ ├── JavaBeanInformationTest.java │ │ │ ├── PropertyDescriptorPropertyInformationTest.java │ │ │ ├── PropertyInformationBean.java │ │ │ └── PropertyInformationFactory.java │ │ └── util │ │ │ ├── BasicBeanPopulatorTest.java │ │ │ ├── BeanPopulationExceptionTest.java │ │ │ ├── BeanPropertyValuesFactoryTest.java │ │ │ └── PropertyInformationFilterTest.java │ │ ├── factories │ │ ├── ArrayFactoryLookupTest.java │ │ ├── BasicNewObjectInstanceFactoryTest.java │ │ ├── CollectionFactoryLookupTest.java │ │ ├── ConcurrentFactoryPluginTest.java │ │ ├── FactoryRepositoryTest.java │ │ ├── NoSuchFactoryExceptionTest.java │ │ ├── ObjectCreationExceptionTest.java │ │ ├── ObjectFactoryPluginTest.java │ │ ├── PrimitiveFactoryPluginTest.java │ │ ├── SimpleFactoryCollection.java │ │ ├── basic │ │ │ ├── ArrayBasedRandomValueGenerator.java │ │ │ ├── BasicFactoryTestBase.java │ │ │ ├── BigDecimalFactoryTest.java │ │ │ ├── BigIntegerFactoryTest.java │ │ │ ├── BooleanFactoryTest.java │ │ │ ├── ByteFactoryTest.java │ │ │ ├── CharacterFactoryTest.java │ │ │ ├── DateFactoryTest.java │ │ │ ├── DoubleFactoryTest.java │ │ │ ├── EnumFactoryTest.java │ │ │ ├── FloatFactoryTest.java │ │ │ ├── IntegerFactoryTest.java │ │ │ ├── LongFactoryTest.java │ │ │ ├── RandomFactoryBaseTest.java │ │ │ ├── ShortFactoryTest.java │ │ │ └── StringFactoryTest.java │ │ ├── beans │ │ │ ├── BeanCreationExceptionTest.java │ │ │ └── EquivalentPopulatedBeanFactoryTest.java │ │ ├── net │ │ │ └── NetFactoryPluginTest.java │ │ └── time │ │ │ ├── ConcurrentFactoryPluginTest.java │ │ │ └── RandomClockTest.java │ │ ├── test │ │ ├── BasicBeanTesterDomainTest.java │ │ ├── BasicFactoryLookupStrategyTest.java │ │ ├── BeanPropertyTesterTest.java │ │ ├── BeanTestExceptionTest.java │ │ ├── BeanTesterDualWritingBeanTest.java │ │ ├── BeanTesterTest.java │ │ ├── BeanVerifierTest.java │ │ ├── ConfigurationBuilderFactory.java │ │ ├── ConfigurationBuilderTest.java │ │ ├── ConfigurationTest.java │ │ ├── EqualityTestTest.java │ │ ├── EqualsMethodContractVerifierTest.java │ │ ├── EqualsMethodTesterDomainTest.java │ │ ├── EqualsMethodTesterTest.java │ │ ├── HashCodeMethodTesterTest.java │ │ ├── InsignificantObjectPropertyEqualityConsistentAsserterTest.java │ │ ├── OptionalPropertyBeanTest.java │ │ ├── PropertyBasedEqualsMethodPropertySignificanceVerifierTest.java │ │ ├── SignificantObjectPropertyEqualityConsistentAsserterTest.java │ │ ├── ToStringMethodTesterTest.java │ │ ├── beans │ │ │ ├── ArrayPropertyBean.java │ │ │ ├── ArrayPropertyBeanWithConstructor.java │ │ │ ├── Bean.java │ │ │ ├── BeanFactory.java │ │ │ ├── BeanWithBadGetterMethod.java │ │ │ ├── BeanWithBadSetterMethod.java │ │ │ ├── BeanWithNonBeanProperty.java │ │ │ ├── BrokenEqualsMultiPropertyBean.java │ │ │ ├── ClassIncrementalHashCodeBean.java │ │ │ ├── CollectionPropertyBean.java │ │ │ ├── ComplexBean.java │ │ │ ├── ComplexBeanFactory.java │ │ │ ├── CounterDrivenEqualsBean.java │ │ │ ├── CounterDrivenEqualsBeanFactory.java │ │ │ ├── CounterDrivenHashCodeBean.java │ │ │ ├── DifferentTypeAcceptingBean.java │ │ │ ├── DifferentTypeAcceptingBeanFactory.java │ │ │ ├── FieldDrivenEqualsBean.java │ │ │ ├── FieldDrivenEqualsBeanFactory.java │ │ │ ├── FieldDrivenHashCodeBean.java │ │ │ ├── FluentPropertyBean.java │ │ │ ├── FluentPropertyBeanTest.java │ │ │ ├── IncrementalStringFactory.java │ │ │ ├── InstanceIncrementalHashCodeBean.java │ │ │ ├── InvocationCountingFactoryWrapper.java │ │ │ ├── MultiPropertyBean.java │ │ │ ├── MultiPropertyBeanFactory.java │ │ │ ├── NonBean.java │ │ │ ├── NonEqualBean.java │ │ │ ├── NonReflexiveBean.java │ │ │ ├── NonReflexiveBeanFactory.java │ │ │ ├── NullAcceptingBean.java │ │ │ ├── NullAcceptingBeanFactory.java │ │ │ ├── NullEquivalentFactory.java │ │ │ ├── NullFactory.java │ │ │ ├── PackagePrivateConstructorObject.java │ │ │ ├── PrivateConstructorObject.java │ │ │ ├── SelfReferencingBean.java │ │ │ ├── SelfReferencingBeanFactory.java │ │ │ ├── domain │ │ │ │ ├── Address.java │ │ │ │ ├── Company.java │ │ │ │ ├── Country.java │ │ │ │ ├── County.java │ │ │ │ ├── Customer.java │ │ │ │ ├── Employee.java │ │ │ │ ├── EmployeeId.java │ │ │ │ ├── EmployeeWithBrokenManagerSetter.java │ │ │ │ ├── Item.java │ │ │ │ ├── Money.java │ │ │ │ ├── NonReflexiveEqualsAddress.java │ │ │ │ ├── Order.java │ │ │ │ ├── Person.java │ │ │ │ ├── Product.java │ │ │ │ ├── Rating.java │ │ │ │ ├── Review.java │ │ │ │ ├── ShippingCompany.java │ │ │ │ └── Status.java │ │ │ └── scan │ │ │ │ └── ScanBean.java │ │ ├── internal │ │ │ └── EqualsBuilderTest.java │ │ └── util │ │ │ └── MessageAndCauseExceptionTestBase.java │ │ └── util │ │ ├── AssertionUtilsTest.java │ │ ├── RandomValueSamplerTest.java │ │ ├── ServiceFactoryTest.java │ │ └── SimpleRandomValueGeneratorTest.java │ └── resources │ └── log4j2.xml └── statics ├── css └── stylesheet.css └── docs ├── meanbean_bean_logo.png ├── meanbean_lightbrown_bean_logo.png ├── meanbean_logo_withbackground.png └── meanbeanlogo.png /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | strategy: 11 | matrix: 12 | java: [ 1.8, 11 ] 13 | name: Java ${{ matrix.java }} 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Set up JDK 18 | uses: actions/setup-java@v1 19 | with: 20 | java-version: ${{ matrix.java }} 21 | - name: Build with Maven 22 | run: mvn -B package --file pom.xml 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | 3 | *.java.hsp 4 | *.sonarj 5 | *.sw* 6 | .DS_Store 7 | .settings 8 | .springBeans 9 | bin 10 | build.sh 11 | ivy-cache 12 | jxl.log 13 | jmx.log 14 | derby.log 15 | .gradle 16 | 17 | classes/ 18 | /build 19 | 20 | # Eclipse artifacts, including WTP generated manifests 21 | .classpath 22 | .project 23 | */src/main/java/META-INF/MANIFEST.MF 24 | .factorypath 25 | 26 | # IDEA artifacts and output dirs 27 | *.iml 28 | *.ipr 29 | *.iws 30 | .idea 31 | out 32 | test-output 33 | .gradletasknamecache 34 | 35 | /.apt_generated/ 36 | /.apt_generated_tests/ 37 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | This notice is provided with respect to tinylog. 2 | 3 | --- begin of LICENSE --- 4 | Copyright 2016-2020 Martin Winandy 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the 7 | 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 distributed under the License is distributed on an 12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 13 | language governing permissions and limitations under the License. 14 | 15 | --- end of LICENSE --- 16 | 17 | ------------------------------------------------------------------------------- 18 | 19 | This notice is provided with respect to spring-framework. 20 | 21 | --- begin of LICENSE --- 22 | 23 | Copyright 2002-2017 the original author or authors. 24 | 25 | Licensed under the Apache License, Version 2.0 (the "License"); 26 | you may not use this file except in compliance with the License. 27 | You may obtain a copy of the License at 28 | 29 | https://www.apache.org/licenses/LICENSE-2.0 30 | 31 | Unless required by applicable law or agreed to in writing, software 32 | distributed under the License is distributed on an "AS IS" BASIS, 33 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 34 | See the License for the specific language governing permissions and 35 | limitations under the License. 36 | 37 | --- end of LICENSE --- 38 | 39 | ------------------------------------------------------------------------------- 40 | 41 | This notice is provided with respect to gson. 42 | 43 | --- begin of LICENSE --- 44 | 45 | Copyright 2008 Google Inc. 46 | 47 | Licensed under the Apache License, Version 2.0 (the "License"); 48 | you may not use this file except in compliance with the License. 49 | You may obtain a copy of the License at 50 | 51 | http://www.apache.org/licenses/LICENSE-2.0 52 | 53 | Unless required by applicable law or agreed to in writing, software 54 | distributed under the License is distributed on an "AS IS" BASIS, 55 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 56 | See the License for the specific language governing permissions and 57 | limitations under the License. 58 | 59 | --- end of LICENSE --- 60 | 61 | ------------------------------------------------------------------------------- 62 | 63 | -------------------------------------------------------------------------------- /RELEASE-NOTES.md: -------------------------------------------------------------------------------- 1 | # MeanBean Release Notes 2 | 3 | ## 3.0.0-M9 4 | - Fix toString, equals and hashCode verifications to honor custom configuration. #15 5 | 6 | ## 3.0.0-M8 7 | - Detect and enable testing for beans with fluent setters. 8 | - Fix factory caching that causes failures when chaining bean verifier calls. #8 9 | - Fix equals test sometimes failing on array properties. #7 10 | 11 | ## 3.0.0-M7 12 | - Fix bug not being able to test Collection with Enum element types. #4 13 | 14 | ## 3.0.0-M6 15 | - Rename BeanVerification to BeanVerifier 16 | - Add mechanism for suppressing warnings. 17 | - Detect setter methods that have side-effects on other properties. e.g. a setter method that writes to two properties 18 | Use Warning.SETTER_SIDE_EFFECT to disable detection and resulting failure. 19 | - Add support for Optional, OptionalInt/Long/Double 20 | - Add ability to suppress warning about dynamically created factory logging 21 | - Build and test meanbean with Java 1.8 and 11 22 | 23 | ## 3.0.0-M5 24 | - Fix bug running meanbean in Java 11 due to ConcurrentHashMap changes 25 | 26 | ## 3.0.0-M4 27 | - Add BeanVerification interface to replace BeanVerifications class 28 | 29 | ## 3.0.0-M3 30 | - Import Guava ClassPath for scanning classpath. Users can test all beans in a given package. 31 | - Add BeanVerifications for fluent assertions 32 | - Add simple toString method tester 33 | - Fix bug in File/Path factory 34 | 35 | 36 | ## 3.0.0-M2 37 | 38 | This is the first public release of meanbean v3. Maven groupId is now com.github.meanbeanlib and Java 8 is required. 39 | 40 | Changes: 41 | - Do not repeatedly warn about "dynamically created factory" 42 | - Add BeanTesterBuilder for customizing BeanTester 43 | - Add custom logger that delegates to slf4j or log4j2 if possible 44 | - Add ServiceLoader mechanism for creating implementation instances of interfaces. Users may take advantage of that to 45 | override default meanbean implementations. 46 | - Add support for Array/Collection/Map of arbitrary element types and dimension. Previously the element type was always 47 | String and dimension was one. Support for more Collection/Map instance types. 48 | - Add FactoryLookup interface for dynamically defining Factory at runtime. 49 | - Add ability to register Factory for a type hierarchy 50 | - Log warning if a property defines URL which requires .equals test that may be slow. 51 | - Allow method references as property specifiers. (e.g. User::getName vs "Name") 52 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/bean/info/BeanInformation.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.bean.info; 22 | 23 | import java.util.Collection; 24 | 25 | /** 26 | * Defines an object that provides information about a JavaBean. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public interface BeanInformation { 31 | 32 | /** 33 | * Get the type of bean this object contains information about. 34 | * 35 | * @return The type of bean this object contains information about. 36 | */ 37 | Class getBeanClass(); 38 | 39 | /** 40 | * Get the names of all properties of the bean. 41 | * 42 | * @return A Collection of names of all properties of the bean. 43 | */ 44 | Collection getPropertyNames(); 45 | 46 | /** 47 | * Get information about all properties of the bean. 48 | * 49 | * @return A Collection of all properties of the bean. 50 | */ 51 | Collection getProperties(); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/bean/info/BeanInformationException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.bean.info; 22 | 23 | /** 24 | * An exception that may be thrown when trying to gather JavaBean-related information on a type. This may be because the 25 | * type is not a valid JavaBean or because an unexpected error occurred when gathering the information. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class BeanInformationException extends RuntimeException { 30 | 31 | /** Unique version ID of this Serializable class. */ 32 | private static final long serialVersionUID = 1L; 33 | 34 | /** 35 | * Construct a new Bean Information Exception with the specified message and cause. 36 | * 37 | * @param message 38 | * A human-readable String message describing the problem that occurred. 39 | * @param cause 40 | * The cause of the exception. 41 | */ 42 | public BeanInformationException(String message, Throwable cause) { 43 | super(message, cause); 44 | } 45 | 46 | /** 47 | * Construct a new Bean Information Exception with the specified message. 48 | * 49 | * @param message 50 | * A human-readable String message describing the problem that occurred. 51 | */ 52 | public BeanInformationException(String message) { 53 | super(message); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/bean/info/BeanInformationFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.bean.info; 22 | 23 | import org.meanbean.util.ServiceDefinition; 24 | 25 | /** 26 | * Defines an object that creates BeanInformation objects. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public interface BeanInformationFactory { 31 | 32 | /** 33 | * Create a BeanInformation object from/based on the specified beanClass. 34 | * 35 | * @param beanClass 36 | * The type of the object the BeanInformation information should be about. 37 | * 38 | * @return Information about the specified type, encapsulated in a BeanInformation object. 39 | * 40 | * @throws IllegalArgumentException 41 | * If the beanClass is deemed illegal. For example, if it is null. 42 | * @throws BeanInformationException 43 | * If a problem occurs when creating BeanInformation about the specified type. This may be because the 44 | * specified type is not a valid JavaBean, or perhaps because an unexpected exception occurred when 45 | * trying to gather information about the type. 46 | */ 47 | BeanInformation create(Class beanClass) throws IllegalArgumentException, BeanInformationException; 48 | 49 | public static ServiceDefinition getServiceDefinition() { 50 | return new ServiceDefinition<>(BeanInformationFactory.class); 51 | } 52 | 53 | public static BeanInformationFactory getInstance() { 54 | return getServiceDefinition().getServiceFactory() 55 | .getFirst(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/bean/info/JavaBeanInformationFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.bean.info; 22 | 23 | import org.kohsuke.MetaInfServices; 24 | 25 | /** 26 | * Concrete BeanInformationFactory that creates concrete JavaBeanInformation objects from/based on a specified 27 | * beanClass. 28 | * 29 | * @author Graham Williamson 30 | */ 31 | @MetaInfServices 32 | public class JavaBeanInformationFactory implements BeanInformationFactory { 33 | 34 | /** 35 | * Create a BeanInformation object from/based on the specified beanClass. 36 | * 37 | * @param beanClass 38 | * The type of the object the BeanInformation information should be about. 39 | * 40 | * @return Information about the specified type, encapsulated in a BeanInformation object. 41 | * 42 | * @throws IllegalArgumentException 43 | * If the beanClass is deemed illegal. For example, if it is null. 44 | * @throws BeanInformationException 45 | * If a problem occurs when creating BeanInformation about the specified type. This may be because the 46 | * specified type is not a valid JavaBean, or perhaps because an unexpected exception occurred when 47 | * trying to gather information about the type. 48 | */ 49 | @Override 50 | public BeanInformation create(Class beanClass) throws IllegalArgumentException, BeanInformationException { 51 | return new JavaBeanInformation(beanClass); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/bean/util/BeanPopulationException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.bean.util; 22 | 23 | /** 24 | * An exception that may be thrown when trying to populate the fields of a JavaBean. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public class BeanPopulationException extends RuntimeException { 29 | 30 | /** Unique version ID of this Serializable class. */ 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * Construct a new Bean Population Exception with the specified message and cause. 35 | * 36 | * @param message 37 | * A human-readable String message describing the problem that occurred. 38 | * @param cause 39 | * The cause of the exception. 40 | */ 41 | public BeanPopulationException(String message, Throwable cause) { 42 | super(message, cause); 43 | } 44 | 45 | /** 46 | * Construct a new Bean Population Exception with the specified message. 47 | * 48 | * @param message 49 | * A human-readable String message describing the problem that occurred. 50 | */ 51 | public BeanPopulationException(String message) { 52 | super(message); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/bean/util/BeanPopulator.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.bean.util; 22 | 23 | import java.util.Map; 24 | 25 | import org.meanbean.bean.info.BeanInformation; 26 | 27 | /** 28 | * Defines an object that affords functionality to populate a bean (set its fields) with specified values. 29 | * 30 | * @author Graham Williamson 31 | */ 32 | public interface BeanPopulator { 33 | 34 | /** 35 | * Populate the specified bean with the specified values. Values are keyed by property name (e.g. "firstName") and 36 | * are matched to properties on the bean and their setters (e.g. "setFirstName"). Only properties with a setter 37 | * method and an entry in the values map will be set. Any entries in the values map that do not exist on the bean 38 | * are ignored. 39 | * 40 | * @param bean 41 | * The object to populate. 42 | * @param beanInformation 43 | * Information about the object to populate. 44 | * @param values 45 | * The values to populate the object with, keyed by property name (e.g. "firstName"). 46 | * 47 | * @throws IllegalArgumentException 48 | * If any of the parameters are deemed illegal. For example, if any are null. 49 | * @throws BeanPopulationException 50 | * If an error occurs when populating the object. 51 | */ 52 | public void populate(Object bean, BeanInformation beanInformation, Map values) 53 | throws IllegalArgumentException, BeanPopulationException; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/ConcurrentFactoryPlugin.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories; 22 | 23 | import org.kohsuke.MetaInfServices; 24 | import org.meanbean.lang.Factory; 25 | import org.meanbean.util.RandomValueGenerator; 26 | 27 | import java.util.concurrent.atomic.AtomicBoolean; 28 | import java.util.concurrent.atomic.AtomicInteger; 29 | import java.util.concurrent.atomic.AtomicLong; 30 | import java.util.function.Function; 31 | 32 | @MetaInfServices 33 | public class ConcurrentFactoryPlugin implements FactoryCollectionPlugin { 34 | 35 | @Override 36 | public void initialize(FactoryCollection factoryCollection, RandomValueGenerator randomValueGenerator) { 37 | factoryCollection.addFactory(AtomicInteger.class, newFactory(randomValueGenerator::nextInt, AtomicInteger::new)); 38 | factoryCollection.addFactory(AtomicLong.class, newFactory(randomValueGenerator::nextLong, AtomicLong::new)); 39 | factoryCollection.addFactory(AtomicBoolean.class, () -> new AtomicBoolean(randomValueGenerator.nextBoolean())); 40 | } 41 | 42 | private Factory newFactory(Factory factory, Function fn) { 43 | return () -> fn.apply(factory.create()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/FactoryCollection.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories; 22 | 23 | import org.meanbean.lang.Factory; 24 | import org.meanbean.util.ServiceDefinition; 25 | 26 | /** 27 | * Defines a collection factories of different types of objects. 28 | * 29 | * @author Graham Williamson 30 | */ 31 | public interface FactoryCollection extends FactoryLookup { 32 | 33 | /** 34 | *

35 | * Add the specified Factory to the collection. 36 | *

37 | * 38 | *

39 | * If a Factory is already registered against the specified class, the existing registered Factory will be replaced 40 | * with the Factory you specify here. 41 | *

42 | * 43 | * @param clazz 44 | * The type of objects the Factory creates. The class type will be used to generate a key with which the 45 | * Factory can be retrieved from the collection at a later stage. 46 | * @param factory 47 | * The Factory to add to the collection. 48 | * 49 | * @throws IllegalArgumentException 50 | * If either of the required parameters are deemed illegal. 51 | */ 52 | void addFactory(Class clazz, Factory factory) throws IllegalArgumentException; 53 | 54 | /** 55 | *

56 | * Add the specified FactoryLookup 57 | *

58 | * 59 | * The factoryLookup will be first consulted when looking for a Factory 60 | */ 61 | void addFactoryLookup(FactoryLookup factoryLookup); 62 | 63 | public static ServiceDefinition getServiceDefinition() { 64 | return new ServiceDefinition<>(FactoryCollection.class); 65 | } 66 | 67 | public static FactoryCollection getInstance() { 68 | return getServiceDefinition().getServiceFactory() 69 | .getFirst(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/FactoryCollectionPlugin.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | import org.meanbean.util.ServiceDefinition; 25 | 26 | import java.util.List; 27 | 28 | /** 29 | * Defines a plugin that will register Factories with the specified FactoryCollection. 30 | * 31 | * @author Graham Williamson 32 | */ 33 | public interface FactoryCollectionPlugin { 34 | 35 | /** 36 | * Initialize the plugin, adding Factories to the FactoryCollection. 37 | * 38 | * @param factoryCollection 39 | * A FactoryCollection that Factory objects can be added to. 40 | * @param randomValueGenerator RandomValueGenerator that can be used by Factory objects. 41 | */ 42 | void initialize(FactoryCollection factoryCollection, RandomValueGenerator randomValueGenerator); 43 | 44 | public static ServiceDefinition getServiceDefinition() { 45 | return new ServiceDefinition<>(FactoryCollectionPlugin.class); 46 | } 47 | 48 | public static List getInstances() { 49 | return getServiceDefinition().getServiceFactory() 50 | .getAll(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/NoSuchFactoryException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories; 22 | 23 | /** 24 | * An exception that may be thrown when trying to get an unknown or unregistered Factory from the FactoryRepository. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public class NoSuchFactoryException extends RuntimeException { 29 | 30 | /** Unique version ID of this Serializable class. */ 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * Construct a new No Such Factory Exception with the specified message. 35 | * 36 | * @param message 37 | * A human-readable String message describing the problem that occurred. 38 | */ 39 | public NoSuchFactoryException(String message) { 40 | super(message); 41 | } 42 | 43 | /** 44 | * Construct a new No Such Factory Exception with the specified message and cause. 45 | * 46 | * @param message 47 | * A human-readable String message describing the problem that occurred. 48 | * @param cause 49 | * The cause of the exception. 50 | */ 51 | public NoSuchFactoryException(String message, Throwable cause) { 52 | super(message, cause); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/ObjectCreationException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories; 22 | 23 | /** 24 | * An exception that may be thrown when trying to create an instance of an object. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public class ObjectCreationException extends RuntimeException { 29 | 30 | /** Unique version ID of this Serializable class. */ 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * Construct a new Object Creation Exception with the specified message and cause. 35 | * 36 | * @param message 37 | * A human-readable String message describing the problem that occurred. 38 | * @param cause 39 | * The cause of the exception. 40 | */ 41 | public ObjectCreationException(String message, Throwable cause) { 42 | super(message, cause); 43 | } 44 | 45 | /** 46 | * Construct a new Object Creation Exception with the specified message. 47 | * 48 | * @param message 49 | * A human-readable String message describing the problem that occurred. 50 | */ 51 | public ObjectCreationException(String message) { 52 | super(message); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/BigDecimalFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | import java.math.BigDecimal; 26 | 27 | /** 28 | * Concrete Factory that creates random BigDecimal objects. 29 | * 30 | * @author Graham Williamson 31 | */ 32 | public final class BigDecimalFactory extends RandomFactoryBase { 33 | 34 | /** 35 | * Construct a new BigDecimal object factory. 36 | * 37 | * @param randomValueGenerator 38 | * A random value generator used by the Factory to generate random values. 39 | * 40 | * @throws IllegalArgumentException 41 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 42 | */ 43 | public BigDecimalFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 44 | super(randomValueGenerator); 45 | } 46 | 47 | /** 48 | * Create a new Double object. 49 | * 50 | * @return A new Double object. 51 | */ 52 | @Override 53 | public BigDecimal create() { 54 | return new BigDecimal(getRandomValueGenerator().nextLong()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/BigIntegerFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | import java.math.BigInteger; 26 | 27 | public final class BigIntegerFactory extends RandomFactoryBase { 28 | 29 | public BigIntegerFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 30 | super(randomValueGenerator); 31 | } 32 | 33 | @Override 34 | public BigInteger create() { 35 | return BigInteger.valueOf(getRandomValueGenerator().nextInt()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/BooleanFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | /** 26 | * Concrete Factory that creates random Boolean objects. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public final class BooleanFactory extends RandomFactoryBase { 31 | 32 | /** 33 | * Construct a new Boolean object factory. 34 | * 35 | * @param randomValueGenerator 36 | * A random value generator used by the Factory to generate random values. 37 | * 38 | * @throws IllegalArgumentException 39 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 40 | */ 41 | public BooleanFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 42 | super(randomValueGenerator); 43 | } 44 | 45 | /** 46 | * Create a new Boolean object. 47 | * 48 | * @return A new Boolean object. 49 | */ 50 | @Override 51 | public Boolean create() { 52 | return getRandomValueGenerator().nextBoolean(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/ByteFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | /** 26 | * Concrete Factory that creates random Byte objects. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public final class ByteFactory extends RandomFactoryBase { 31 | 32 | /** 33 | * Construct a new Byte object factory. 34 | * 35 | * @param randomValueGenerator 36 | * A random value generator used by the Factory to generate random values. 37 | * 38 | * @throws IllegalArgumentException 39 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 40 | */ 41 | public ByteFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 42 | super(randomValueGenerator); 43 | } 44 | 45 | /** 46 | * Create a new Byte object. 47 | * 48 | * @return A new Byte object. 49 | */ 50 | @Override 51 | public Byte create() { 52 | return getRandomValueGenerator().nextByte(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/CharacterFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | /** 26 | * Concrete Factory that creates random Character objects. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public final class CharacterFactory extends RandomFactoryBase { 31 | 32 | /** 33 | * Construct a new Character object factory. 34 | * 35 | * @param randomValueGenerator 36 | * A random value generator used by the Factory to generate random values. 37 | * 38 | * @throws IllegalArgumentException 39 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 40 | */ 41 | public CharacterFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 42 | super(randomValueGenerator); 43 | } 44 | 45 | /** 46 | * Create a new Character object. 47 | * 48 | * @return A new Character object. 49 | */ 50 | @Override 51 | public Character create() { 52 | // Basis of our random number. This value is always positive. 53 | double randomNumber = getRandomValueGenerator().nextDouble(); 54 | char result = (char) (Character.MAX_VALUE * randomNumber); 55 | return result; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/DateFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | import java.util.Date; 26 | 27 | /** 28 | * Concrete Factory that creates random Date objects. 29 | * 30 | * @author Graham Williamson 31 | */ 32 | public final class DateFactory extends RandomFactoryBase { 33 | 34 | /** 35 | * Construct a new Date object factory. 36 | * 37 | * @param randomValueGenerator 38 | * A random value generator used by the Factory to generate random values. 39 | * 40 | * @throws IllegalArgumentException 41 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 42 | */ 43 | public DateFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 44 | super(randomValueGenerator); 45 | } 46 | 47 | /** 48 | * Create a new Date object. 49 | * 50 | * @return A new Date object. 51 | */ 52 | @Override 53 | public Date create() { 54 | // Get random time since the epoch 55 | long randomTime = Math.abs(getRandomValueGenerator().nextLong()); 56 | return new Date(randomTime); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/DoubleFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | /** 26 | * Concrete Factory that creates random Double objects. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public final class DoubleFactory extends RandomFactoryBase { 31 | 32 | /** 33 | * Construct a new Double object factory. 34 | * 35 | * @param randomValueGenerator 36 | * A random value generator used by the Factory to generate random values. 37 | * 38 | * @throws IllegalArgumentException 39 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 40 | */ 41 | public DoubleFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 42 | super(randomValueGenerator); 43 | } 44 | 45 | /** 46 | * Create a new Double object. 47 | * 48 | * @return A new Double object. 49 | */ 50 | @Override 51 | public Double create() { 52 | // Basis of our random number. This value is always positive, so we need to decide the sign 53 | double result = getRandomValueGenerator().nextDouble(); 54 | // Our double is either based on MAX_VALUE, else MIN_VALUE 55 | boolean basedOnMax = getRandomValueGenerator().nextBoolean(); 56 | result *= basedOnMax ? Double.MAX_VALUE : Double.MIN_VALUE; 57 | // Our double is either positive, else negative 58 | boolean positive = getRandomValueGenerator().nextBoolean(); 59 | result *= positive ? 1 : -1; 60 | return result; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/EnumFactoryLookup.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.kohsuke.MetaInfServices; 24 | import org.meanbean.factories.FactoryLookup; 25 | import org.meanbean.factories.NoSuchFactoryException; 26 | import org.meanbean.lang.Factory; 27 | import org.meanbean.util.Order; 28 | import org.meanbean.util.RandomValueGenerator; 29 | 30 | import java.lang.reflect.Type; 31 | 32 | /** 33 | * FactoryLookup for EnumFactory instances 34 | */ 35 | @Order(4100) 36 | @MetaInfServices 37 | public class EnumFactoryLookup implements FactoryLookup { 38 | 39 | @SuppressWarnings("unchecked") 40 | @Override 41 | public Factory getFactory(Type type) throws IllegalArgumentException, NoSuchFactoryException { 42 | return (Factory) new EnumFactory((Class) type, RandomValueGenerator.getInstance()); 43 | } 44 | 45 | @SuppressWarnings("rawtypes") 46 | @Override 47 | public boolean hasFactory(Type type) throws IllegalArgumentException { 48 | return type instanceof Class && ((Class) type).isEnum(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/FloatFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | /** 26 | * Concrete Factory that creates random Float objects. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public final class FloatFactory extends RandomFactoryBase { 31 | 32 | /** 33 | * Construct a new Float object factory. 34 | * 35 | * @param randomValueGenerator 36 | * A random value generator used by the Factory to generate random values. 37 | * 38 | * @throws IllegalArgumentException 39 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 40 | */ 41 | public FloatFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 42 | super(randomValueGenerator); 43 | } 44 | 45 | /** 46 | * Create a new Float object. 47 | * 48 | * @return A new Float object. 49 | */ 50 | @Override 51 | public Float create() { 52 | // Basis of our random number. This value is always positive, so we need to decide the sign 53 | float result = getRandomValueGenerator().nextFloat(); 54 | // Our float is either based on MAX_VALUE, else MIN_VALUE 55 | boolean basedOnMax = getRandomValueGenerator().nextBoolean(); 56 | result *= basedOnMax ? Float.MAX_VALUE : Float.MIN_VALUE; 57 | // Our float is either positive, else negative 58 | boolean positive = getRandomValueGenerator().nextBoolean(); 59 | result *= positive ? 1 : -1; 60 | return result; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/IntegerFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | /** 26 | * Concrete Factory that creates random Integer objects. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public final class IntegerFactory extends RandomFactoryBase { 31 | 32 | /** 33 | * Construct a new Integer object factory. 34 | * 35 | * @param randomValueGenerator 36 | * A random value generator used by the Factory to generate random values. 37 | * 38 | * @throws IllegalArgumentException 39 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 40 | */ 41 | public IntegerFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 42 | super(randomValueGenerator); 43 | } 44 | 45 | /** 46 | * Create a new Integer object. 47 | * 48 | * @return A new Integer object. 49 | */ 50 | @Override 51 | public Integer create() { 52 | return getRandomValueGenerator().nextInt(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/LongFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | /** 26 | * Concrete Factory that creates random Long objects. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public final class LongFactory extends RandomFactoryBase { 31 | 32 | /** 33 | * Construct a new Long object factory. 34 | * 35 | * @param randomValueGenerator 36 | * A random value generator used by the Factory to generate random values. 37 | * 38 | * @throws IllegalArgumentException 39 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 40 | */ 41 | public LongFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 42 | super(randomValueGenerator); 43 | } 44 | 45 | /** 46 | * Create a new Long object. 47 | * 48 | * @return A new Long object. 49 | */ 50 | @Override 51 | public Long create() { 52 | return getRandomValueGenerator().nextLong(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/RandomFactoryBase.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.lang.Factory; 24 | import org.meanbean.util.RandomValueGenerator; 25 | import org.meanbean.util.ValidationHelper; 26 | 27 | /** 28 | * Abstract base class for a Factory that creates random objects of the specified type. 29 | * 30 | * @author Graham Williamson 31 | * @param 32 | * The data type of the object this Factory creates. 33 | */ 34 | public abstract class RandomFactoryBase implements Factory { 35 | 36 | /** Random number generator used by the factory to generate random values. */ 37 | private final RandomValueGenerator randomValueGenerator; 38 | 39 | /** 40 | * Construct a new Factory. 41 | * 42 | * @param randomValueGenerator 43 | * A random value generator used by the Factory to generate random values. 44 | * 45 | * @throws IllegalArgumentException 46 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 47 | */ 48 | public RandomFactoryBase(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 49 | ValidationHelper.ensureExists("randomValueGenerator", "construct Factory", randomValueGenerator); 50 | this.randomValueGenerator = randomValueGenerator; 51 | } 52 | 53 | /** 54 | * Get the random value generator. 55 | * 56 | * @return A random value generator. 57 | */ 58 | public final RandomValueGenerator getRandomValueGenerator() { 59 | return randomValueGenerator; 60 | } 61 | 62 | /** 63 | * Create a new object of the specified type. 64 | * 65 | * @return A new object of the specified type. 66 | */ 67 | @Override 68 | public abstract T create(); 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/ShortFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | /** 26 | * Concrete Factory that creates random Short objects. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public final class ShortFactory extends RandomFactoryBase { 31 | 32 | /** 33 | * Construct a new Short object factory. 34 | * 35 | * @param randomValueGenerator 36 | * A random value generator used by the Factory to generate random values. 37 | * 38 | * @throws IllegalArgumentException 39 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 40 | */ 41 | public ShortFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 42 | super(randomValueGenerator); 43 | } 44 | 45 | /** 46 | * Create a new Short object. 47 | * 48 | * @return A new Short object. 49 | */ 50 | @Override 51 | public Short create() { 52 | short result = 0; 53 | // Basis of our random number. This value is always positive, so we need to decide the sign 54 | double randomNumber = getRandomValueGenerator().nextDouble(); 55 | // Our short is either based on MAX_VALUE, else MIN_VALUE 56 | boolean basedOnMax = getRandomValueGenerator().nextBoolean(); 57 | if (basedOnMax) { 58 | result = (short) (Short.MAX_VALUE * randomNumber); 59 | } else { 60 | result = (short) (Short.MIN_VALUE * randomNumber); 61 | } 62 | // Our double is either positive, else negative 63 | boolean positive = getRandomValueGenerator().nextBoolean(); 64 | result *= positive ? 1 : -1; 65 | return result; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/basic/StringFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | 25 | /** 26 | * Concrete Factory that creates random String objects. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public final class StringFactory extends RandomFactoryBase { 31 | 32 | /** 33 | * Construct a new String object factory. 34 | * 35 | * @param randomValueGenerator 36 | * A random value generator used by the Factory to generate random values. 37 | * 38 | * @throws IllegalArgumentException 39 | * If the specified randomValueGenerator is deemed illegal. For example, if it is null. 40 | */ 41 | public StringFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 42 | super(randomValueGenerator); 43 | } 44 | 45 | /** 46 | * Create a new String object. 47 | * 48 | * @return A new String object. 49 | */ 50 | @Override 51 | public String create() { 52 | return "TestString:[" + getRandomValueGenerator().nextLong() + "]"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/beans/BeanCreationException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.beans; 22 | 23 | /** 24 | * An exception that may be thrown when trying to create an instance of a JavaBean. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public class BeanCreationException extends RuntimeException { 29 | 30 | /** Unique version ID of this Serializable class. */ 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * Construct a new Bean Creation Exception with the specified message and cause. 35 | * 36 | * @param message 37 | * A human-readable String message describing the problem that occurred. 38 | * @param cause 39 | * The cause of the exception. 40 | */ 41 | public BeanCreationException(String message, Throwable cause) { 42 | super(message, cause); 43 | } 44 | 45 | /** 46 | * Construct a new Bean Creation Exception with the specified message. 47 | * 48 | * @param message 49 | * A human-readable String message describing the problem that occurred. 50 | */ 51 | public BeanCreationException(String message) { 52 | super(message); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/equivalent/EquivalentEnumFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.equivalent; 22 | 23 | import org.meanbean.lang.EquivalentFactory; 24 | import org.meanbean.util.ValidationHelper; 25 | 26 | /** 27 | * Concrete Factory that always creates the same Enum constant of the specified Enum type. 28 | * 29 | * @author Graham Williamson 30 | */ 31 | public class EquivalentEnumFactory implements EquivalentFactory> { 32 | 33 | /** Enum constants of the specified Enum type. */ 34 | private final Enum[] enumConstants; 35 | 36 | /** 37 | * Construct a new Factory. 38 | * 39 | * @param enumClass 40 | * The type of Enum to create Enum constants of. 41 | * 42 | * @throws IllegalArgumentException 43 | * If enumClass is deemed illegal. For example, if it is null. 44 | */ 45 | public EquivalentEnumFactory(Class enumClass) throws IllegalArgumentException { 46 | ValidationHelper.ensureExists("enumClass", "construct EnumFactory", enumClass); 47 | if (!enumClass.isEnum()) { 48 | throw new IllegalArgumentException("Cannot create EnumFactory for non-Enum class."); 49 | } 50 | this.enumConstants = (Enum[]) enumClass.getEnumConstants(); 51 | } 52 | 53 | /** 54 | * Create an Enum constant of the specified Enum type. 55 | * 56 | * @return An Enum constant of the specified Enum type. 57 | */ 58 | @Override 59 | public Enum create() { 60 | return enumConstants[0]; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/io/FileFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.io; 22 | 23 | import org.kohsuke.MetaInfServices; 24 | import org.meanbean.factories.FactoryCollection; 25 | import org.meanbean.factories.FactoryCollectionPlugin; 26 | import org.meanbean.util.RandomValueGenerator; 27 | 28 | import java.io.File; 29 | import java.io.IOException; 30 | import java.io.UncheckedIOException; 31 | import java.nio.file.Files; 32 | import java.nio.file.Path; 33 | 34 | @MetaInfServices(FactoryCollectionPlugin.class) 35 | public class FileFactory implements FactoryCollectionPlugin { 36 | 37 | @Override 38 | public void initialize(FactoryCollection factoryCollection, RandomValueGenerator randomValueGenerator) { 39 | factoryCollection.addFactory(File.class, this::generateTempFile); 40 | factoryCollection.addFactory(Path.class, this::generateTempPath); 41 | } 42 | 43 | private File generateTempFile() { 44 | return generateTempPath().toFile(); 45 | } 46 | 47 | private Path generateTempPath() { 48 | try { 49 | Path path = Files.createTempFile("mean-bean-file-factory-", ".txt"); 50 | Files.delete(path); 51 | return path; 52 | } catch (IOException e) { 53 | throw new UncheckedIOException(e); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/net/NetFactoryPlugin.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.net; 22 | 23 | import org.kohsuke.MetaInfServices; 24 | import org.meanbean.factories.FactoryCollection; 25 | import org.meanbean.factories.FactoryCollectionPlugin; 26 | import org.meanbean.util.RandomValueGenerator; 27 | 28 | import java.net.URI; 29 | import java.net.URL; 30 | 31 | @MetaInfServices 32 | public final class NetFactoryPlugin implements FactoryCollectionPlugin { 33 | 34 | @Override 35 | public void initialize(FactoryCollection factoryCollection, RandomValueGenerator randomValueGenerator) { 36 | UrlFactory urlFactory = new UrlFactory(randomValueGenerator); 37 | factoryCollection.addFactory(URL.class, urlFactory); 38 | factoryCollection.addFactory(URI.class, () -> URI.create(urlFactory.create().toString())); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/net/UrlFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.net; 22 | 23 | import org.meanbean.factories.basic.RandomFactoryBase; 24 | import org.meanbean.util.RandomValueGenerator; 25 | import org.meanbean.util.RandomValueSampler; 26 | 27 | import java.net.MalformedURLException; 28 | import java.net.URL; 29 | import java.util.Arrays; 30 | import java.util.List; 31 | import java.util.UUID; 32 | import java.util.stream.Collectors; 33 | import java.util.stream.IntStream; 34 | 35 | public class UrlFactory extends RandomFactoryBase { 36 | 37 | private RandomValueSampler sampler; 38 | 39 | private List schemes = Arrays.asList("http://", "https://", "ftp://"); 40 | private List tlds = Arrays.asList(".example", ".invalid", ".test"); 41 | private List paths = Arrays.asList("", "/foo", "/foo/bar/", "/foo/bar/index?a=b"); 42 | 43 | public UrlFactory(RandomValueGenerator randomValueGenerator) { 44 | super(randomValueGenerator); 45 | this.sampler = new RandomValueSampler(randomValueGenerator); 46 | } 47 | 48 | @Override 49 | public URL create() { 50 | String scheme = sampler.getFrom(schemes); 51 | String domain = getRandomDomain(); 52 | String tld = sampler.getFrom(tlds); 53 | String path = sampler.getFrom(paths); 54 | String url = String.join("", scheme, domain, tld, path); 55 | try { 56 | return new URL(url); 57 | } catch (MalformedURLException e) { 58 | throw new IllegalStateException(url, e); 59 | } 60 | } 61 | 62 | protected String getRandomDomain() { 63 | int subdomainCount = getRandomValueGenerator().nextInt(1) + 1; 64 | return IntStream.range(0, subdomainCount) 65 | .mapToObj(num -> UUID.randomUUID().toString()) 66 | .collect(Collectors.joining(".")); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/time/RandomClock.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.time; 22 | 23 | import org.meanbean.util.RandomValueGenerator; 24 | import org.meanbean.util.RandomValueSampler; 25 | 26 | import java.time.Clock; 27 | import java.time.Instant; 28 | import java.time.ZoneId; 29 | import java.util.Set; 30 | 31 | public class RandomClock extends Clock { 32 | 33 | private RandomValueGenerator randomValueGenerator; 34 | private RandomValueSampler randomValueSampler; 35 | 36 | public RandomClock(RandomValueGenerator randomValueGenerator) { 37 | this.randomValueGenerator = randomValueGenerator; 38 | this.randomValueSampler = new RandomValueSampler(randomValueGenerator); 39 | } 40 | 41 | @Override 42 | public ZoneId getZone() { 43 | Set availableZoneIds = ZoneId.getAvailableZoneIds(); 44 | return randomValueSampler.findFrom(availableZoneIds) 45 | .map(ZoneId::of) 46 | .orElse(ZoneId.systemDefault()); 47 | } 48 | 49 | @Override 50 | public Clock withZone(ZoneId zone) { 51 | throw new UnsupportedOperationException(); 52 | } 53 | 54 | @Override 55 | public Instant instant() { 56 | return Instant.ofEpochMilli(randomValueGenerator.nextLong()); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/factories/util/LocaleFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.util; 22 | 23 | import org.kohsuke.MetaInfServices; 24 | import org.meanbean.factories.FactoryCollection; 25 | import org.meanbean.factories.FactoryCollectionPlugin; 26 | import org.meanbean.lang.Factory; 27 | import org.meanbean.util.RandomValueGenerator; 28 | import org.meanbean.util.RandomValueSampler; 29 | 30 | import java.util.Arrays; 31 | import java.util.List; 32 | import java.util.Locale; 33 | 34 | @MetaInfServices(FactoryCollectionPlugin.class) 35 | public class LocaleFactory implements Factory, FactoryCollectionPlugin { 36 | 37 | private RandomValueGenerator randomValueGenerator = RandomValueGenerator.getInstance(); 38 | private RandomValueSampler randomValueSampler = new RandomValueSampler(randomValueGenerator); 39 | 40 | @Override 41 | public Locale create() { 42 | List locales = Arrays.asList(Locale.getAvailableLocales()); 43 | return randomValueSampler.getFrom(locales); 44 | } 45 | 46 | @Override 47 | public void initialize(FactoryCollection factoryCollection, RandomValueGenerator randomValueGenerator) { 48 | factoryCollection.addFactory(Locale.class, this); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/lang/EquivalentFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.lang; 22 | 23 | import org.meanbean.util.ServiceDefinition; 24 | 25 | /** 26 | * Defines an object that creates logically equivalent objects of a specified type. 27 | * 28 | * @author Graham Williamson 29 | * @param 30 | * The data type of the object this Factory creates. 31 | */ 32 | public interface EquivalentFactory { 33 | 34 | /** 35 | * Create a new logically equivalent object of the specified type. 36 | * 37 | * @return A new object of the specified type. 38 | */ 39 | T create(); 40 | 41 | @SuppressWarnings({ "rawtypes", "unchecked" }) 42 | public static ServiceDefinition> getServiceDefinition() { 43 | return new ServiceDefinition<>((Class) EquivalentFactory.class); 44 | } 45 | 46 | public static EquivalentFactory getInstance() { 47 | return getServiceDefinition().getServiceFactory() 48 | .getFirst(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/lang/Factory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.lang; 22 | 23 | /** 24 | * Defines an object that creates objects of a specified type. 25 | * 26 | * @author Graham Williamson 27 | * @param 28 | * The data type of the object this Factory creates. 29 | */ 30 | public interface Factory { 31 | 32 | /** 33 | * Create a new object of the specified type. 34 | * 35 | * @return A new object of the specified type. 36 | */ 37 | T create(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/logging/$Logger.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.logging; 22 | 23 | /** 24 | * Internal facade around well-known logging facades 25 | */ 26 | public interface $Logger { 27 | public boolean isTraceEnabled(); 28 | 29 | public void trace(String format, Object... arguments); 30 | 31 | public boolean isDebugEnabled(); 32 | 33 | public void debug(String format, Object... arguments); 34 | 35 | public boolean isInfoEnabled(); 36 | 37 | public void info(String format, Object... arguments); 38 | 39 | public boolean isWarnEnabled(); 40 | 41 | public void warn(String format, Object... arguments); 42 | 43 | public boolean isErrorEnabled(); 44 | 45 | public void error(String format, Object... arguments); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/test/BeanTestException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test; 22 | 23 | /** 24 | * An exception that may be thrown when trying to test a JavaBean using BeanTester. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public class BeanTestException extends RuntimeException { 29 | 30 | /** Unique version ID of this Serializable class. */ 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * Construct a new Bean Test Exception with the specified message. 35 | * 36 | * @param message 37 | * A human-readable String message describing the problem that occurred. 38 | */ 39 | public BeanTestException(String message) { 40 | super(message); 41 | } 42 | 43 | /** 44 | * Construct a new Bean Test Exception with the specified message and cause. 45 | * 46 | * @param message 47 | * A human-readable String message describing the problem that occurred. 48 | * @param cause 49 | * The cause of the exception. 50 | */ 51 | public BeanTestException(String message, Throwable cause) { 52 | super(message, cause); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/test/Warning.java: -------------------------------------------------------------------------------- 1 | package org.meanbean.test; 2 | 3 | /** 4 | * Enum of warnings that can be suppressed in {@link BeanVerifier}. 5 | */ 6 | public enum Warning { 7 | 8 | /** 9 | * Disables the check and do not fail for setter methods that have side-effect other properties. For example, 10 | * a setter method that sets prroperty fields. 11 | */ 12 | SETTER_SIDE_EFFECT, 13 | 14 | /** 15 | * When meanbean finds a property type that does not have built-in support for creating random values (like it does 16 | * with String, Date, etc), then meanbean creates a dynamic factory hoping that the property type is a java bean. 17 | * That dynamic factory is used to create random values of the property. 18 | * 19 | * When that happens a warning is logged. This can be used to suppress that (or call VerifierSettings::registerFactory 20 | * to register a custom factory) 21 | */ 22 | DYNAMICALLY_CREATED_FACTORY, 23 | 24 | ; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/test/internal/EqualityTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.internal; 22 | 23 | /** 24 | * Equality test of two objects. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public enum EqualityTest { 29 | 30 | /** 31 | * Test the logical equality of two objects (x.equals(y)). 32 | */ 33 | LOGICAL { 34 | @Override 35 | public boolean test(Object x, Object y) { 36 | return x.equals(y); 37 | } 38 | }, 39 | 40 | /** 41 | * Test the absolute equality of two objects (x == y). 42 | */ 43 | ABSOLUTE { 44 | @Override 45 | public boolean test(Object x, Object y) { 46 | return x == y; 47 | } 48 | }; 49 | 50 | /** 51 | * Is object x equal to object y. 52 | * 53 | * @param x 54 | * The first object to compare. 55 | * @param y 56 | * The second object to compare. 57 | * 58 | * @return true if the objects are considered equal; false otherwise. 59 | */ 60 | public abstract boolean test(Object x, Object y); 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/test/internal/NoopSideEffectDetector.java: -------------------------------------------------------------------------------- 1 | package org.meanbean.test.internal; 2 | 3 | import org.meanbean.bean.info.PropertyInformation; 4 | 5 | import java.util.List; 6 | 7 | public class NoopSideEffectDetector implements SideEffectDetector { 8 | 9 | public static final NoopSideEffectDetector INSTANCE = new NoopSideEffectDetector(); 10 | 11 | @Override 12 | public List init(Object bean, List readableWritableProperties) { 13 | return readableWritableProperties; 14 | } 15 | 16 | @Override 17 | public void beforeTestProperty(PropertyInformation property, EqualityTest equalityTest) { 18 | 19 | } 20 | 21 | @Override 22 | public void detectAfterTestProperty() { 23 | 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/main/java/org/meanbean/test/internal/SideEffectDetector.java: -------------------------------------------------------------------------------- 1 | package org.meanbean.test.internal; 2 | 3 | import org.meanbean.bean.info.PropertyInformation; 4 | 5 | import java.util.List; 6 | 7 | public interface SideEffectDetector { 8 | 9 | List init(Object bean, List readableWritableProperties); 10 | 11 | void beforeTestProperty(PropertyInformation property, EqualityTest equalityTest); 12 | 13 | void detectAfterTestProperty(); 14 | 15 | } -------------------------------------------------------------------------------- /src/main/java/org/meanbean/test/internal/SideEffectDetectorFactory.java: -------------------------------------------------------------------------------- 1 | package org.meanbean.test.internal; 2 | 3 | import org.meanbean.bean.info.PropertyInformation; 4 | 5 | import java.util.List; 6 | 7 | public interface SideEffectDetectorFactory { 8 | 9 | List init(Object bean, List readableWritableProperties); 10 | 11 | void beforeTestProperty(PropertyInformation property, EqualityTest equalityTest); 12 | 13 | void detectAfterTestProperty(); 14 | 15 | } -------------------------------------------------------------------------------- /src/main/java/org/meanbean/util/AssertionUtils.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.util; 22 | 23 | /** 24 | * Utility methods for assertions. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public final class AssertionUtils { 29 | 30 | /** 31 | * Construct a new AssertionUtils. 32 | */ 33 | private AssertionUtils() { 34 | // Do nothing - make non-instantiable 35 | } 36 | 37 | /** 38 | * Fail an assertion, which will throw an AssertionError with no message. 39 | */ 40 | public static void fail() { 41 | throw new AssertionError(); 42 | } 43 | 44 | /** 45 | * Fail an assertion, which will throw an AssertionError with the specified message. 46 | * 47 | * @param message 48 | * A message detailing the assertion failure. 49 | */ 50 | public static void fail(String message) { 51 | throw new AssertionError(message); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/util/ClassPathUtils.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.util; 22 | 23 | import org.meanbean.test.BeanVerifier; 24 | import org.meanbean.util.ClassPath.ClassInfo; 25 | 26 | import java.lang.reflect.Modifier; 27 | import java.util.Set; 28 | 29 | public final class ClassPathUtils { 30 | 31 | public static Class[] findClassesIn(String packageName) { 32 | ClassPath classPath = ClassPath.from(BeanVerifier.class); 33 | Set classInfoSet = classPath.getTopLevelClassesRecursive(packageName); 34 | return classInfoSet.stream() 35 | .map(ClassInfo::load) 36 | .filter(clazz -> !clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers())) 37 | .toArray(Class[]::new); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/util/Order.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | /* 22 | * Copyright 2002-2017 the original author or authors. 23 | * 24 | * Licensed under the Apache License, Version 2.0 (the "License"); 25 | * you may not use this file except in compliance with the License. 26 | * You may obtain a copy of the License at 27 | * 28 | * https://www.apache.org/licenses/LICENSE-2.0 29 | * 30 | * Unless required by applicable law or agreed to in writing, software 31 | * distributed under the License is distributed on an "AS IS" BASIS, 32 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 33 | * See the License for the specific language governing permissions and 34 | * limitations under the License. 35 | */ 36 | 37 | package org.meanbean.util; 38 | 39 | import java.lang.annotation.Documented; 40 | import java.lang.annotation.ElementType; 41 | import java.lang.annotation.Retention; 42 | import java.lang.annotation.RetentionPolicy; 43 | import java.lang.annotation.Target; 44 | 45 | @Retention(RetentionPolicy.RUNTIME) 46 | @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD }) 47 | @Documented 48 | public @interface Order { 49 | 50 | /** 51 | * Useful constant for the highest precedence value. 52 | * @see java.lang.Integer#MIN_VALUE 53 | */ 54 | int HIGHEST_PRECEDENCE = Integer.MIN_VALUE; 55 | 56 | /** 57 | * Useful constant for the lowest precedence value. 58 | * @see java.lang.Integer#MAX_VALUE 59 | */ 60 | int LOWEST_PRECEDENCE = Integer.MAX_VALUE; 61 | 62 | /** 63 | * The order value. 64 | *

Default is {@link LOWEST_PRECEDENCE}. 65 | */ 66 | int value() default LOWEST_PRECEDENCE; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/util/PropertyNameFinder.java: -------------------------------------------------------------------------------- 1 | package org.meanbean.util; 2 | 3 | import com.github.meanbeanlib.mirror.Executables; 4 | import com.github.meanbeanlib.mirror.SerializableLambdas.SerializableFunction1; 5 | 6 | import java.beans.BeanInfo; 7 | import java.beans.Introspector; 8 | import java.beans.PropertyDescriptor; 9 | import java.lang.reflect.Method; 10 | import java.util.Arrays; 11 | import java.util.stream.Stream; 12 | 13 | public class PropertyNameFinder { 14 | 15 | public static String findPropertyName(Class beanClass, SerializableFunction1 beanGetter) { 16 | Method method = Executables.findGetter(beanGetter); 17 | try { 18 | BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); 19 | PropertyDescriptor property = Stream.of(beanInfo.getPropertyDescriptors()) 20 | .filter(pd -> methodsEqual(method, pd.getReadMethod())) 21 | .findFirst() 22 | .orElseThrow(() -> new IllegalArgumentException("Invalid bean getter method:" + method)); 23 | return property.getName(); 24 | } catch (Exception e) { 25 | if (e instanceof IllegalArgumentException) { 26 | throw (IllegalArgumentException) e; 27 | } 28 | throw new IllegalArgumentException("Invalid bean getter method: " + method, e); 29 | } 30 | } 31 | 32 | @SafeVarargs 33 | public static String[] findPropertyNames(Class beanClass, SerializableFunction1... beanGetters) { 34 | return Stream.of(beanGetters) 35 | .map(beanGetter -> PropertyNameFinder.findPropertyName(beanClass, beanGetter)) 36 | .toArray(String[]::new); 37 | } 38 | 39 | private static boolean methodsEqual(Method left, Method right) { 40 | if (left.equals(right)) { 41 | return true; 42 | } 43 | if (right == null) { 44 | return false; 45 | } 46 | return left.getReturnType().equals(right.getReturnType()) 47 | && left.getName().equals(right.getName()) 48 | && Arrays.equals(left.getParameterTypes(), right.getParameterTypes()) 49 | && left.getDeclaringClass().isAssignableFrom(right.getDeclaringClass()); 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/util/RandomValueSampler.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.util; 22 | 23 | import java.util.Collection; 24 | import java.util.List; 25 | import java.util.Optional; 26 | import java.util.RandomAccess; 27 | 28 | public class RandomValueSampler { 29 | 30 | private RandomValueGenerator randomValueGenerator; 31 | 32 | public RandomValueSampler(RandomValueGenerator randomValueGenerator) { 33 | this.randomValueGenerator = randomValueGenerator; 34 | } 35 | 36 | public E getFrom(Collection collection) { 37 | return findFrom(collection) 38 | .orElseThrow(() -> new IllegalStateException()); 39 | } 40 | 41 | public Optional findFrom(Collection collection) { 42 | if (collection instanceof List && collection instanceof RandomAccess) { 43 | return findFrom((List) collection); 44 | } 45 | return collection.stream() 46 | .skip(randomIndex(collection)) 47 | .findFirst(); 48 | } 49 | 50 | public E getFrom(List list) { 51 | return findFrom(list) 52 | .orElseThrow(() -> new IllegalStateException()); 53 | } 54 | 55 | public Optional findFrom(List list) { 56 | if (list.isEmpty()) { 57 | return Optional.empty(); 58 | } 59 | 60 | int randomSkip = randomIndex(list); 61 | return Optional.ofNullable(list.get(randomSkip)); 62 | } 63 | 64 | private int randomIndex(Collection collection) { 65 | return collection.size() == 0 66 | ? 0 67 | : randomValueGenerator.nextInt(collection.size()); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/util/ServiceDefinition.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.util; 22 | 23 | import java.util.Arrays; 24 | 25 | /** 26 | * Defines how service implementations should be instantiated 27 | */ 28 | public class ServiceDefinition { 29 | 30 | private Class serviceType; 31 | private Class[] constructorTypes = {}; 32 | private Object[] constructorArgs = {}; 33 | 34 | public ServiceDefinition(Class serviceType) { 35 | this(serviceType, new Class[] {}, new Object[] {}); 36 | } 37 | 38 | public ServiceDefinition(Class serviceType, Class[] constructorTypes, Object[] constructorArgs) { 39 | if (constructorTypes.length != constructorArgs.length) { 40 | throw new IllegalArgumentException(); 41 | } 42 | this.serviceType = serviceType; 43 | this.constructorTypes = Arrays.copyOf(constructorTypes, constructorTypes.length); 44 | this.constructorArgs = Arrays.copyOf(constructorArgs, constructorTypes.length); 45 | } 46 | 47 | Class getServiceType() { 48 | return serviceType; 49 | } 50 | 51 | Class[] getConstructorTypes() { 52 | return constructorTypes; 53 | } 54 | 55 | Object[] getConstructorArgs() { 56 | return constructorArgs; 57 | } 58 | 59 | public ServiceFactory getServiceFactory(){ 60 | return ServiceFactory.getInstance(this); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/util/reflect/PreJava9ReflectionAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Gson 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 | * http://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 | package org.meanbean.util.reflect; 17 | 18 | import java.lang.reflect.AccessibleObject; 19 | 20 | /** 21 | * A basic implementation of {@link ReflectionAccessor} which is suitable for Java 8 and below. 22 | *

23 | * This implementation just calls {@link AccessibleObject#setAccessible(boolean) setAccessible(true)}, which worked 24 | * fine before Java 9. 25 | */ 26 | final class PreJava9ReflectionAccessor extends ReflectionAccessor { 27 | 28 | /** {@inheritDoc} */ 29 | @Override 30 | public void makeAccessible(AccessibleObject ao) { 31 | ao.setAccessible(true); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/meanbean/util/reflect/ReflectionAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Gson 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 | * http://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 | package org.meanbean.util.reflect; 17 | 18 | import java.lang.reflect.AccessibleObject; 19 | 20 | /** 21 | * Provides a replacement for {@link AccessibleObject#setAccessible(boolean)}, which may be used to 22 | * avoid reflective access issues appeared in Java 9, like java.lang.reflect.InaccessibleObjectException 23 | * thrown or warnings like 24 | *

25 |  *   WARNING: An illegal reflective access operation has occurred
26 |  *   WARNING: Illegal reflective access by ...
27 |  * 
28 | *

29 | * Works both for Java 9 and earlier Java versions. 30 | */ 31 | public abstract class ReflectionAccessor { 32 | 33 | // the singleton instance, use getInstance() to obtain 34 | private static final ReflectionAccessor instance = JavaVersion.getMajorJavaVersion() < 9 ? new PreJava9ReflectionAccessor() : new UnsafeReflectionAccessor(); 35 | 36 | /** 37 | * Does the same as {@code ao.setAccessible(true)}, but never throws 38 | * java.lang.reflect.InaccessibleObjectException 39 | */ 40 | public abstract void makeAccessible(AccessibleObject ao); 41 | 42 | /** 43 | * Obtains a {@link ReflectionAccessor} instance suitable for the current Java version. 44 | *

45 | * You may need one a reflective operation in your code throws java.lang.reflect.InaccessibleObjectException. 46 | * In such a case, use {@link ReflectionAccessor#makeAccessible(AccessibleObject)} on a field, method or constructor 47 | * (instead of basic {@link AccessibleObject#setAccessible(boolean)}). 48 | */ 49 | public static ReflectionAccessor getInstance() { 50 | return instance; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/javadoc/overview.html: -------------------------------------------------------------------------------- 1 | 2 |

MeanBean - Automated JavaBean Testing

3 | 4 |
https://github.com/meanbeanlib/meanbean 5 |
6 |
7 | see {@link org.meanbean.test.BeanVerifier} or {@link org.meanbean.test.BeanTester} 8 |
9 |
10 | Examples: 11 | 12 |
13 | 	// verify java-bean getters/setters, equals, hashCode and toString for a single bean type
14 | 	BeanVerifier.verifyBean(MyBean.class);
15 | 		
16 | 	// verify beans defined in the same package
17 | 	BeanVerifier.verifyBeansIn(MyBean.class.getPackage());
18 | 	
19 | 20 |
21 | 22 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/bean/info/BeanInformationExceptionTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.bean.info; 22 | 23 | import org.meanbean.test.util.MessageAndCauseExceptionTestBase; 24 | 25 | public class BeanInformationExceptionTest extends MessageAndCauseExceptionTestBase { 26 | 27 | @Override 28 | public Exception createMessageException(String message) { 29 | return new BeanInformationException(message); 30 | } 31 | 32 | @Override 33 | public Exception createMessageAndCauseException(String message, Throwable cause) { 34 | return new BeanInformationException(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/bean/info/JavaBeanInformationFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.bean.info; 22 | 23 | import static org.junit.Assert.assertEquals; 24 | 25 | import org.junit.Test; 26 | 27 | public class JavaBeanInformationFactoryTest { 28 | 29 | @Test 30 | public void shouldCreateCorrectJavaBeanInformation() throws Exception { 31 | // Given 32 | JavaBeanInformationFactory factory = new JavaBeanInformationFactory(); 33 | Class inputBeanClass = String.class; 34 | // When 35 | BeanInformation beanInformation = factory.create(inputBeanClass); 36 | // Then 37 | assertEquals("Incorrect BeanInformation.", beanInformation.getBeanClass(), inputBeanClass); 38 | } 39 | 40 | @Test(expected = IllegalArgumentException.class) 41 | public void shouldPreventNullBeanClass() throws Exception { 42 | // Given 43 | JavaBeanInformationFactory factory = new JavaBeanInformationFactory(); 44 | // When 45 | factory.create(null); 46 | // Then - throws IllegalArgumentException 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/bean/util/BeanPopulationExceptionTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.bean.util; 22 | 23 | import org.meanbean.test.util.MessageAndCauseExceptionTestBase; 24 | 25 | public class BeanPopulationExceptionTest extends MessageAndCauseExceptionTestBase { 26 | 27 | @Override 28 | public Exception createMessageException(String message) { 29 | return new BeanPopulationException(message); 30 | } 31 | 32 | @Override 33 | public Exception createMessageAndCauseException(String message, Throwable cause) { 34 | return new BeanPopulationException(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/CollectionFactoryLookupTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories; 22 | 23 | import org.junit.Test; 24 | import org.meanbean.test.BeanTester; 25 | import org.meanbean.test.beans.CollectionPropertyBean; 26 | 27 | public class CollectionFactoryLookupTest { 28 | 29 | @Test 30 | public void test() throws Exception { 31 | BeanTester tester = new BeanTester(); 32 | tester.testBean(CollectionPropertyBean.class); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/NoSuchFactoryExceptionTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories; 22 | 23 | import org.meanbean.test.util.MessageAndCauseExceptionTestBase; 24 | 25 | public class NoSuchFactoryExceptionTest extends MessageAndCauseExceptionTestBase { 26 | 27 | @Override 28 | public Exception createMessageException(String message) { 29 | return new NoSuchFactoryException(message); 30 | } 31 | 32 | @Override 33 | public Exception createMessageAndCauseException(String message, Throwable cause) { 34 | return new NoSuchFactoryException(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/ObjectCreationExceptionTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories; 22 | 23 | import org.meanbean.test.util.MessageAndCauseExceptionTestBase; 24 | 25 | public class ObjectCreationExceptionTest extends MessageAndCauseExceptionTestBase { 26 | 27 | @Override 28 | public Exception createMessageException(String message) { 29 | return new ObjectCreationException(message); 30 | } 31 | 32 | @Override 33 | public Exception createMessageAndCauseException(String message, Throwable cause) { 34 | return new ObjectCreationException(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/ObjectFactoryPluginTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories; 22 | 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | import org.junit.runner.RunWith; 26 | import org.meanbean.util.RandomValueGenerator; 27 | import org.meanbean.util.SimpleRandomValueGenerator; 28 | import org.mockito.runners.MockitoJUnitRunner; 29 | 30 | import java.util.Date; 31 | import java.util.UUID; 32 | 33 | import static org.hamcrest.MatcherAssert.assertThat; 34 | import static org.hamcrest.Matchers.is; 35 | 36 | @RunWith(MockitoJUnitRunner.class) 37 | public class ObjectFactoryPluginTest { 38 | 39 | public static final Class[] FACTORY_CLASSES = { Boolean.class, Byte.class, Short.class, Integer.class, 40 | Long.class, Float.class, Double.class, Character.class, String.class, Date.class, UUID.class }; 41 | 42 | private RandomValueGenerator randomValueGenerator = new SimpleRandomValueGenerator(); 43 | 44 | private FactoryCollection factoryCollection; 45 | 46 | @Before 47 | public void before() { 48 | factoryCollection = new SimpleFactoryCollection(); 49 | } 50 | 51 | @Test 52 | public void shouldRegisterCollectionFactories() throws Exception { 53 | ObjectFactoryPlugin plugin = new ObjectFactoryPlugin(); 54 | for (Class clazz : FACTORY_CLASSES) { 55 | assertThat("Factory for class [" + clazz + "] should not be registered prior to plugin initialization.", 56 | factoryCollection.hasFactory(clazz), is(false)); 57 | } 58 | plugin.initialize(factoryCollection, randomValueGenerator); 59 | for (Class clazz : FACTORY_CLASSES) { 60 | assertThat("Plugin did not register Factory for class [" + clazz + "].", 61 | factoryCollection.hasFactory(clazz), is(true)); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/SimpleFactoryCollection.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories; 22 | 23 | import org.meanbean.lang.Factory; 24 | 25 | import java.lang.reflect.Type; 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | 29 | /** 30 | * Simple concrete implementation of the FactoryCollection interface that should be used for testing only. 31 | * 32 | * @author Graham Williamson 33 | */ 34 | public class SimpleFactoryCollection implements FactoryCollection { 35 | 36 | private final Map> factories = new HashMap<>(); 37 | 38 | @Override 39 | public boolean hasFactory(Type type) throws IllegalArgumentException { 40 | return factories.containsKey(type); 41 | } 42 | 43 | @SuppressWarnings("unchecked") 44 | @Override 45 | public Factory getFactory(Type type) throws IllegalArgumentException, NoSuchFactoryException { 46 | return (Factory) factories.get(type); 47 | } 48 | 49 | @Override 50 | public void addFactory(Class clazz, Factory factory) throws IllegalArgumentException { 51 | factories.put(clazz, factory); 52 | } 53 | 54 | @Override 55 | public void addFactoryLookup(FactoryLookup factoryLookup) { 56 | throw new UnsupportedOperationException(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/basic/BasicFactoryTestBase.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import static org.hamcrest.MatcherAssert.assertThat; 24 | import static org.hamcrest.Matchers.is; 25 | import static org.hamcrest.Matchers.not; 26 | import static org.hamcrest.Matchers.sameInstance; 27 | 28 | import org.junit.Test; 29 | import org.meanbean.lang.Factory; 30 | import org.meanbean.util.RandomValueGenerator; 31 | 32 | public abstract class BasicFactoryTestBase { 33 | 34 | @Test(expected = IllegalArgumentException.class) 35 | public void constructorShouldPreventNullRandomNumberGenerator() throws Exception { 36 | createFactory(null); 37 | } 38 | 39 | @Test 40 | public void createShouldReturnNewObjectEachInvocation() throws Exception { 41 | Factory factory = createFactory(createRandomNumberGenerator()); 42 | T createdObject1 = factory.create(); 43 | T createdObject2 = factory.create(); 44 | assertThat("Factory does not create new objects.", createdObject1, is(not(sameInstance(createdObject2)))); 45 | } 46 | 47 | @Test 48 | public void createShouldReturnDifferentValuesEachInvocation() throws Exception { 49 | Factory factory = createFactory(createRandomNumberGenerator()); 50 | T createdObject1 = factory.create(); 51 | T createdObject2 = factory.create(); 52 | assertThat("Factory does not create different values.", createdObject1, is(not(createdObject2))); 53 | } 54 | 55 | protected abstract RandomValueGenerator createRandomNumberGenerator(); 56 | 57 | protected abstract Factory createFactory(RandomValueGenerator randomValueGenerator); 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/basic/BigDecimalFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import static org.hamcrest.Matchers.is; 24 | import static org.junit.Assert.assertThat; 25 | 26 | import java.math.BigDecimal; 27 | 28 | import org.junit.Test; 29 | import org.meanbean.lang.Factory; 30 | import org.meanbean.util.RandomValueGenerator; 31 | 32 | public class BigDecimalFactoryTest extends BasicFactoryTestBase { 33 | 34 | private static final long RANDOM_LONG_1 = -21474835679L; 35 | 36 | private static final long RANDOM_LONG_2 = 21437935679L; 37 | 38 | @Override 39 | protected Factory createFactory(RandomValueGenerator randomValueGenerator) { 40 | return new BigDecimalFactory(randomValueGenerator); 41 | } 42 | 43 | @Override 44 | protected RandomValueGenerator createRandomNumberGenerator() { 45 | return new ArrayBasedRandomValueGenerator(null, null, new long[] { RANDOM_LONG_1, RANDOM_LONG_2 }, null, null, 46 | null); 47 | } 48 | 49 | @Test 50 | public void createShouldReturnExpectedBigDecimals() throws Exception { 51 | Factory factory = createFactory(createRandomNumberGenerator()); 52 | assertThat("Incorrect random BigDecimal.", factory.create(), is(new BigDecimal(RANDOM_LONG_1))); 53 | assertThat("Incorrect random BigDecimal.", factory.create(), is(new BigDecimal(RANDOM_LONG_2))); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/basic/BigIntegerFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.meanbean.lang.Factory; 24 | import org.meanbean.util.RandomValueGenerator; 25 | import org.meanbean.util.SimpleRandomValueGenerator; 26 | 27 | import java.math.BigInteger; 28 | 29 | public class BigIntegerFactoryTest extends BasicFactoryTestBase { 30 | 31 | @Override 32 | protected RandomValueGenerator createRandomNumberGenerator() { 33 | return new SimpleRandomValueGenerator(); 34 | } 35 | 36 | @Override 37 | protected Factory createFactory(RandomValueGenerator randomValueGenerator) { 38 | return new BigIntegerFactory(randomValueGenerator); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/basic/BooleanFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import static org.hamcrest.MatcherAssert.assertThat; 24 | import static org.hamcrest.Matchers.is; 25 | 26 | import org.junit.Test; 27 | import org.meanbean.lang.Factory; 28 | import org.meanbean.util.RandomValueGenerator; 29 | 30 | public class BooleanFactoryTest extends BasicFactoryTestBase { 31 | 32 | private static final Boolean RANDOM_BOOLEAN_1 = false; 33 | 34 | private static final Boolean RANDOM_BOOLEAN_2 = true; 35 | 36 | @Override 37 | protected Factory createFactory(RandomValueGenerator randomValueGenerator) { 38 | return new BooleanFactory(randomValueGenerator); 39 | } 40 | 41 | @Override 42 | protected RandomValueGenerator createRandomNumberGenerator() { 43 | return new ArrayBasedRandomValueGenerator(null, null, null, null, null, new boolean[] { RANDOM_BOOLEAN_1, 44 | RANDOM_BOOLEAN_2 }); 45 | } 46 | 47 | @Test 48 | public void createShouldReturnExpectedBooleans() throws Exception { 49 | Factory factory = createFactory(createRandomNumberGenerator()); 50 | assertThat("Incorrect random Boolean.", factory.create(), is(RANDOM_BOOLEAN_1)); 51 | assertThat("Incorrect random Boolean.", factory.create(), is(RANDOM_BOOLEAN_2)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/basic/ByteFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import static org.hamcrest.Matchers.is; 24 | import static org.junit.Assert.assertThat; 25 | 26 | import org.junit.Test; 27 | import org.meanbean.lang.Factory; 28 | import org.meanbean.util.RandomValueGenerator; 29 | 30 | public class ByteFactoryTest extends BasicFactoryTestBase { 31 | 32 | private static final byte RANDOM_BYTE_1 = -17; 33 | 34 | private static final byte RANDOM_BYTE_2 = 97; 35 | 36 | @Override 37 | protected Factory createFactory(RandomValueGenerator randomValueGenerator) { 38 | return new ByteFactory(randomValueGenerator); 39 | } 40 | 41 | @Override 42 | protected RandomValueGenerator createRandomNumberGenerator() { 43 | return new ArrayBasedRandomValueGenerator(new byte[][] { { RANDOM_BYTE_1 }, { RANDOM_BYTE_2 } }, null, null, 44 | null, null, null); 45 | } 46 | 47 | @Test 48 | public void createShouldReturnExpectedBytes() throws Exception { 49 | Factory factory = createFactory(createRandomNumberGenerator()); 50 | assertThat("Incorrect random Byte.", factory.create(), is(RANDOM_BYTE_1)); 51 | assertThat("Incorrect random Byte.", factory.create(), is(RANDOM_BYTE_2)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/basic/CharacterFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import static org.hamcrest.Matchers.is; 24 | import static org.junit.Assert.assertThat; 25 | 26 | import org.junit.Test; 27 | import org.meanbean.lang.Factory; 28 | import org.meanbean.util.RandomValueGenerator; 29 | 30 | public class CharacterFactoryTest extends BasicFactoryTestBase { 31 | 32 | private static final double RANDOM_DOUBLE_1 = 0.45; 33 | 34 | private static final double RANDOM_DOUBLE_2 = 0.9345; 35 | 36 | @Override 37 | protected Factory createFactory(RandomValueGenerator randomValueGenerator) { 38 | return new CharacterFactory(randomValueGenerator); 39 | } 40 | 41 | @Override 42 | protected RandomValueGenerator createRandomNumberGenerator() { 43 | return new ArrayBasedRandomValueGenerator(null, null, null, null, new double[] { RANDOM_DOUBLE_1, 44 | RANDOM_DOUBLE_2 }, null); 45 | } 46 | 47 | @Test 48 | public void createShouldReturnCharactersMatchingRandomIntegers() throws Exception { 49 | Factory factory = createFactory(createRandomNumberGenerator()); 50 | assertThat("Incorrect random character.", factory.create().charValue(), 51 | is((char) (Character.MAX_VALUE * RANDOM_DOUBLE_1))); 52 | assertThat("Incorrect random character.", factory.create().charValue(), 53 | is((char) (Character.MAX_VALUE * RANDOM_DOUBLE_2))); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/basic/DateFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import static org.hamcrest.Matchers.is; 24 | import static org.junit.Assert.assertThat; 25 | 26 | import java.util.Date; 27 | 28 | import org.junit.Test; 29 | import org.meanbean.lang.Factory; 30 | import org.meanbean.util.RandomValueGenerator; 31 | 32 | public class DateFactoryTest extends BasicFactoryTestBase { 33 | 34 | private static long RANDOM_LONG_1 = 372036854775807L; 35 | 36 | private static long RANDOM_LONG_2 = -12320685475807L; 37 | 38 | @Override 39 | protected Factory createFactory(RandomValueGenerator randomValueGenerator) { 40 | return new DateFactory(randomValueGenerator); 41 | } 42 | 43 | @Override 44 | protected RandomValueGenerator createRandomNumberGenerator() { 45 | return new ArrayBasedRandomValueGenerator(null, null, new long[] { RANDOM_LONG_1, RANDOM_LONG_2 }, null, null, 46 | null); 47 | } 48 | 49 | @Test 50 | public void createShouldReturnDateWithTimeInMillisMatchingRandomLong() throws Exception { 51 | Factory factory = 52 | createFactory(new ArrayBasedRandomValueGenerator(null, null, new long[] { RANDOM_LONG_1 }, null, null, 53 | null)); 54 | assertThat("Incorrect random date.", factory.create().getTime(), is(RANDOM_LONG_1)); 55 | } 56 | 57 | @Test 58 | public void createShouldReturnDateWithTimeInMillisMatchingAbsoluteRandomLong() throws Exception { 59 | Factory factory = 60 | createFactory(new ArrayBasedRandomValueGenerator(null, null, new long[] { RANDOM_LONG_2 }, null, null, 61 | null)); 62 | assertThat("Incorrect random date.", factory.create().getTime(), is(Math.abs(RANDOM_LONG_2))); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/basic/IntegerFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import static org.hamcrest.Matchers.is; 24 | import static org.junit.Assert.assertThat; 25 | 26 | import org.junit.Test; 27 | import org.meanbean.lang.Factory; 28 | import org.meanbean.util.RandomValueGenerator; 29 | 30 | public class IntegerFactoryTest extends BasicFactoryTestBase { 31 | 32 | private static final int RANDOM_INT_1 = -2147483567; 33 | 34 | private static final int RANDOM_INT_2 = 2143793567; 35 | 36 | @Override 37 | protected Factory createFactory(RandomValueGenerator randomValueGenerator) { 38 | return new IntegerFactory(randomValueGenerator); 39 | } 40 | 41 | @Override 42 | protected RandomValueGenerator createRandomNumberGenerator() { 43 | return new ArrayBasedRandomValueGenerator(null, new int[] { RANDOM_INT_1, RANDOM_INT_2 }, null, null, null, 44 | null); 45 | } 46 | 47 | @Test 48 | public void createShouldReturnExpectedIntegers() throws Exception { 49 | Factory factory = createFactory(createRandomNumberGenerator()); 50 | assertThat("Incorrect random Integer.", factory.create(), is(RANDOM_INT_1)); 51 | assertThat("Incorrect random Integer.", factory.create(), is(RANDOM_INT_2)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/basic/LongFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import static org.hamcrest.Matchers.is; 24 | import static org.junit.Assert.assertThat; 25 | 26 | import org.junit.Test; 27 | import org.meanbean.lang.Factory; 28 | import org.meanbean.util.RandomValueGenerator; 29 | 30 | public class LongFactoryTest extends BasicFactoryTestBase { 31 | 32 | private static long RANDOM_LONG_1 = 372036854775807L; 33 | 34 | private static long RANDOM_LONG_2 = -12320685475807L; 35 | 36 | @Override 37 | protected Factory createFactory(RandomValueGenerator randomValueGenerator) { 38 | return new LongFactory(randomValueGenerator); 39 | } 40 | 41 | @Override 42 | protected RandomValueGenerator createRandomNumberGenerator() { 43 | return new ArrayBasedRandomValueGenerator(null, null, new long[] { RANDOM_LONG_1, RANDOM_LONG_2 }, null, null, 44 | null); 45 | } 46 | 47 | @Test 48 | public void createShouldReturnExpectedLongs() throws Exception { 49 | Factory factory = createFactory(createRandomNumberGenerator()); 50 | assertThat("Incorrect random Long.", factory.create(), is(RANDOM_LONG_1)); 51 | assertThat("Incorrect random Long.", factory.create(), is(RANDOM_LONG_2)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/basic/RandomFactoryBaseTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import org.junit.Test; 24 | import org.meanbean.util.RandomValueGenerator; 25 | import org.meanbean.util.SimpleRandomValueGenerator; 26 | 27 | import static org.hamcrest.MatcherAssert.assertThat; 28 | import static org.hamcrest.Matchers.is; 29 | import static org.hamcrest.Matchers.not; 30 | import static org.hamcrest.Matchers.nullValue; 31 | 32 | public class RandomFactoryBaseTest { 33 | 34 | @Test(expected = IllegalArgumentException.class) 35 | public void constructorShouldPreventNullRandomNumberGenerator() throws Exception { 36 | new SimpleFactory(null); 37 | } 38 | 39 | @Test 40 | public void getRandomNumberGeneratorShouldReturnRandomNumberGenerator() throws Exception { 41 | RandomValueGenerator randomValueGenerator = new SimpleRandomValueGenerator(); 42 | SimpleFactory factory = new SimpleFactory(randomValueGenerator); 43 | assertThat("RandomNumberGenerator should not be null.", factory.getRandomValueGenerator(), is(not(nullValue()))); 44 | } 45 | 46 | static class SimpleFactory extends RandomFactoryBase { 47 | 48 | public SimpleFactory(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException { 49 | super(randomValueGenerator); 50 | } 51 | 52 | @Override 53 | public T create() { 54 | return null; // Not relevant in testing the base class - do nothing 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/basic/StringFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.basic; 22 | 23 | import static org.hamcrest.Matchers.is; 24 | import static org.junit.Assert.assertThat; 25 | 26 | import org.junit.Test; 27 | import org.meanbean.lang.Factory; 28 | import org.meanbean.util.RandomValueGenerator; 29 | 30 | public class StringFactoryTest extends BasicFactoryTestBase { 31 | 32 | private static final long RANDOM_LONG_1 = 841027364; 33 | 34 | private static final long RANDOM_LONG_2 = -5928352; 35 | 36 | @Override 37 | protected Factory createFactory(RandomValueGenerator randomValueGenerator) { 38 | return new StringFactory(randomValueGenerator); 39 | } 40 | 41 | @Override 42 | protected RandomValueGenerator createRandomNumberGenerator() { 43 | return new ArrayBasedRandomValueGenerator(null, null, new long[] { RANDOM_LONG_1, RANDOM_LONG_2 }, null, null, 44 | null); 45 | } 46 | 47 | @Test 48 | public void createShouldReturnExpectedStrings() throws Exception { 49 | Factory factory = createFactory(createRandomNumberGenerator()); 50 | assertThat("Incorrect random String.", factory.create(), is("TestString:[" + RANDOM_LONG_1 + "]")); 51 | assertThat("Incorrect random String.", factory.create(), is("TestString:[" + RANDOM_LONG_2 + "]")); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/beans/BeanCreationExceptionTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.beans; 22 | 23 | import org.meanbean.test.util.MessageAndCauseExceptionTestBase; 24 | 25 | public class BeanCreationExceptionTest extends MessageAndCauseExceptionTestBase { 26 | 27 | @Override 28 | public Exception createMessageException(String message) { 29 | return new BeanCreationException(message); 30 | } 31 | 32 | @Override 33 | public Exception createMessageAndCauseException(String message, Throwable cause) { 34 | return new BeanCreationException(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/factories/time/RandomClockTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.factories.time; 22 | 23 | import org.junit.Test; 24 | import org.meanbean.util.SimpleRandomValueGenerator; 25 | 26 | import java.time.Instant; 27 | import java.time.ZoneId; 28 | import java.time.ZoneOffset; 29 | import java.util.List; 30 | import java.util.function.Supplier; 31 | import java.util.stream.Collectors; 32 | import java.util.stream.IntStream; 33 | 34 | import static org.assertj.core.api.Assertions.assertThat; 35 | 36 | public class RandomClockTest { 37 | 38 | private int count = 10; 39 | private RandomClock randomClock = new RandomClock(new SimpleRandomValueGenerator()); 40 | 41 | @Test 42 | public void testGetZone() { 43 | List zones = nUniqueCopies(randomClock::getZone); 44 | 45 | assertThat(zones) 46 | .allMatch(this::isValidZone) 47 | .hasSizeGreaterThan(5); 48 | } 49 | 50 | @Test 51 | public void testGetInstant() { 52 | List instants = nUniqueCopies(randomClock::instant); 53 | 54 | assertThat(instants) 55 | .hasSize(10); 56 | } 57 | 58 | @Test(expected = UnsupportedOperationException.class) 59 | public void testWithZone() { 60 | randomClock.withZone(ZoneOffset.UTC); 61 | } 62 | 63 | private List nUniqueCopies(Supplier supplier) { 64 | return IntStream.range(0, count) 65 | .mapToObj(num -> supplier.get()) 66 | .distinct() 67 | .collect(Collectors.toList()); 68 | } 69 | 70 | private boolean isValidZone(ZoneId zoneId) { 71 | return ZoneId.getAvailableZoneIds().contains(zoneId.getId()); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/BasicBeanTesterDomainTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test; 22 | 23 | import static org.junit.Assert.assertTrue; 24 | import static org.junit.Assert.fail; 25 | 26 | import org.junit.Before; 27 | import org.junit.Test; 28 | import org.junit.runner.RunWith; 29 | import org.meanbean.test.beans.domain.EmployeeWithBrokenManagerSetter; 30 | import org.mockito.runners.MockitoJUnitRunner; 31 | 32 | @RunWith(MockitoJUnitRunner.class) 33 | public class BasicBeanTesterDomainTest { 34 | 35 | private BeanTester beanTester; 36 | 37 | @Before 38 | public void before() { 39 | beanTester = new BeanTester(); 40 | } 41 | 42 | @Test 43 | public void testBeanShouldThrowAssertionErrorWhenEmployeeManagerSetterDoesNotChangeFieldAsExpected() 44 | throws Exception { 45 | AssertionError assertionError = null; 46 | try { 47 | beanTester.testBean(EmployeeWithBrokenManagerSetter.class); 48 | fail("AssertionError should have been thrown."); 49 | } catch (AssertionError e) { 50 | assertionError = e; 51 | } 52 | assertTrue(assertionError.getMessage().startsWith("Property [manager] getter did not return test value.")); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/BeanTestExceptionTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test; 22 | 23 | import org.meanbean.test.util.MessageAndCauseExceptionTestBase; 24 | 25 | public class BeanTestExceptionTest extends MessageAndCauseExceptionTestBase { 26 | 27 | @Override 28 | public Exception createMessageException(String message) { 29 | return new BeanTestException(message); 30 | } 31 | 32 | @Override 33 | public Exception createMessageAndCauseException(String message, Throwable cause) { 34 | return new BeanTestException(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/BeanTesterDualWritingBeanTest.java: -------------------------------------------------------------------------------- 1 | package org.meanbean.test; 2 | 3 | import org.junit.Rule; 4 | import org.junit.Test; 5 | import org.junit.rules.ExpectedException; 6 | 7 | import static org.meanbean.test.Warning.SETTER_SIDE_EFFECT; 8 | 9 | public class BeanTesterDualWritingBeanTest { 10 | 11 | @Rule 12 | public final ExpectedException thrown = ExpectedException.none(); 13 | 14 | @Test 15 | public void testDualWriteFails() { 16 | thrown.expect(AssertionError.class); 17 | thrown.expectMessage("Property [name] appears to have a side-effect on another property [title]"); 18 | 19 | BeanVerifier.forClass(DualWritingSetterBean.class) 20 | .verifyGettersAndSetters(); 21 | } 22 | 23 | @Test 24 | public void testDualWriteSuppressed() { 25 | BeanVerifier.forClass(DualWritingSetterBean.class) 26 | .withSettings(settings -> settings.suppressWarning(SETTER_SIDE_EFFECT)) 27 | .verifyGettersAndSetters(); 28 | } 29 | 30 | public static class DualWritingSetterBean { 31 | private String name; 32 | private String title; 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | // the setter writes to two fields 39 | public void setName(String name) { 40 | this.name = name; 41 | this.title = name; 42 | } 43 | 44 | public String getTitle() { 45 | return title; 46 | } 47 | 48 | public void setTitle(String title) { 49 | this.title = title; 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/EqualityTestTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test; 22 | 23 | import static org.hamcrest.MatcherAssert.assertThat; 24 | import static org.hamcrest.Matchers.is; 25 | 26 | import org.junit.Test; 27 | import org.meanbean.test.beans.Bean; 28 | import org.meanbean.test.beans.BeanFactory; 29 | import org.meanbean.test.internal.EqualityTest; 30 | 31 | public class EqualityTestTest { 32 | 33 | private static final BeanFactory beanFactory = new BeanFactory(); 34 | 35 | @Test 36 | public void absoluteShouldReturnTrueForSameInstance() throws Exception { 37 | Bean x = beanFactory.create(); 38 | assertThat("Incorrect EqualityTest result.", EqualityTest.ABSOLUTE.test(x, x), is(true)); 39 | } 40 | 41 | @Test 42 | public void absoluteShouldReturnFalseForDifferentInstances() throws Exception { 43 | Bean x = beanFactory.create(); 44 | Bean y = beanFactory.create(); 45 | assertThat("Incorrect EqualityTest result.", EqualityTest.ABSOLUTE.test(x, y), is(false)); 46 | } 47 | 48 | @Test 49 | public void logicalShouldReturnTrueForLogicallyEquivalentObjects() throws Exception { 50 | Bean x = beanFactory.create(); 51 | Bean y = beanFactory.create(); 52 | assertThat("Incorrect EqualityTest result.", EqualityTest.LOGICAL.test(x, y), is(true)); 53 | } 54 | 55 | @Test 56 | public void logicalShouldReturnFalseForNonLogicallyEquivalentObjects() throws Exception { 57 | Bean x = beanFactory.create(); 58 | Bean y = beanFactory.create(); 59 | y.setName(y.getName() + "_DIFFERENT"); 60 | assertThat("Incorrect EqualityTest result.", EqualityTest.LOGICAL.test(x, y), is(false)); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/ArrayPropertyBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import java.util.Arrays; 24 | 25 | public class ArrayPropertyBean { 26 | 27 | private byte[] data; 28 | 29 | public byte[] getData() { 30 | return data; 31 | } 32 | 33 | public void setData(byte[] data) { 34 | this.data = data; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) { 40 | return true; 41 | } 42 | if (obj == null) { 43 | return false; 44 | } 45 | if (getClass() != obj.getClass()) { 46 | return false; 47 | } 48 | ArrayPropertyBean other = (ArrayPropertyBean) obj; 49 | return Arrays.equals(data, other.data); 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | return Arrays.hashCode(data); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/ArrayPropertyBeanWithConstructor.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | public class ArrayPropertyBeanWithConstructor extends ArrayPropertyBean { 24 | 25 | public ArrayPropertyBeanWithConstructor(byte[] data) { 26 | this.setData(data); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/Bean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import java.util.Objects; 24 | 25 | /** 26 | * A simple single property bean with correctly implemented equals and hashCode methods that should be used only for 27 | * testing. 28 | * 29 | * @author Graham Williamson 30 | */ 31 | public class Bean { 32 | 33 | private String name; 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | return Objects.hash(name); 46 | } 47 | 48 | @Override 49 | public boolean equals(Object obj) { 50 | if (this == obj) 51 | return true; 52 | if (obj == null) 53 | return false; 54 | if (getClass() != obj.getClass()) 55 | return false; 56 | Bean other = (Bean) obj; 57 | return Objects.equals(name, other.name); 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "Bean [name=" + name + "]"; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/BeanFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.EquivalentFactory; 24 | 25 | /** 26 | * Factory that creates logically equivalent Bean instances. This should only be used for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class BeanFactory implements EquivalentFactory { 31 | 32 | public static final String NAME = "MY_NAME"; 33 | 34 | @Override 35 | public Bean create() { 36 | Bean bean = new Bean(); 37 | bean.setName(NAME); 38 | return bean; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/BeanWithBadGetterMethod.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A simple single property bean with correctly implemented equals and hashCode methods, but with a getter that throws a 25 | * RuntimeException. This class should only be used for testing. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class BeanWithBadGetterMethod extends Bean { 30 | 31 | @Override 32 | public String getName() { 33 | throw new RuntimeException("BAD SETTER METHOD"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/BeanWithBadSetterMethod.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A simple single property bean with correctly implemented equals and hashCode methods, but with a setter that throws a 25 | * RuntimeException. Since the setter cannot be called, the getter returns a constant value. This class should only be 26 | * used for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class BeanWithBadSetterMethod extends Bean { 31 | 32 | @Override 33 | public void setName(String name) { 34 | throw new RuntimeException("BAD SETTER METHOD"); 35 | } 36 | 37 | @Override 38 | public String getName() { 39 | return "TEST_VALUE"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/BeanWithNonBeanProperty.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A bean with a simple property and a non-Bean property, meaning that test data cannot be dynamically created for the 25 | * non-Bean property. The equals and hashCode methods have been implemented correctly. This class should only be used 26 | * for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class BeanWithNonBeanProperty extends Bean { 31 | 32 | private NonBean nonBean; 33 | 34 | public NonBean getNonBean() { 35 | return nonBean; 36 | } 37 | 38 | public void setNonBean(NonBean nonBean) { 39 | this.nonBean = nonBean; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | StringBuilder builder = new StringBuilder(); 45 | builder.append("CompositeBean [nonBean=").append(getNonBean()).append("]"); 46 | return builder.toString(); 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | final int prime = 31; 52 | int result = super.hashCode(); 53 | result = prime * result + ((nonBean == null) ? 0 : nonBean.hashCode()); 54 | return result; 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | if (this == obj) 60 | return true; 61 | if (!super.equals(obj)) 62 | return false; 63 | if (getClass() != obj.getClass()) 64 | return false; 65 | BeanWithNonBeanProperty other = (BeanWithNonBeanProperty) obj; 66 | if (nonBean == null) { 67 | if (other.nonBean != null) 68 | return false; 69 | } else if (!nonBean.equals(other.nonBean)) 70 | return false; 71 | return true; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/BrokenEqualsMultiPropertyBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A bean with multiple properties, but with a broken hashCode and equals method that neglect to evaluate all 25 | * properties. This class should only be used for testing. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class BrokenEqualsMultiPropertyBean extends MultiPropertyBean { 30 | 31 | @Override 32 | public int hashCode() { 33 | final int prime = 31; 34 | int result = 1; 35 | result = prime * result + ((getFirstName() == null) ? 0 : getFirstName().hashCode()); 36 | return result; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object obj) { 41 | if (this == obj) 42 | return true; 43 | if (obj == null) 44 | return false; 45 | if (getClass() != obj.getClass()) 46 | return false; 47 | MultiPropertyBean other = (MultiPropertyBean) obj; 48 | if (getFirstName() == null) { 49 | if (other.getFirstName() != null) 50 | return false; 51 | } else if (!getFirstName().equals(other.getFirstName())) 52 | return false; 53 | return true; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/ClassIncrementalHashCodeBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * Extension of Bean that returns an incremental hashCode value shared by all instances of the class, starting from 1. 25 | * This should only be used for testing. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class ClassIncrementalHashCodeBean extends Bean { 30 | 31 | private static int NEXT_HASH_CODE = 1; 32 | 33 | /** 34 | * Returns an incremental hashCode value starting from 1. 35 | * 36 | * @return Hash code value. 37 | */ 38 | @Override 39 | public int hashCode() { 40 | return NEXT_HASH_CODE++; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/CollectionPropertyBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import java.util.Date; 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.Set; 27 | import java.util.UUID; 28 | 29 | import static org.assertj.core.api.Assertions.assertThat; 30 | 31 | public class CollectionPropertyBean { 32 | 33 | private List dates; 34 | 35 | private Set longs; 36 | 37 | private Map map; 38 | 39 | private List> doubles; 40 | 41 | public List getDates() { 42 | return dates; 43 | } 44 | 45 | public void setDates(List dates) { 46 | assertThat(dates).hasOnlyElementsOfType(Date.class); 47 | this.dates = dates; 48 | } 49 | 50 | public Set getLongs() { 51 | return longs; 52 | } 53 | 54 | public void setLongs(Set longs) { 55 | assertThat(longs).hasOnlyElementsOfType(Long.class); 56 | this.longs = longs; 57 | } 58 | 59 | public Map getMap() { 60 | return map; 61 | } 62 | 63 | public void setMap(Map map) { 64 | assertThat(map.keySet()).hasOnlyElementsOfType(Integer.class); 65 | assertThat(map.values()).hasOnlyElementsOfType(UUID.class); 66 | this.map = map; 67 | } 68 | 69 | public List> getDoubles() { 70 | return doubles; 71 | } 72 | 73 | public void setDoubles(List> doubles) { 74 | assertThat(doubles).hasOnlyElementsOfType(Set.class); 75 | assertThat(doubles).allSatisfy(set -> assertThat(set).hasOnlyElementsOfType(Double.class)); 76 | this.doubles = doubles; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/ComplexBeanFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.EquivalentFactory; 24 | 25 | import java.util.Calendar; 26 | import java.util.Date; 27 | 28 | /** 29 | * Factory that creates logically equivalent ComplexBean instances. This should only be used for testing. 30 | * 31 | * @author Graham Williamson 32 | */ 33 | public class ComplexBeanFactory implements EquivalentFactory { 34 | 35 | private static final Date DATE_OF_BIRTH; 36 | static { 37 | Calendar calendar = Calendar.getInstance(); 38 | calendar.set(2010, 7, 12, 16, 31, 1); 39 | DATE_OF_BIRTH = calendar.getTime(); 40 | } 41 | 42 | @Override 43 | public ComplexBean create() { 44 | ComplexBean bean = new ComplexBean(); 45 | bean.setId(1); 46 | bean.setFirstName("TEST_FIRST_NAME"); 47 | bean.setLastName("TEST_LAST_NAME"); 48 | bean.setDateOfBirth(DATE_OF_BIRTH); 49 | bean.setFavouriteNumber(1234); 50 | return bean; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/CounterDrivenEqualsBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A bean whose equals method is driven by a counter that returns false on a specified invocation number. This class 25 | * should only be used for testing. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class CounterDrivenEqualsBean extends Bean { 30 | 31 | private final int falseInvocationIndex; 32 | 33 | private int counter; 34 | 35 | public CounterDrivenEqualsBean(int falseInvocationIndex) { 36 | this.falseInvocationIndex = falseInvocationIndex; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object obj) { 41 | if (counter++ == falseInvocationIndex) { 42 | return false; 43 | } 44 | return super.equals(obj); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/CounterDrivenEqualsBeanFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.EquivalentFactory; 24 | 25 | /** 26 | * A factory that creates CounterDrivenEqualsBeans. This class should only be used for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class CounterDrivenEqualsBeanFactory implements EquivalentFactory { 31 | 32 | public static final String NAME = "TEST_NAME"; 33 | 34 | private final int falseInvocationIndex; 35 | 36 | public CounterDrivenEqualsBeanFactory(int falseInvocationIndex) { 37 | this.falseInvocationIndex = falseInvocationIndex; 38 | } 39 | 40 | @Override 41 | public CounterDrivenEqualsBean create() { 42 | CounterDrivenEqualsBean bean = new CounterDrivenEqualsBean(falseInvocationIndex); 43 | bean.setName(NAME); 44 | return bean; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/CounterDrivenHashCodeBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A bean that returns the value of an incrementing counter when hashCode() is called. This should only be 25 | * used for testing. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class CounterDrivenHashCodeBean extends Bean { 30 | 31 | private int counter; 32 | 33 | @Override 34 | public int hashCode() { 35 | return counter++; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/DifferentTypeAcceptingBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A bean whose equals method returns true when compared with an object of a different type. This class should only be 25 | * used for testing. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class DifferentTypeAcceptingBean extends Bean { 30 | 31 | @Override 32 | public boolean equals(Object obj) { 33 | if ((obj != null) && (getClass() != obj.getClass())) { 34 | return true; 35 | } 36 | return super.equals(obj); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/DifferentTypeAcceptingBeanFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.EquivalentFactory; 24 | 25 | /** 26 | * Factory that creates empty DifferentTypeAcceptingBean instances. This should only be used for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class DifferentTypeAcceptingBeanFactory implements EquivalentFactory { 31 | 32 | @Override 33 | public DifferentTypeAcceptingBean create() { 34 | return new DifferentTypeAcceptingBean(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/FieldDrivenEqualsBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A bean that returns a predetermined value when equals() is called. This should only be used for testing. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public class FieldDrivenEqualsBean extends Bean { 29 | 30 | private final boolean equalsResult; 31 | 32 | public FieldDrivenEqualsBean(boolean equalsResult) { 33 | this.equalsResult = equalsResult; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object obj) { 38 | return equalsResult; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/FieldDrivenEqualsBeanFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.EquivalentFactory; 24 | 25 | /** 26 | * Factory that creates FieldDrivenEqualsBean instances, populated with the specified equalsResult. This should only be 27 | * used for testing. 28 | * 29 | * @author Graham Williamson 30 | */ 31 | public class FieldDrivenEqualsBeanFactory implements EquivalentFactory { 32 | 33 | private final boolean equalsResult; 34 | 35 | public FieldDrivenEqualsBeanFactory(boolean equalsResult) { 36 | this.equalsResult = equalsResult; 37 | } 38 | 39 | @Override 40 | public FieldDrivenEqualsBean create() { 41 | FieldDrivenEqualsBean bean = new FieldDrivenEqualsBean(equalsResult); 42 | bean.setName("TEST_NAME"); 43 | return bean; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/FieldDrivenHashCodeBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A bean that returns a predetermined value when hashCode() is called. This should only be used for 25 | * testing. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class FieldDrivenHashCodeBean extends Bean { 30 | 31 | private final int hashCode; 32 | 33 | public FieldDrivenHashCodeBean(int hashCode) { 34 | this.hashCode = hashCode; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return hashCode; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/FluentPropertyBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import java.util.Objects; 24 | 25 | public class FluentPropertyBean { 26 | 27 | private String data; 28 | 29 | public String getData() { 30 | return data; 31 | } 32 | 33 | public FluentPropertyBean setData(String data) { 34 | this.data = data; 35 | return this; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object obj) { 40 | if (this == obj) { 41 | return true; 42 | } 43 | if (obj == null) { 44 | return false; 45 | } 46 | if (!(obj instanceof FluentPropertyBean)) { 47 | return false; 48 | } 49 | FluentPropertyBean other = (FluentPropertyBean) obj; 50 | return Objects.equals(data, other.data); 51 | } 52 | 53 | @Override 54 | public int hashCode() { 55 | return Objects.hash(data); 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return data; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/FluentPropertyBeanTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.junit.Test; 24 | import org.meanbean.test.BeanVerifier; 25 | 26 | import static org.assertj.core.api.Assertions.assertThatCode; 27 | import static org.mockito.Matchers.anyString; 28 | import static org.mockito.Mockito.doThrow; 29 | import static org.mockito.Mockito.mock; 30 | 31 | public class FluentPropertyBeanTest { 32 | 33 | @Test 34 | public void testOk() { 35 | BeanVerifier.forClass(FluentPropertyBean.class) 36 | .editSettings() 37 | .setDefaultIterations(1) 38 | .edited() 39 | .verify(); 40 | } 41 | 42 | @Test 43 | public void testFails() { 44 | assertThatCode(() -> { 45 | runTestForcingException(); 46 | }).hasRootCauseMessage("fake exception"); 47 | } 48 | 49 | private void runTestForcingException() { 50 | BeanVerifier.forClass(FluentPropertyBean.class) 51 | .editSettings() 52 | .registerFactory(FluentPropertyBean.class, () -> { 53 | FluentPropertyBean bean = mock(FluentPropertyBean.class); 54 | doThrow(new IllegalStateException("fake exception")) 55 | .when(bean) 56 | .setData(anyString()); 57 | return bean; 58 | }) 59 | .setDefaultIterations(1) 60 | .edited() 61 | .verify(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/IncrementalStringFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.Factory; 24 | 25 | /** 26 | * Factory that creates Strings with an increasing number in them. This should only be used for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class IncrementalStringFactory implements Factory { 31 | 32 | private int counter; 33 | 34 | @Override 35 | public String create() { 36 | return "TEST_STRING_" + counter++; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/InstanceIncrementalHashCodeBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * Extension of Bean that returns an incremental hashCode value starting from 1. This should only be used for testing. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public class InstanceIncrementalHashCodeBean extends Bean { 29 | 30 | private int nextHashCode = 1; 31 | 32 | /** 33 | * Returns an incremental hashCode value starting from 1. 34 | * 35 | * @return Hash code value. 36 | */ 37 | @Override 38 | public int hashCode() { 39 | return nextHashCode++; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/InvocationCountingFactoryWrapper.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.Factory; 24 | 25 | /** 26 | * Factory wrapper (decorator) that keeps count of the number of times create() is invoked, delegating the 27 | * actual creation of the object to the wrapped factory, specified at construction. 28 | * 29 | * This should only be used for testing. 30 | * 31 | * @author Graham Williamson 32 | */ 33 | public class InvocationCountingFactoryWrapper implements Factory { 34 | 35 | private final Factory factory; 36 | 37 | private int invocationCount = 0; 38 | 39 | public InvocationCountingFactoryWrapper(Factory factory) { 40 | this.factory = factory; 41 | } 42 | 43 | @Override 44 | public T create() { 45 | invocationCount++; 46 | return factory.create(); 47 | } 48 | 49 | public int getInvocationCount() { 50 | return invocationCount; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/MultiPropertyBeanFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.EquivalentFactory; 24 | 25 | /** 26 | * Factory that creates logically equivalent MultiPropertyBean instances. This should only be used for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class MultiPropertyBeanFactory implements EquivalentFactory { 31 | 32 | @Override 33 | public MultiPropertyBean create() { 34 | MultiPropertyBean bean = new MultiPropertyBean(); 35 | bean.setFirstName("FIRST_NAME"); 36 | bean.setLastName("LAST_NAME"); 37 | return bean; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/NonBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A single property object that does not have a no-arg constructor and therefore is not a JavaBean. The equals and 25 | * hashCode methods are implemented correctly. This class should be used for testing only. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class NonBean { 30 | 31 | private final String value; 32 | 33 | public NonBean(String value) { 34 | this.value = value; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | final int prime = 31; 40 | int result = 1; 41 | result = prime * result + ((value == null) ? 0 : value.hashCode()); 42 | return result; 43 | } 44 | 45 | @Override 46 | public boolean equals(Object obj) { 47 | if (this == obj) 48 | return true; 49 | if (obj == null) 50 | return false; 51 | if (getClass() != obj.getClass()) 52 | return false; 53 | NonBean other = (NonBean) obj; 54 | if (value == null) { 55 | if (other.value != null) 56 | return false; 57 | } else if (!value.equals(other.value)) 58 | return false; 59 | return true; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/NonEqualBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * Extension of Bean that never considers another Bean logically equivalent. This should only be used for testing. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public class NonEqualBean extends Bean { 29 | 30 | /** 31 | * Always returns false. 32 | * 33 | * @param obj 34 | * Not used. 35 | * 36 | * @return false, always. 37 | */ 38 | @Override 39 | public boolean equals(Object obj) { 40 | return false; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/NonReflexiveBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A bean whose equals method returns false when compared with itself. This class should only be used for testing. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public class NonReflexiveBean extends Bean { 29 | 30 | @Override 31 | public boolean equals(Object obj) { 32 | if (obj == this) { 33 | return false; 34 | } 35 | return super.equals(obj); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/NonReflexiveBeanFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.EquivalentFactory; 24 | 25 | /** 26 | * Factory that creates empty NonReflexiveBean instances. This should only be used for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class NonReflexiveBeanFactory implements EquivalentFactory { 31 | 32 | @Override 33 | public NonReflexiveBean create() { 34 | return new NonReflexiveBean(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/NullAcceptingBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * A bean whose equals method returns true when compared with null. This class should only be used for testing. 25 | * 26 | * @author Graham Williamson 27 | */ 28 | public class NullAcceptingBean extends Bean { 29 | 30 | @Override 31 | public boolean equals(Object obj) { 32 | if (obj == null) { 33 | return true; 34 | } 35 | return super.equals(obj); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/NullAcceptingBeanFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.EquivalentFactory; 24 | 25 | /** 26 | * Factory that creates empty NullAcceptingBean instances. This should only be used for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class NullAcceptingBeanFactory implements EquivalentFactory { 31 | 32 | @Override 33 | public NullAcceptingBean create() { 34 | return new NullAcceptingBean(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/NullEquivalentFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.EquivalentFactory; 24 | 25 | /** 26 | * A factory that always returns null. This should only be used for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class NullEquivalentFactory implements EquivalentFactory { 31 | 32 | @Override 33 | public Object create() { 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/NullFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.Factory; 24 | 25 | /** 26 | * A factory that always returns null. This should only be used for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class NullFactory implements Factory { 31 | 32 | @Override 33 | public Object create() { 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/PackagePrivateConstructorObject.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * An object that has a default/package-private no-argument constructor and no other constructor. This class should be 25 | * used for testing only. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class PackagePrivateConstructorObject { 30 | 31 | PackagePrivateConstructorObject() { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/PrivateConstructorObject.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | /** 24 | * An object that has a private no-argument constructor and no other constructor. This class should be used for testing 25 | * only. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class PrivateConstructorObject { 30 | 31 | private PrivateConstructorObject() { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/SelfReferencingBeanFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans; 22 | 23 | import org.meanbean.lang.EquivalentFactory; 24 | 25 | /** 26 | * Factory that creates logically equivalent SelfReferencingBean instances. This should only be used for testing. 27 | * 28 | * @author Graham Williamson 29 | */ 30 | public class SelfReferencingBeanFactory implements EquivalentFactory { 31 | 32 | private static final SelfReferencingBean parent = new SelfReferencingBean(); 33 | static { 34 | parent.setFirstName("PARENT_FIRST_NAME"); 35 | } 36 | 37 | @Override 38 | public SelfReferencingBean create() { 39 | SelfReferencingBean bean = new SelfReferencingBean(); 40 | bean.setFirstName("TEST_FIRST_NAME"); 41 | bean.setLastName("TEST_LAST_NAME"); 42 | bean.setParent(parent); 43 | return bean; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/domain/Country.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.domain; 22 | 23 | public enum Country { 24 | 25 | UK, USA, FRANCE, GERMANY, IRELAND, SPAIN, PORTUGAL 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/domain/County.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.domain; 22 | 23 | public enum County { 24 | 25 | SURREY, LONDON, DORSET, DEVON 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/domain/Customer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.domain; 22 | 23 | import java.util.Collection; 24 | import java.util.Set; 25 | 26 | 27 | public class Customer extends Person { 28 | 29 | private Set
addresses; 30 | 31 | private Collection orders; 32 | 33 | public Set
getAddresses() { 34 | return addresses; 35 | } 36 | 37 | public void setAddresses(Set
addresses) { 38 | this.addresses = addresses; 39 | } 40 | 41 | public Collection getOrders() { 42 | return orders; 43 | } 44 | 45 | public void setOrders(Collection orders) { 46 | this.orders = orders; 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | final int prime = 31; 52 | int result = super.hashCode(); 53 | result = prime * result + ((addresses == null) ? 0 : addresses.hashCode()); 54 | result = prime * result + ((orders == null) ? 0 : orders.hashCode()); 55 | return result; 56 | } 57 | 58 | @Override 59 | public boolean equals(Object obj) { 60 | if (this == obj) 61 | return true; 62 | if (!super.equals(obj)) 63 | return false; 64 | if (getClass() != obj.getClass()) 65 | return false; 66 | Customer other = (Customer) obj; 67 | if (addresses == null) { 68 | if (other.addresses != null) 69 | return false; 70 | } else if (!addresses.equals(other.addresses)) 71 | return false; 72 | if (orders == null) { 73 | if (other.orders != null) 74 | return false; 75 | } else if (!orders.equals(other.orders)) 76 | return false; 77 | return true; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/domain/EmployeeId.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.domain; 22 | 23 | import java.util.Objects; 24 | 25 | public class EmployeeId { 26 | 27 | private String id; 28 | 29 | public String getId() { 30 | return id; 31 | } 32 | 33 | public void setId(String id) { 34 | this.id = id; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return Objects.hash(id); 40 | } 41 | 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (this == obj) 45 | return true; 46 | if (obj == null) 47 | return false; 48 | if (getClass() != obj.getClass()) 49 | return false; 50 | EmployeeId other = (EmployeeId) obj; 51 | return Objects.equals(id, other.id); 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "EmployeeId [id=" + id + "]"; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/domain/EmployeeWithBrokenManagerSetter.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.domain; 22 | 23 | public class EmployeeWithBrokenManagerSetter extends Employee { 24 | 25 | @Override 26 | public void setManager(Employee manager) { 27 | Employee myManager = new Employee(); 28 | myManager.setFirstName("MY_MANAGER"); 29 | super.setManager(myManager); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/domain/Item.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.domain; 22 | 23 | public class Item { 24 | 25 | private Long id; 26 | 27 | private Product product; 28 | 29 | private int quantity; 30 | 31 | public Long getId() { 32 | return id; 33 | } 34 | 35 | public void setId(Long id) { 36 | this.id = id; 37 | } 38 | 39 | public Product getProduct() { 40 | return product; 41 | } 42 | 43 | public void setProduct(Product product) { 44 | this.product = product; 45 | } 46 | 47 | public int getQuantity() { 48 | return quantity; 49 | } 50 | 51 | public void setQuantity(int quantity) { 52 | this.quantity = quantity; 53 | } 54 | 55 | @Override 56 | public int hashCode() { 57 | final int prime = 31; 58 | int result = 1; 59 | result = prime * result + ((product == null) ? 0 : product.hashCode()); 60 | result = prime * result + quantity; 61 | return result; 62 | } 63 | 64 | @Override 65 | public boolean equals(Object obj) { 66 | if (this == obj) 67 | return true; 68 | if (obj == null) 69 | return false; 70 | if (getClass() != obj.getClass()) 71 | return false; 72 | Item other = (Item) obj; 73 | if (product == null) { 74 | if (other.product != null) 75 | return false; 76 | } else if (!product.equals(other.product)) 77 | return false; 78 | if (quantity != other.quantity) 79 | return false; 80 | return true; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/domain/Money.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.domain; 22 | 23 | public class Money { 24 | 25 | // TODO IMPLEMENT 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/domain/NonReflexiveEqualsAddress.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.domain; 22 | 23 | 24 | /** 25 | * An Address whose equals method returns false when compared with itself. This class should only be used for testing. 26 | * 27 | * @author Graham Williamson 28 | */ 29 | public class NonReflexiveEqualsAddress extends Address { 30 | 31 | @Override 32 | public boolean equals(Object obj) { 33 | if (obj == this) { 34 | return false; 35 | } 36 | return super.equals(obj); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/domain/Rating.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.domain; 22 | 23 | public enum Rating { 24 | 25 | VERY_BAD, BAD, AVERAGE, GOOD, VERY_GOOD 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/domain/ShippingCompany.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.domain; 22 | 23 | import java.util.Collection; 24 | 25 | 26 | public class ShippingCompany extends Company { 27 | 28 | private Collection
depots; 29 | 30 | public Collection
getDepots() { 31 | return depots; 32 | } 33 | 34 | public void setDepots(Collection
depots) { 35 | this.depots = depots; 36 | } 37 | 38 | @Override 39 | public int hashCode() { 40 | final int prime = 31; 41 | int result = super.hashCode(); 42 | result = prime * result + ((depots == null) ? 0 : depots.hashCode()); 43 | return result; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object obj) { 48 | if (this == obj) 49 | return true; 50 | if (!super.equals(obj)) 51 | return false; 52 | if (getClass() != obj.getClass()) 53 | return false; 54 | ShippingCompany other = (ShippingCompany) obj; 55 | if (depots == null) { 56 | if (other.depots != null) 57 | return false; 58 | } else if (!depots.equals(other.depots)) 59 | return false; 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/domain/Status.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.domain; 22 | 23 | public enum Status { 24 | 25 | NOT_STARTED, ALLOCATED, SHIPPING, COMPLETE, CANCELLED 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/test/beans/scan/ScanBean.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.test.beans.scan; 22 | 23 | import java.util.Objects; 24 | 25 | public class ScanBean { 26 | 27 | private String name; 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return Objects.hash(name); 40 | } 41 | 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (!(obj instanceof ScanBean)) { 45 | return false; 46 | } 47 | ScanBean other = (ScanBean) obj; 48 | return Objects.equals(name, other.name); 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "ScanBean [name=" + name + "]"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/meanbean/util/AssertionUtilsTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * ​​​ 3 | * meanbean 4 | * ⁣⁣⁣ 5 | * Copyright (C) 2010 - 2020 the original author or authors. 6 | * ⁣⁣⁣ 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *  19 | */ 20 | 21 | package org.meanbean.util; 22 | 23 | import static org.hamcrest.Matchers.is; 24 | import static org.hamcrest.Matchers.not; 25 | import static org.hamcrest.Matchers.nullValue; 26 | import static org.junit.Assert.assertThat; 27 | 28 | import org.junit.Test; 29 | 30 | public class AssertionUtilsTest { 31 | 32 | @Test(expected = AssertionError.class) 33 | public void shouldThrowAssertionError() throws Exception { 34 | // Given 35 | // When 36 | AssertionUtils.fail(); 37 | // Then - should throw AssertionError 38 | } 39 | 40 | @Test 41 | public void shouldThrowAssertionErrorWithMessage() throws Exception { 42 | // Given 43 | final String message = "TEST_FAIL_MESSAGE"; 44 | // When 45 | AssertionError assertionError = null; 46 | try { 47 | AssertionUtils.fail(message); 48 | } catch (AssertionError error) { 49 | assertionError = error; 50 | } 51 | // Then 52 | assertThat("fail should have thrown AssertionError.", assertionError, is(not(nullValue()))); 53 | assertThat("Incorrect message.", assertionError.getMessage(), is(message)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /statics/docs/meanbean_bean_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meanbeanlib/meanbean/d4a0c17c139042b64a5203021cca2a208c23de64/statics/docs/meanbean_bean_logo.png -------------------------------------------------------------------------------- /statics/docs/meanbean_lightbrown_bean_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meanbeanlib/meanbean/d4a0c17c139042b64a5203021cca2a208c23de64/statics/docs/meanbean_lightbrown_bean_logo.png -------------------------------------------------------------------------------- /statics/docs/meanbean_logo_withbackground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meanbeanlib/meanbean/d4a0c17c139042b64a5203021cca2a208c23de64/statics/docs/meanbean_logo_withbackground.png -------------------------------------------------------------------------------- /statics/docs/meanbeanlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meanbeanlib/meanbean/d4a0c17c139042b64a5203021cca2a208c23de64/statics/docs/meanbeanlogo.png --------------------------------------------------------------------------------