method2testcases
stringlengths
118
6.63k
### Question: JRubyRackApplication implements RackApplication { @Override public RackResponse call(RackEnvironment environment) { RubyHash environmentHash = convertToRubyHash(environment.entrySet()); RubyArray response = callRackApplication(environmentHash); return convertToJavaRackResponse(response); } JRubyRackApplic...
### Question: JRubyRackInput extends RubyObject { @JRubyMethod(optional = 1) public IRubyObject read(ThreadContext context, IRubyObject[] args) { Integer length = null; if (args.length > 0) { long arg = args[0].convertToInteger("to_i").getLongValue(); length = (int) Math.min(arg, Integer.MAX_VALUE); } try { return toRu...
### Question: RackResponsePropagator { public void propagate(RackResponse rackResponse, HttpServletResponse response) { propagateStatus(rackResponse, response); propagateHeaders(rackResponse, response); propagateBody(rackResponse, response); } void propagate(RackResponse rackResponse, HttpServletResponse response); }...
### Question: RackResponsePropagator { private void propagateHeaders(RackResponse rackResponse, HttpServletResponse response) { for (Map.Entry<String, String> header : rackResponse.getHeaders().entrySet()) { if (shouldPropagateHeaderToClient(header)) { for (String val : header.getValue().split("\n")) { response.addHead...
### Question: RackResponsePropagator { private void propagateBody(RackResponse rackResponse, HttpServletResponse response) { ServletOutputStream outputStream = null; try { outputStream = response.getOutputStream(); } catch (IOException e) { Throwables.propagate(e); } Iterator<byte[]> body = rackResponse.getBody(); whil...
### Question: RackEnvironmentBuilder { private RackInput rackInput(HttpServletRequest request) { try { return new RackInput(new TempfileBufferedInputStream(request.getInputStream())); } catch (IOException e) { throw propagate(e); } } RackEnvironment build(HttpServletRequest request); }### Answer: @Test public void ra...
### Question: RackLogger { public void info(String message) { logger.info(message); } RackLogger(Logger logger); void info(String message); void debug(String message); void warn(String message); void error(String message); void fatal(String message); static final Marker FATAL; }### Answer: @Test public void info() { su...
### Question: RackServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RackEnvironment rackEnvironment = rackEnvironmentBuilder.build(request); try { RackResponse rackResponse = rackApplication.call(rackEnvironmen...
### Question: RackInput implements Closeable { public byte[] gets() throws IOException { return readToLinefeed(); } RackInput(InputStream inputStream); byte[] gets(); byte[] read(Integer length); void rewind(); @Override void close(); }### Answer: @Test public void getsAtEof() throws Exception { assertThat(empty.gets(...
### Question: RackInput implements Closeable { public byte[] read(Integer length) throws IOException { if (length == null) { return readToEof(); } else { return readTo(length); } } RackInput(InputStream inputStream); byte[] gets(); byte[] read(Integer length); void rewind(); @Override void close(); }### Answer: @Test ...
### Question: RackLogger { public void debug(String message) { logger.debug(message); } RackLogger(Logger logger); void info(String message); void debug(String message); void warn(String message); void error(String message); void fatal(String message); static final Marker FATAL; }### Answer: @Test public void debug() {...
### Question: RackInput implements Closeable { public void rewind() throws IOException { stream.reset(); buffer.reset(); bufferReadHead = 0; } RackInput(InputStream inputStream); byte[] gets(); byte[] read(Integer length); void rewind(); @Override void close(); }### Answer: @Test public void rewind() throws Exception ...
### Question: RackLogger { public void warn(String message) { logger.warn(message); } RackLogger(Logger logger); void info(String message); void debug(String message); void warn(String message); void error(String message); void fatal(String message); static final Marker FATAL; }### Answer: @Test public void warn() { su...
### Question: RackLogger { public void error(String message) { logger.error(message); } RackLogger(Logger logger); void info(String message); void debug(String message); void warn(String message); void error(String message); void fatal(String message); static final Marker FATAL; }### Answer: @Test public void error() {...
### Question: RackLogger { public void fatal(String message) { logger.error(FATAL, message); } RackLogger(Logger logger); void info(String message); void debug(String message); void warn(String message); void error(String message); void fatal(String message); static final Marker FATAL; }### Answer: @Test public void fa...
### Question: RackErrors { public void puts(String message) { logger.error(message); } RackErrors(Logger logger); void puts(String message); void write(String message); void flush(); }### Answer: @Test public void puts() { rackErrors.puts("Boom!"); verify(logger).error("Boom!"); }
### Question: RackErrors { public void write(String message) { buffer.append(message); } RackErrors(Logger logger); void puts(String message); void write(String message); void flush(); }### Answer: @Test public void write() { rackErrors.write("Boom?"); verify(logger, never()).error(anyString()); }
### Question: RackErrors { public void flush() { if (buffer.length() > 0) { logger.error(buffer.toString()); buffer.setLength(0); } } RackErrors(Logger logger); void puts(String message); void write(String message); void flush(); }### Answer: @Test public void flushOnEmpty() { rackErrors.flush(); verify(logger, never(...
### Question: MQClientInstance { public boolean registerProducer(final String group, final DefaultMQProducerImpl producer) { if (null == group || null == producer) { return false; } MQProducerInner prev = this.producerTable.putIfAbsent(group, producer); if (prev != null) { log.warn("the producer group[{}] exist already...
### Question: MQClientInstance { public boolean registerConsumer(final String group, final MQConsumerInner consumer) { if (null == group || null == consumer) { return false; } MQConsumerInner prev = this.consumerTable.putIfAbsent(group, consumer); if (prev != null) { log.warn("the consumer group[" + group + "] exist al...
### Question: MQClientInstance { public boolean registerAdminExt(final String group, final MQAdminExtInner admin) { if (null == group || null == admin) { return false; } MQAdminExtInner prev = this.adminExtTable.putIfAbsent(group, admin); if (prev != null) { log.warn("the admin group[{}] exist already.", group); return...
### Question: RemotingCommand { public static byte[] markProtocolType(int source, SerializeType type) { byte[] result = new byte[4]; result[0] = type.getCode(); result[1] = (byte) ((source >> 16) & 0xFF); result[2] = (byte) ((source >> 8) & 0xFF); result[3] = (byte) (source & 0xFF); return result; } protected Remoting...
### Question: RemotingCommand { public static RemotingCommand createResponseCommand(Class<? extends CommandCustomHeader> classHeader) { return createResponseCommand(RemotingSysResponseCode.SYSTEM_ERROR, "not set any response code", classHeader); } protected RemotingCommand(); static RemotingCommand createRequestComman...
### Question: ResetOffsetByTimeOldCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { String co...
### Question: RouteInfoManager { public TopicRouteData pickupTopicRouteData(final String topic) { TopicRouteData topicRouteData = new TopicRouteData(); boolean foundQueueData = false; boolean foundBrokerData = false; Set<String> brokerNameSet = new HashSet<String>(); List<BrokerData> brokerDataList = new LinkedList<Bro...
### Question: ResetOffsetByTimeCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { String group...
### Question: GetConsumerStatusCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { String group...
### Question: CleanExpiredCQSubCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { boolean resu...
### Question: CleanUnusedTopicCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { boolean resul...
### Question: UpdateBrokerConfigSubCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { String k...
### Question: BrokerStatusSubCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { defaultMQAdmin...
### Question: GetBrokerConfigCommand implements SubCommand { @Override public void execute(final CommandLine commandLine, final Options options, final RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); tr...
### Question: BrokerConsumeStatsSubCommad implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { defaultMQ...
### Question: SendMsgStatusCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { final DefaultMQProducer producer = new DefaultMQProducer("PID_SMSC", rpcHook); producer.setInstanceName("PID_SMSC_" + System.currentTimeMillis()); try { producer.start();...
### Question: ConsumerStatusSubCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { defaultMQAdm...
### Question: GetNamesrvConfigCommand implements SubCommand { @Override public void execute(final CommandLine commandLine, final Options options, final RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); t...
### Question: WipeWritePermSubCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { defaultMQAdmi...
### Question: UpdateTopicPermSubCommand implements SubCommand { @Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try {...
### Question: TopicRouteSubCommand implements SubCommand { @Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { defa...
### Question: DeleteTopicSubCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook); adminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { String topic = commandLine.getOpt...
### Question: AllocateMQSubCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook); adminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { adminExt.start(); String topic = c...
### Question: TopicClusterSubCommand implements SubCommand { @Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); String t...
### Question: TopicStatusSubCommand implements SubCommand { @Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { def...
### Question: UpdateOrderConfCommand implements SubCommand { @Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { St...
### Question: ProducerManager { public void scanNotActiveChannel() { try { if (this.hashcodeChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { Iterator<Entry<Integer, List<ClientChannelInfo>>> it = this.hashcodeChannelTable.entrySet().iterator(); while (it.hasNext()) { Entry<Integer, List<ClientCh...
### Question: ProducerManager { public void doChannelCloseEvent(final String remoteAddr, final Channel channel) { if (channel != null) { try { if (this.hashcodeChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { for (final Map.Entry<Integer, List<ClientChannelInfo>> entry : this.hashcodeChannelTabl...
### Question: ProducerManager { public void registerProducer(final String group, final ClientChannelInfo clientChannelInfo) { try { ClientChannelInfo clientChannelInfoFound = null; if (this.hashcodeChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { List<ClientChannelInfo> clientChannelInfoList = t...
### Question: ProducerManager { public void unregisterProducer(final String group, final ClientChannelInfo clientChannelInfo) { try { if (this.hashcodeChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { List<ClientChannelInfo> clientChannelInfoList = this.hashcodeChannelTable.get(group.hashCode());...
### Question: SendMessageProcessor extends AbstractSendMessageProcessor implements NettyRequestProcessor { @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext; switch (request.getCode()) { case RequestCod...
### Question: ClientManageProcessor implements NettyRequestProcessor { @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { switch (request.getCode()) { case RequestCode.HEART_BEAT: return this.heartBeat(ctx, request); case RequestCode.UNR...
### Question: MappedFile extends ReferenceResource { public SelectMappedBufferResult selectMappedBuffer(int pos, int size) { int readPosition = getReadPosition(); if ((pos + size) <= readPosition) { if (this.hold()) { ByteBuffer byteBuffer = this.mappedByteBuffer.slice(); byteBuffer.position(pos); ByteBuffer byteBuffer...
### Question: MappedFileQueue { public MappedFile getLastMappedFile(final long startOffset, boolean needCreate) { long createOffset = -1; MappedFile mappedFileLast = getLastMappedFile(); if (mappedFileLast == null) { createOffset = startOffset - (startOffset % this.mappedFileSize); } if (mappedFileLast != null && mappe...
### Question: MappedFileQueue { public long getMappedMemorySize() { long size = 0; Object[] mfs = this.copyMappedFiles(0); if (mfs != null) { for (Object mf : mfs) { if (((ReferenceResource) mf).isAvailable()) { size += this.mappedFileSize; } } } return size; } MappedFileQueue(final String storePath, int mappedFileSize...
### Question: FilterAPI { public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); if (null == subString || s...
### Question: ConsumerConnectionSubCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { defaultM...
### Question: UtilAll { public static String currentStackTrace() { StringBuilder sb = new StringBuilder(); StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement ste : stackTrace) { sb.append("\n\t"); sb.append(ste.toString()); } return sb.toString(); } static int getPid(); sta...
### Question: UtilAll { public static int getPid() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String name = runtime.getName(); try { return Integer.parseInt(name.substring(0, name.indexOf('@'))); } catch (Exception e) { return -1; } } static int getPid(); static String currentStackTrace(); static ...
### Question: UtilAll { public static double getDiskPartitionSpaceUsedPercent(final String path) { if (null == path || path.isEmpty()) return -1; try { File file = new File(path); if (!file.exists()) return -1; long totalSpace = file.getTotalSpace(); if (totalSpace > 0) { long freeSpace = file.getFreeSpace(); long used...
### Question: UtilAll { public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(str.charAt(i))) { return false; } } return true; } static int getPid(); static String currentStackTrace(); sta...
### Question: MixAll { public static String brokerVIPChannel(final boolean isChange, final String brokerAddr) { if (isChange) { String[] ipAndPort = brokerAddr.split(":"); String brokerAddrNew = ipAndPort[0] + ":" + (Integer.parseInt(ipAndPort[1]) - 2); return brokerAddrNew; } else { return brokerAddr; } } static Stri...
### Question: MixAll { public static boolean compareAndIncreaseOnly(final AtomicLong target, final long value) { long prev = target.get(); while (value > prev) { boolean updated = target.compareAndSet(prev, value); if (updated) return true; prev = target.get(); } return false; } static String getRetryTopic(final Strin...
### Question: MixAll { public static String file2String(final String fileName) { File file = new File(fileName); return file2String(file); } static String getRetryTopic(final String consumerGroup); static boolean isSysConsumerGroup(final String consumerGroup); static boolean isSystemTopic(final String topic); static S...
### Question: MixAll { public static void string2File(final String str, final String fileName) throws IOException { String tmpFile = fileName + ".tmp"; string2FileNotSafe(str, tmpFile); String bakFile = fileName + ".bak"; String prevContent = file2String(fileName); if (prevContent != null) { string2FileNotSafe(prevCont...
### Question: ProducerConnectionSubCommand implements SubCommand { @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { defaultM...
### Question: SelectMessageQueueByHash implements MessageQueueSelector { @Override public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) { int value = arg.hashCode(); if (value < 0) { value = Math.abs(value); } value = value % mqs.size(); return mqs.get(value); } @Override MessageQueue select(Lis...
### Question: ChecksumHelper { protected byte[] addChecksum(byte[] source) { CRC32 crc32 = new CRC32(); crc32.update(source); long checkSum = crc32.getValue(); byte[] checkSumBytes = String.valueOf(checkSum).getBytes(); byte[] concat = Bytes.concat(source, (SEPARATOR+"").getBytes(), checkSumBytes); return concat; } ...
### Question: ChecksumHelper { protected byte[] validateAndStripChecksum(byte[] source) { int lastIndexOf = Bytes.lastIndexOf(source, (byte) SEPARATOR); if (lastIndexOf < 0) { throw new RuntimeException("no checksum was found on source: " + new String(source)); } long checkSum = Long.parseLong(new String(Arrays.copyOfR...
### Question: Compressor { public byte[] compress(byte[] source) throws IOException { return compress(DEFAULTCOMPRESSIONTYPE, source); } byte[] compress(byte[] source); byte[] compress(CompressionType type, byte[] source); byte[] decompress(byte[] source); byte[] decompress(CompressionType type, byte[] source); }### ...
### Question: ExtrasHandler { void addToExtras(List<Person> persons) { persons.forEach(p -> { p.setRelationshipStatus(null); p.clearFamilyID(); }); this.extras.addAll(persons); persons.clear(); } ExtrasHandler(List<IndRecord> indRecords, Random random); }### Answer: @Test public void testAddToExtras() throws NoSuchFi...
### Question: ExtrasHandler { List<Person> getPersonsFromExtras(RelationshipStatus relStatus, Sex sex, AgeRange ageRange, int count) { return getPersonsFromExtras(relStatus == null ? null : Collections.singletonList(relStatus), sex == null ? null : Collections.singletonList(sex), ageRange == null ? null : Collections.s...
### Question: HouseholdFactory { private void assignOneParentUnitsAsNonPrimaryFamilies(List<Household> households, List<Family> basicUnits) { Log.info("Adding " + FamilyType.ONE_PARENT + " as non primary"); Log.debug(FamilyType.ONE_PARENT + ": available family units: " + basicUnits.size()); List<Household> eligibleHhs ...
### Question: HouseholdFactory { void completeHouseholdsWithChildren(List<Household> households, List<Person> knownChildren) { Log.info("Adding all known children to households"); Log.debug("Total known Children from data: " + knownChildren.size()); knownChildren.sort(new AgeRange.AgeComparator().reversed()); List<Hous...
### Question: HouseholdFactory { void completeHouseholdsWithRelatives(List<Household> households, List<Person> relatives, FamilyHouseholdType familyHouseholdType) { Log.info("Fill " + ((familyHouseholdType == null) ? "All" : familyHouseholdType) + " households with relatives"); Log.debug("Start remaining relatives: " +...
### Question: ExtrasHandler { int remainingExtras() { return extras.size(); } ExtrasHandler(List<IndRecord> indRecords, Random random); }### Answer: @Test public void testFormingExtras() { Assert.assertNotNull(extrasHandler); Assert.assertEquals("Number of extras", extrasHandler.remainingExtras(), 145); }
### Question: EasyPermissions { public static boolean hasPermissions(@NonNull Context context, @Size(min = 1) @NonNull String... perms) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { Log.w(TAG, "hasPermissions: API version < M, returning true by default"); return true; } if (context == null) { throw new Illegal...
### Question: CacheLoaderAdapter implements CacheLoader<K, V>, Factory<CacheLoader<K, V>> { @Override public Map<K, V> loadAll(final Iterable<? extends K> keys) throws CacheLoaderException { final Map<K, V> result = new HashMap<K, V>(); for (final K k : keys) { final V v = load(k); if (v != null) { result.put(k, v); } ...
### Question: CDIJCacheHelper { public MethodMeta findMeta(final InvocationContext ic) { final Method mtd = ic.getMethod(); final Class<?> refType = findKeyType(ic.getTarget()); final MethodKey key = new MethodKey(refType, mtd); MethodMeta methodMeta = methods.get(key); if (methodMeta == null) { synchronized (this) { m...
### Question: DelegatingInvoker implements Invoker { @Override public Object invoke(Object proxy, Method method, Object[] arguments) throws Throwable { try { return method.invoke(delegateProvider.getObject(), arguments); } catch (InvocationTargetException e) { throw e.getTargetException(); } } DelegatingInvoker(ObjectP...
### Question: CloningProvider implements ObjectProvider<T>, Serializable { @Override public T getObject() { try { return ObjectUtils.clone(cloneable); } catch (CloneFailedException e) { throw new ObjectProviderException(e.getMessage(), e.getCause()); } } CloningProvider(T cloneable); @Override T getObject(); }### Answ...
### Question: InterceptorUtils { public static Interceptor constant(Object value) { return new ObjectProviderInterceptor(ObjectProviderUtils.constant(value)); } private InterceptorUtils(); static Interceptor constant(Object value); static Interceptor provider(ObjectProvider<?> provider); static Interceptor throwing(Ex...
### Question: InterceptorUtils { public static Interceptor provider(ObjectProvider<?> provider) { return new ObjectProviderInterceptor(provider); } private InterceptorUtils(); static Interceptor constant(Object value); static Interceptor provider(ObjectProvider<?> provider); static Interceptor throwing(Exception e); s...
### Question: InterceptorUtils { public static Interceptor throwing(Exception e) { return new ThrowingInterceptor(ObjectProviderUtils.constant(e)); } private InterceptorUtils(); static Interceptor constant(Object value); static Interceptor provider(ObjectProvider<?> provider); static Interceptor throwing(Exception e);...
### Question: ObjectProviderInterceptor implements Interceptor { @Override public Object intercept(Invocation invocation) throws Throwable { return provider.getObject(); } ObjectProviderInterceptor(ObjectProvider<?> provider); @Override Object intercept(Invocation invocation); }### Answer: @Test public void testInterc...
### Question: SwitchInterceptor implements Interceptor, Serializable { @Override public Object intercept(Invocation invocation) throws Throwable { for (Pair<InvocationMatcher, Interceptor> currentCase : cases) { if (currentCase.getLeft().matches(invocation)) { return currentCase.getRight().intercept(invocation); } } re...
### Question: InvokerInterceptor implements Interceptor { @Override public Object intercept(Invocation invocation) throws Throwable { return invoker.invoke(invocation.getProxy(), invocation.getMethod(), invocation.getArguments()); } InvokerInterceptor(Invoker invoker); @Override Object intercept(Invocation invocation);...
### Question: ArgumentMatcherUtils { public static <T> ArgumentMatcher<T> any() { return new AnyMatcher<T>(); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> eq(final T value); static ArgumentMatcher<C> gt(C comparable...
### Question: BeanProvider implements ObjectProvider<T>, Serializable { @Override public T getObject() { try { return beanClass.newInstance(); } catch (InstantiationException e) { throw new ObjectProviderException(e, "%s is not concrete.", beanClass); } catch (IllegalAccessException e) { throw new ObjectProviderExcepti...
### Question: ArgumentMatcherUtils { public static <T> ArgumentMatcher<T> eq(final T value) { return new EqualsMatcher<T>(value); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> eq(final T value); static ArgumentMatche...
### Question: ArgumentMatcherUtils { public static <C extends Comparable<C>> ArgumentMatcher<C> gt(C comparable) { return new GreaterThanMatcher<C>(comparable); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> eq(final ...
### Question: ArgumentMatcherUtils { public static <C extends Comparable<C>> ArgumentMatcher<C> gte(C comparable) { return new GreaterThanOrEqualMatcher<C>(comparable); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> e...
### Question: ArgumentMatcherUtils { public static <T> ArgumentMatcher<T> isA(final Class<?> type) { return new InstanceOfMatcher<T>(type); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> eq(final T value); static Argu...
### Question: ArgumentMatcherUtils { public static <T> ArgumentMatcher<T> isNull() { return new IsNullMatcher<T>(); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> eq(final T value); static ArgumentMatcher<C> gt(C comp...
### Question: ArgumentMatcherUtils { public static <C extends Comparable<C>> ArgumentMatcher<C> lt(C comparable) { return new LessThanMatcher<C>(comparable); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> eq(final T v...
### Question: ArgumentMatcherUtils { public static <C extends Comparable<C>> ArgumentMatcher<C> lte(C comparable) { return new LessThanOrEqualMatcher<C>(comparable); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> eq(f...
### Question: ArgumentMatcherUtils { public static ArgumentMatcher<String> matches(String regex) { return new RegexMatcher(Validate.notNull(regex)); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> eq(final T value); st...
### Question: ArgumentMatcherUtils { public static <T> ArgumentMatcher<T> notNull() { return new NotNullMatcher<T>(); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> eq(final T value); static ArgumentMatcher<C> gt(C co...
### Question: ArgumentMatcherUtils { public static ArgumentMatcher<String> startsWith(String prefix) { return new StartsWithMatcher(Validate.notNull(prefix)); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> eq(final T ...
### Question: ArgumentMatcherUtils { public static ArgumentMatcher<String> endsWith(String suffix) { return new EndsWithMatcher(Validate.notNull(suffix)); } private ArgumentMatcherUtils(); static ArgumentMatcher<T> any(); static ArgumentMatcher<String> endsWith(String suffix); static ArgumentMatcher<T> eq(final T valu...
### Question: ProxyUtils { public static <T> T nullValue(Class<T> type) { @SuppressWarnings("unchecked") final T result = (T) NULL_VALUE_MAP.get(type); return result; } private ProxyUtils(); static Class<?>[] getAllInterfaces(Class<?> cls); static String getJavaClassName(Class<?> clazz); static Class<?> getWrapperClas...
### Question: ProxyUtils { public static Class<?>[] getAllInterfaces(Class<?> cls) { return cls == null ? null : ClassUtils.getAllInterfaces(cls).toArray(ArrayUtils.EMPTY_CLASS_ARRAY); } private ProxyUtils(); static Class<?>[] getAllInterfaces(Class<?> cls); static String getJavaClassName(Class<?> clazz); static Class...