@Test public void noKeyReturnedInMap() { kh.getKeyList().addAll(singletonList(emptyMap())); exception.expect(DataRetrievalFailureException.class); exception.expectMessage(startsWith("Unable to retrieve the generated key.")); kh.getKey(); }
@Test public void setFieldWithNullTargetClass() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage(startsWith("Either targetObject or targetClass")); setField((Class<?>) null, "id", Long.valueOf(99)); }
@Test public void setFieldWithBogusName() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage(startsWith("Could not find field 'bogus'")); setField(person, "bogus", Long.valueOf(99), long.class); }
@Test public void invokeMethodWithTooFewArguments() { exception.expect(IllegalStateException.class); exception.expectMessage(startsWith("Method not found")); invokeMethod(component, "configure", Integer.valueOf(42)); }
@Test public void invokeMethodWithTooManyArguments() { exception.expect(IllegalStateException.class); exception.expectMessage(startsWith("Method not found")); invokeMethod(component, "configure", Integer.valueOf(42), "enigma", "baz", "quux"); }
@Test public void setFieldWithNullTargetObject() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage(startsWith("Either targetObject or targetClass")); setField((Object) null, "id", Long.valueOf(99)); }
@Test public void setFieldWithWrongType() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage(startsWith("Could not find field")); setField(person, "id", Long.valueOf(99), String.class); }
@Test public void loadContextWithoutLocationsAndConfigurationClasses() throws Exception { expectedException.expect(IllegalStateException.class); expectedException.expectMessage(startsWith("Neither")); expectedException.expectMessage(containsString("was able to load an ApplicationContext from")); MergedContextConfiguration mergedConfig = new MergedContextConfiguration( getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); loader.loadContext(mergedConfig); }
@Test public void extendedEmptyAnnotation() { expectedException.expect(IllegalStateException.class); expectedException.expectMessage(startsWith("Could not detect default properties file for test")); expectedException.expectMessage(containsString("ExtendedEmptyPropertySources.properties")); buildMergedTestPropertySources(ExtendedEmptyPropertySources.class); }
@Test public void emptyAnnotation() { expectedException.expect(IllegalStateException.class); expectedException.expectMessage(startsWith("Could not detect default properties file for test")); expectedException.expectMessage(containsString("EmptyPropertySources.properties")); buildMergedTestPropertySources(EmptyPropertySources.class); }
/** * @since 4.3 */ @Test public void buildMergedConfigWithContextConfigurationWithoutLocationsClassesOrInitializers() { exception.expect(IllegalStateException.class); exception.expectMessage(startsWith("DelegatingSmartContextLoader was unable to detect defaults, " + "and no ApplicationContextInitializers or ContextCustomizers were declared for context configuration attributes")); buildMergedContextConfiguration(MissingContextAttributesTestCase.class); }
@Test public void getFieldWithNullTargetObject() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage(startsWith("Either targetObject or targetClass")); getField((Object) null, "id"); }
@Test public void getFieldWithNullTargetClass() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage(startsWith("Either targetObject or targetClass")); getField((Class<?>) null, "id"); }
@Test public void invokeMethodWithIncompatibleArgumentTypes() { exception.expect(IllegalStateException.class); exception.expectMessage(startsWith("Method not found")); invokeMethod(component, "subtract", "foo", 2.0); }
@Test public void multipleKeys() { Map<String, Object> m = new HashMap<String, Object>() {{ put("key", 1); put("seq", 2); }}; kh.getKeyList().addAll(singletonList(m)); assertEquals("two keys should be in the map", 2, kh.getKeys().size()); exception.expect(InvalidDataAccessApiUsageException.class); exception.expectMessage(startsWith("The getKey method should only be used when a single key is returned.")); kh.getKey(); }
@Test public void maxAge() { Duration maxAge = Duration.ofDays(365); String expires = HttpHeaders.formatDate(System.currentTimeMillis() + maxAge.toMillis()); expires = expires.substring(0, expires.indexOf(":") + 1); assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge).build().toString(), allOf( startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires), endsWith(" GMT"))); assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge.getSeconds()).build().toString(), allOf( startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires), endsWith(" GMT"))); }
@Test public void threadNameGetsSetCorrectly() throws Exception { final String customPrefix = "chankPop#"; final Object monitor = new Object(); SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(customPrefix); ThreadNameHarvester task = new ThreadNameHarvester(monitor); executeAndWait(executor, task, monitor); assertThat(task.getThreadName(), startsWith(customPrefix)); }
@Test public void unknownReturnType() { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-return-type")); Mono<Void> publisher = this.dispatcherHandler.handle(exchange); StepVerifier.create(publisher) .consumeErrorWith(error -> { assertThat(error, instanceOf(IllegalStateException.class)); assertThat(error.getMessage(), startsWith("No HandlerResultHandler")); }) .verify(); }
@SuppressWarnings("unchecked") @Test public void multiStringHeaderValueWithMatchers() throws Exception { this.mockMvc.perform(get("/persons/1")) .andExpect(header().stringValues(VARY, hasItems(containsString("foo"), startsWith("bar")))); }
@Test public void entityMatcher() { this.client.get().uri("/John") .exchange() .expectStatus().isOk() .expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8) .expectBody(Person.class).value(Person::getName, startsWith("Joh")); }