@Test public void showsErrorMessageContainingClassAndTypeAndAnnotationWhenTypeAndAnnotationTypeSpecifiedWhenTimeout() throws Exception { exception.expect(ConditionTimeoutException.class); exception.expectMessage("Field in org.awaitility.classes.FakeRepositoryWithAnnotation annotated with org.awaitility.classes.ExampleAnnotation and of type int expected <1> but was <0> within 200 milliseconds."); FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); await().atMost(200, MILLISECONDS).until(fieldIn(repository).ofType(int.class).andAnnotatedWith(ExampleAnnotation.class), equalTo(1)); } }
@Test public void showsErrorMessageContainingClassAndTypeAndFieldNameAndAnnotationWhenTypeAndNameAndAnnotationTypeSpecifiedWhenTimeout() throws Exception { exception.expect(ConditionTimeoutException.class); exception.expectMessage("Field private volatile int org.awaitility.classes.FakeRepositoryWithAnnotation.value expected <1> but was <0> within 200 milliseconds."); FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); await().atMost(200, MILLISECONDS).until(fieldIn(repository).ofType(int.class).andWithName("value").andAnnotatedWith(ExampleAnnotation.class), equalTo(1)); }
/** * Find a field based on a type. E.g. * <p> </p> * <code> * await().until(fieldIn(object).ofType(int.class), equalTo(2)); * </code> * <p> </p> * You can also specify the field more accurately by continuing the statement: * E.g. * <code> * await().until(fieldIn(object).ofType(int.class).andWithName("fieldName"), equalTo(2)); * </code> * <p> </p> * or * <p> </p> * <code> * await().until(fieldIn(object).ofType(int.class).andAnnotatedWith(MyAnnotation.class).andWithName("fieldName"), equalTo(2)); * </code> * * @param fieldType The type of the field. * @param <T> The type of the field * @return The field supplier */ public <T> NameAndAnnotationFieldSupplier<T> ofType(Class<T> fieldType) { this.expectedFieldType = fieldType; return new NameAndAnnotationFieldSupplier<T>(); }
/** * Find a field based on the annotation and field type. E.g. * <p> </p> * <code> * await().until(fieldIn(object).annotatedWith(MyAnnotation.class).andOfType(int.class), equalTo(2)); * </code> * * @param type The class representing the type of the field * @param <S> The type of the field * @return The supplier */ public <S> NameAndAnnotationFieldSupplier<S> andOfType(Class<S> type) { assertNotNullParameter(type, "Expected field type"); FieldSupplierBuilder.this.expectedFieldType = type; return new NameAndAnnotationFieldSupplier<S>(); }
/** * Find a field based on a type. E.g. * <p> </p> * <code> * await().until(fieldIn(object).ofType(int.class), equalTo(2)); * </code> * <p> </p> * You can also specify the field more accurately by continuing the statement: * E.g. * <code> * await().until(fieldIn(object).ofType(int.class).andWithName("fieldName"), equalTo(2)); * </code> * <p> </p> * or * <p> </p> * <code> * await().until(fieldIn(object).ofType(int.class).andAnnotatedWith(MyAnnotation.class).andWithName("fieldName"), equalTo(2)); * </code> * * @param fieldType The type of the field. * @param <T> The type of the field * @return The field supplier */ public <T> NameAndAnnotationFieldSupplier<T> ofType(Class<T> fieldType) { this.expectedFieldType = fieldType; return new NameAndAnnotationFieldSupplier<T>(); }
/** * Find a field based on the annotation and field type. E.g. * <p> </p> * <code> * await().until(fieldIn(object).annotatedWith(MyAnnotation.class).andOfType(int.class), equalTo(2)); * </code> * * @param type The class representing the type of the field * @param <S> The type of the field * @return The supplier */ public <S> NameAndAnnotationFieldSupplier<S> andOfType(Class<S> type) { assertNotNullParameter(type, "Expected field type"); FieldSupplierBuilder.this.expectedFieldType = type; return new NameAndAnnotationFieldSupplier<S>(); }
@Test(timeout = 2000, expected = FieldNotFoundException.class) public void givenAnnotationAndTypeWhenAnnotationMatchButTypeDoesntThenFieldNotFoundExceptionIsThrown() throws Exception { FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); byte one = (byte) 1; await().until(fieldIn(repository).ofType(byte.class).andAnnotatedWith(ExampleAnnotation.class), equalTo(one)); assertEquals(1, repository.getValue()); }
@Test(timeout = 2000, expected = FieldNotFoundException.class) public void givenTypeAndAnnotationAndNameWhenNameAndAnnotationMatchButTypeNotFoundThenFieldNotFoundExceptionIsThrown() throws Exception { FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); byte one = (byte) 1; await().until(fieldIn(repository).ofType(byte.class).andAnnotatedWith(ExampleAnnotation.class).andWithName("value"), equalTo(one)); assertEquals(1, repository.getValue()); }
@Test(timeout = 2000) public void typeAndAnnotationAndName() throws Exception { FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); await().until( fieldIn(repository).ofType(int.class).andAnnotatedWith(ExampleAnnotation.class).andWithName("value"), equalTo(1)); assertEquals(1, repository.getValue()); }
@Test(timeout = 2000) public void typeAndAnnotation() throws Exception { FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); await().until(fieldIn(repository).ofType(int.class).andAnnotatedWith(ExampleAnnotation.class), equalTo(1)); assertEquals(1, repository.getValue()); }
@Test(timeout = 2000, expected = FieldNotFoundException.class) public void givenStaticFieldAndUsingOfTypeAndNameThrowsFieldNotFoundExceptionWhenUsingInstance() throws Exception { FakeRepositoryWithStaticFieldAndAnnotation repository = new FakeRepositoryWithStaticFieldAndAnnotation(); new Asynch(repository).perform(); await().until(fieldIn(repository).ofType(int.class).andWithName("value"), equalTo(1)); assertEquals(1, repository.getValue()); }
@Test(timeout = 2000) public void returnsResultAfterFieldInSupplier() throws Exception { new Asynch(fakeRepository).perform(); int value = await().until(fieldIn(fakeRepository).ofType(int.class).andWithName("value"), equalTo(1)); assertEquals(1, value); } }
@Test public void showsErrorMessageContainingClassAndTypeAndFieldNameWhenTypeAndNameSpecifiedWhenTimeout() throws Exception { exception.expect(ConditionTimeoutException.class); exception.expectMessage("Field private volatile int org.awaitility.classes.FakeRepositoryWithAnnotation.value expected <1> but was <0> within 200 milliseconds."); FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); await().atMost(200, MILLISECONDS).until(fieldIn(repository).ofType(int.class).andWithName("value"), equalTo(1)); }
@Test(timeout = 2000) public void givenStaticFieldAndUsingOfTypeAndName() throws Exception { FakeRepositoryWithStaticFieldAndAnnotation repository = new FakeRepositoryWithStaticFieldAndAnnotation(); new Asynch(repository).perform(); await().until(fieldIn(FakeRepositoryWithStaticFieldAndAnnotation.class).ofType(int.class).andWithName("value"), equalTo(1)); assertEquals(1, repository.getValue()); }
@Test(timeout = 2000) public void typeAndNameAndAnnotation() throws Exception { FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); await().until( fieldIn(repository).ofType(int.class).andWithName("value").andAnnotatedWith(ExampleAnnotation.class), equalTo(1)); assertEquals(1, repository.getValue()); }
@Test(timeout = 2000, expected = FieldNotFoundException.class) public void givenAnnotationAndTypeWhenTypeMatchButAnnotationDoesntThenFieldNotFoundExceptionIsThrown() throws Exception { FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); await().until(fieldIn(repository).ofType(int.class).andAnnotatedWith(ExampleAnnotation2.class), equalTo(1)); assertEquals(1, repository.getValue()); }
@Test(timeout = 2000, expected = FieldNotFoundException.class) public void givenTypeAndAnnotationAndNameWhenNameAndTypeMatchButAnnotationNotFoundThenFieldNotFoundExceptionIsThrown() throws Exception { FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); await().until( fieldIn(repository).ofType(int.class).andAnnotatedWith(ExampleAnnotation2.class).andWithName("value"), equalTo(1)); assertEquals(1, repository.getValue()); }
@Test(timeout = 2000, expected = FieldNotFoundException.class) public void givenTypeAndNameWhenNameMatchButTypeDoesntThenFieldNotFoundExceptionIsThrown() throws Exception { FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); byte one = (byte) 1; await().until(fieldIn(repository).ofType(byte.class).andWithName("value"), equalTo(one)); assertEquals(1, repository.getValue()); }
@Test(timeout = 2000) public void ofTypeAndName() throws Exception { new Asynch(fakeRepository).perform(); await().until(fieldIn(fakeRepository).ofType(int.class).andWithName("value"), equalTo(1)); assertEquals(1, fakeRepository.getValue()); } @Test(timeout = 2000)
@Test(timeout = 2000, expected = FieldNotFoundException.class) public void givenTypeAndNameAndAnnotationWhenNameAndAnnotationMatchButTypeNotFoundThenFieldNotFoundExceptionIsThrown() throws Exception { FakeRepositoryWithAnnotation repository = new FakeRepositoryWithAnnotation(); new Asynch(repository).perform(); byte one = (byte) 1; await().until(fieldIn(repository).ofType(byte.class).andWithName("value").andAnnotatedWith(ExampleAnnotation.class), equalTo(one)); assertEquals(1, repository.getValue()); }