private boolean matchesClassCastMessage(String classCastMessage, Class<?> eventClass) { // On Java 8, the message starts with the class name: "java.lang.String cannot be cast..." if (classCastMessage.startsWith(eventClass.getName())) { return true; } // On Java 11, the message starts with "class ..." a.k.a. Class.toString() if (classCastMessage.startsWith(eventClass.toString())) { return true; } // On Java 9, the message used to contain the module name: "java.base/java.lang.String cannot be cast..." int moduleSeparatorIndex = classCastMessage.indexOf('/'); if (moduleSeparatorIndex != -1 && classCastMessage.startsWith(eventClass.getName(), moduleSeparatorIndex + 1)) { return true; } // Assuming an unrelated class cast failure... return false; }
@SuppressWarnings("PMD.PreserveStackTrace") private static void appendExceptionMessage(Throwable t, Appendable appendable) { try { appendable.append(t.getClass().toString()).append(": ").append(t.getMessage()).append('\n'); } catch (IOException e1) { throw new RuntimeException(t); } }
private Map<String, Map<String, String>> map( Class<? extends PropertyContainer> cls ) { if ( cls.equals( Node.class ) ) { return nodeConfig; } else if ( cls.equals( Relationship.class ) ) { return relConfig; } throw new IllegalArgumentException( cls.toString() ); }
private String fieldTypesToString() { StringBuilder string = new StringBuilder(); string.append(this.fieldTypes[0].toString()); for (int i = 1; i < this.fieldTypes.length; i++) { string.append(", ").append(this.fieldTypes[i]); } return string.toString(); }
/** * @return A hashcode representing the name of this method and its parameters, * but without its class */ private static String createMethodKey(Method m) { StringBuilder result = new StringBuilder(m.getName()); for (Class paramClass : m.getParameterTypes()) { result.append(' ').append(paramClass.toString()); } return result.toString(); }
private static Object createValue(Class<?> type, String valueAsString) throws NoSuchMethodException { for (ValueCreator valueCreator : valueCreators) { Object createdValue = valueCreator.createValue(type, valueAsString); if (createdValue != null) { return createdValue; } } throw new IllegalArgumentException(String.format("cannot instanciate any %s object using %s value", type.toString(), valueAsString)); }
/** * {@inheritDoc} */ public Annotation resolve() { throw new IncompatibleClassChangeError("Not an annotation type: " + incompatibleType.toString()); }
/** * {@inheritDoc} */ public Enum<?> resolve() { throw new IncompatibleClassChangeError("Not an enumeration type: " + type.toString()); }
public static MockitoException cannotMockClass(Class<?> clazz, String reason) { return new MockitoException(join( "Cannot mock/spy " + clazz.toString(), "Mockito cannot mock/spy because :", " - " + reason )); }
@Override public final T getNullValue(DeserializationContext ctxt) throws JsonMappingException { // 01-Mar-2017, tatu: Alas, not all paths lead to `_coerceNull()`, as `SettableBeanProperty` // short-circuits `null` handling. Hence need this check as well. if (_primitive && ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)) { ctxt.reportInputMismatch(this, "Cannot map `null` into type %s (set DeserializationConfig.DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES to 'false' to allow)", handledType().toString()); } return _nullValue; }
@Override public final T getNullValue(DeserializationContext ctxt) throws JsonMappingException { // 01-Mar-2017, tatu: Alas, not all paths lead to `_coerceNull()`, as `SettableBeanProperty` // short-circuits `null` handling. Hence need this check as well. if (_primitive && ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)) { ctxt.reportInputMismatch(this, "Cannot map `null` into type %s (set DeserializationConfig.DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES to 'false' to allow)", handledType().toString()); } return _nullValue; }
@Test public void just() { Flowable<Integer> source = Flowable.fromArray(new Integer[] { 1 }); Assert.assertTrue(source.getClass().toString(), source instanceof ScalarCallable); }
@SuppressWarnings("unchecked") @Test public void scalarCallable() { Maybe<Integer> m = Maybe.just(1); assertTrue(m.getClass().toString(), m instanceof ScalarCallable); assertEquals(1, ((ScalarCallable<Integer>)m).call().intValue()); } }
@SuppressWarnings("unchecked") @Test public void callable() throws Exception { final int[] counter = { 0 }; Maybe<Void> m = Maybe.fromAction(new Action() { @Override public void run() throws Exception { counter[0]++; } }); assertTrue(m.getClass().toString(), m instanceof Callable); assertNull(((Callable<Void>)m).call()); assertEquals(1, counter[0]); }
@SuppressWarnings("unchecked") @Test public void callable() throws Exception { final int[] counter = { 0 }; Maybe<Void> m = Maybe.fromRunnable(new Runnable() { @Override public void run() { counter[0]++; } }); assertTrue(m.getClass().toString(), m instanceof Callable); assertNull(((Callable<Void>)m).call()); assertEquals(1, counter[0]); }
@SuppressWarnings("unchecked") @Test public void callable() throws Exception { final int[] counter = { 0 }; Maybe<Integer> m = Maybe.fromCallable(new Callable<Integer>() { @Override public Integer call() throws Exception { counter[0]++; return 0; } }); assertTrue(m.getClass().toString(), m instanceof Callable); assertEquals(0, ((Callable<Void>)m).call()); assertEquals(1, counter[0]); }
@Test public void scalarCallable() { Maybe<Integer> m = Maybe.empty(); assertTrue(m.getClass().toString(), m instanceof ScalarCallable); assertNull(((ScalarCallable<?>)m).call()); } }
@Test public void source() { Maybe<Integer> m = Maybe.just(1); Single<Integer> s = m.toSingle(); assertTrue(s.getClass().toString(), s instanceof HasUpstreamMaybeSource); assertSame(m, (((HasUpstreamMaybeSource<?>)s).source())); }
@Test public void processHeadersToSend() { Map<String, Object> map = this.messagingTemplate.processHeadersToSend(null); assertNotNull(map); assertTrue("Actual: " + map.getClass().toString(), MessageHeaders.class.isAssignableFrom(map.getClass())); SimpMessageHeaderAccessor headerAccessor = MessageHeaderAccessor.getAccessor((MessageHeaders) map, SimpMessageHeaderAccessor.class); assertTrue(headerAccessor.isMutable()); assertEquals(SimpMessageType.MESSAGE, headerAccessor.getMessageType()); }
@Test public void setPropertyWithCustomEditor() { MutablePropertyValues values = new MutablePropertyValues(); values.add("name", Integer.class); TestBean target = new TestBean(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.registerCustomEditor(String.class, new PropertyEditorSupport() { @Override public void setValue(Object value) { super.setValue(value.toString()); } }); accessor.setPropertyValues(values); assertEquals(Integer.class.toString(), target.getName()); }