method2testcases
stringlengths
118
6.63k
### Question: BookResource { @GET @Path("/{id : \\d+}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Find a Book by the Id.", response = Book.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Book found"), @ApiResponse(code = 400, message = "Invalid input"), @ApiResponse(code = 404, message = "Bo...
### Question: BookResource { @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Find all Books", response = Book.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "All books found"), @ApiResponse(code = 404, message = "Books not found")} ) public Response findAll() { log...
### Question: BookResource { @POST @Consumes(APPLICATION_JSON) @ApiOperation(value = "Create a Book") @ApiResponses(value = { @ApiResponse(code = 201, message = "The book is created"), @ApiResponse(code = 400, message = "Invalid input"), @ApiResponse(code = 415, message = "Format is not JSon") }) public Response create...
### Question: BookResource { @PUT @Path("/{id : \\d+}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Update a Book", response = Book.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "The book is updated"), @ApiResponse(code = 400, message = "Invalid input") }) public R...
### Question: AlbumService implements PaginatedService { public ResourceDto<AlbumDto> getAlbumsPage() { return getAlbumsPage(FIRST_PAGE_NUM); } @Inject AlbumService(@Named("albumDao") AlbumDao albumDao, @Named("artistDao") MaprDbDao<Artist> artistDao, LanguageDao languageDao, SlugService slugSe...
### Question: AlbumService implements PaginatedService { public AlbumDto getAlbumById(String id) { if (id == null || id.isEmpty()) { throw new IllegalArgumentException("Album's identifier can not be empty"); } Album album = albumDao.getById(id); if (album == null) { throw new ResourceNotFoundException("Album with id '"...
### Question: SecKillCommandService { public SecKillGrabResult addCouponTo(T customerId) { if (recoveryInfo.getClaimedCustomers().add(customerId)) { if (claimedCoupons.getAndIncrement() < recoveryInfo.remainingCoupons()) { return couponQueue.offer(customerId) ? SecKillGrabResult.Success : SecKillGrabResult.Failed; } re...
### Question: SecKillRecoveryService { public SecKillRecoveryCheckResult<T> check(PromotionEntity promotion) { List<EventEntity> entities = this.repository.findByPromotionId(promotion.getPromotionId()); if (!entities.isEmpty()) { long count = entities.stream() .filter(event -> SecKillEventType.CouponGrabbedEvent.equals...
### Question: SpanTemplate implements SpanOperations { @Override public ActiveSpan startActive(String name) { return tracer.buildSpan(name) .startActive(); } SpanTemplate(Tracer tracer); @Override void doInTracer(SpanCallback callback); @Override Span start(String name); @Override ActiveSpan startActive(String name); @...
### Question: SpanTemplate implements SpanOperations { @Override public void inject(SpanContext ctx, HttpHeaders headers) { HttpHeadersInjectAdapter injectAdapter = new HttpHeadersInjectAdapter(headers); tracer.inject(ctx, Format.Builtin.HTTP_HEADERS, injectAdapter); } SpanTemplate(Tracer tracer); @Override void doInTr...
### Question: StateCapture { public static Executor capturingDecorator(final Executor executor) { if (stateCaptors.isEmpty() || executor instanceof CapturingExecutor) { return executor; } else { return new CapturingExecutor(executor); } } private StateCapture(); static Executor capturingDecorator(final Executor execut...
### Question: MXBeanPoller { public void shutdown() { running.set(false); executor.shutdown(); try { executor.awaitTermination(SHUTDOWN_TIMEOUT, TimeUnit.SECONDS); } catch (InterruptedException e) { executor.shutdownNow(); Thread.currentThread().interrupt(); } } MXBeanPoller(final MetricRecorder metricRecorder, ...
### Question: FileRecorder extends MetricRecorder<MetricRecorder.RecorderContext> { static boolean isValid(final Metric label) { final String str = label.toString(); return !(str.contains("\n") || str.contains(",") || str.contains(":") || str.contains("=")); } FileRecorder(final String filename); static final FileRecor...
### Question: DoubleFormat { public static void format(Appendable sb, double value) { try { format_exception(sb, value); } catch (IOException e) { throw new IllegalStateException("Appendable must not throw IOException", e); } } private DoubleFormat(); static void format(Appendable sb, double value); }### Answer: @Tes...
### Question: ContextAwareExecutor implements Executor { @Override public void execute(Runnable command) { executor.execute(ThreadContext.current().wrap(command)); } ContextAwareExecutor(Executor executor); @Override void execute(Runnable command); }### Answer: @Test public void currentContextIsPropagatedToTask() thro...
### Question: ImmutableTypedMap implements TypedMap { @Override public Set<Key> keySet() { return this.dataMap.keySet(); } private ImmutableTypedMap(Map<Key<?>, Entry<?>> dataMap); @Override final T get(Key<T> key); @Override int size(); @Override boolean isEmpty(); @Override Iterator<Entry> iterator(); @Override Iter...
### Question: ImmutableTypedMap implements TypedMap { @Override public <T> Set<Key<T>> typedKeySet(final Class<T> clazz) { Set<Key<T>> keys = new HashSet<>(); for (Key k : this.keySet()) { if (k.valueType.equals(clazz)) { keys.add(k); } } return Collections.unmodifiableSet(keys); } private ImmutableTypedMap(Map<Key<?>...
### Question: ImmutableTypedMap implements TypedMap { @Override public Iterator<Entry> iterator() { return this.dataMap.values().iterator(); } private ImmutableTypedMap(Map<Key<?>, Entry<?>> dataMap); @Override final T get(Key<T> key); @Override int size(); @Override boolean isEmpty(); @Override Iterator<Entry> iterat...
### Question: ImmutableTypedMap implements TypedMap { @Override public int size() { return this.dataMap.size(); } private ImmutableTypedMap(Map<Key<?>, Entry<?>> dataMap); @Override final T get(Key<T> key); @Override int size(); @Override boolean isEmpty(); @Override Iterator<Entry> iterator(); @Override Iterator<Entr...
### Question: ImmutableTypedMap implements TypedMap { @Override public <T> Iterator<Entry<T>> typedIterator(Class<T> clazz) { List<Entry<T>> entries = new ArrayList(); for (Iterator<Entry> it = this.iterator(); it.hasNext(); ) { final Entry e = it.next(); if (e.getKey().valueType.equals(clazz)) { entries.add(e); } } re...
### Question: NullContext implements MetricContext { @Override public TypedMap attributes() { return attributes; } NullContext(TypedMap attributes); NullContext(TypedMap attributes, MetricContext parent); static NullContext empty(); @Override TypedMap attributes(); @Override void record(Metric label, Number value, Un...
### Question: Metric { public static Metric define(final String name) { return new Metric(name); } private Metric(final String name); static Metric define(final String name); @Override final String toString(); @Override boolean equals(final Object o); @Override int hashCode(); }### Answer: @Test public void validatio...
### Question: MultiRecorder extends MetricRecorder<MultiRecorder.MultiRecorderContext> { @Override protected void record(Metric label, Number value, Unit unit, Instant time, MultiRecorderContext context) { context.contexts.parallelStream().forEach(t -> t.record(label, value, unit, time)); } MultiRecorder(List<MetricRec...
### Question: MultiRecorder extends MetricRecorder<MultiRecorder.MultiRecorderContext> { @Override protected void count(Metric label, long delta, MultiRecorderContext context) { context.contexts.parallelStream().forEach(t -> t.count(label, delta)); } MultiRecorder(List<MetricRecorder<?>> recorders); }### Answer: @Tes...
### Question: MultiRecorder extends MetricRecorder<MultiRecorder.MultiRecorderContext> { @Override protected void close(MultiRecorderContext context) { context.contexts.parallelStream().forEach(MetricContext::close); } MultiRecorder(List<MetricRecorder<?>> recorders); }### Answer: @Test public void closeIsSentToAllDe...