@Test public void whenATypeHasNotBeenRandomizedYet_thenHasPopulatedBeanShouldReturnFalse() { // Given populatorContext.addPopulatedBean(String.class, bean1); // When boolean hasPopulatedBean = populatorContext.hasAlreadyRandomizedType(Integer.class); // Then assertThat(hasPopulatedBean).isFalse(); }
@Test public void whenATypeHasBeenRandomized_thenTheRandomizedBeanShouldBeRetrievedFromTheObjectPool() { // Given populatorContext.addPopulatedBean(String.class, bean1); populatorContext.addPopulatedBean(String.class, bean2); // When Object populatedBean = populatorContext.getPopulatedBean(String.class); // Then assertThat(populatedBean).isIn(bean1, bean2); }
@Test public void stackedFieldNamesShouldBeCorrectlyEncoded() throws NoSuchFieldException { // Given Field address = Person.class.getDeclaredField("address"); populatorContext.pushStackItem(new PopulatorContextStackItem(null, address)); Field street = Address.class.getDeclaredField("street"); // When String fullFieldName = populatorContext.getFieldFullName(street); // Then assertThat(fullFieldName).isEqualTo("address.street"); }
@Test public void whenATypeHasBeenRandomized_thenHasPopulatedBeanShouldReturnTrueOnlyWhenTheObjectPoolIsFilled() { // Only one instance has been randomized => should be considered as not randomized yet populatorContext.addPopulatedBean(String.class, "bean" + 0); assertThat(populatorContext.hasAlreadyRandomizedType(String.class)).isFalse(); // When the object pool size is filled => should be considered as already randomized for (int i = 1; i < Constants.MAX_OBJECT_POOL_SIZE; i++) { populatorContext.addPopulatedBean(String.class, "bean" + i); } assertThat(populatorContext.hasAlreadyRandomizedType(String.class)).isTrue(); }
@Test public void whenCurrentStackSizeLessMaxRandomizationDepth_thenShouldNotExceedRandomizationDepth() throws NoSuchFieldException { // Given PopulatorContext customPopulatorContext = new PopulatorContext(Constants.MAX_OBJECT_POOL_SIZE, 2); Field address = Person.class.getDeclaredField("address"); customPopulatorContext.pushStackItem(new PopulatorContextStackItem(bean1, address)); // When boolean hasExceededRandomizationDepth = customPopulatorContext.hasExceededRandomizationDepth(); // Then assertThat(hasExceededRandomizationDepth).isFalse(); }