method2testcases
stringlengths
118
6.63k
### Question: SpringModelAdjuster implements ModelAdjuster { @Override public @Nullable Object adjust(@Nullable final Object obj) { if (obj instanceof Model) { final Model model = (Model) obj; return model.asMap().get("model"); } if (obj instanceof Map) { final Map map = (Map) obj; return map.get("model"); } return obj...
### Question: DefaultToSoyDataConverter implements ToSoyDataConverter { @Override public Optional<SoyMapData> toSoyMap(final Object model) throws Exception { if (model == null) { return Optional.absent(); } return Optional.fromNullable(objectToSoyDataMap(model)); } DefaultToSoyDataConverter(); void setIgnorableProperti...
### Question: SoyAjaxController { private ResponseEntity<String> compileJs(final String[] templateFileNames, final String hash, final boolean disableProcessors, final HttpServletRequest request, final String locale ) throws IOException { Preconditions.checkNotNull(templateFilesResolver, "templateFilesResolver cannot be...
### Question: DefaultToSoyDataConverter implements ToSoyDataConverter { @SuppressWarnings("unchecked") protected Map<String, ?> toSoyCompatibleMap(final Object obj) throws Exception { Object ret = toSoyCompatibleObjects(obj); if (!(ret instanceof Map)) { throw new IllegalArgumentException("Input should be a Map or POJO...
### Question: DefaultToSoyDataConverter implements ToSoyDataConverter { protected Object toSoyCompatibleObjects(Object obj) throws Exception { if (obj == null) { return obj; } if (Primitives.isWrapperType(obj.getClass()) || obj instanceof String) { return obj; } if(obj.getClass().isEnum()) { return ((Enum)obj).name(); ...
### Question: DefaultToSoyDataConverter implements ToSoyDataConverter { protected SoyMapData objectToSoyDataMap(Object obj) throws Exception { if (obj == null) { return new SoyMapData(); } if (obj instanceof SoyMapData) { return (SoyMapData) obj; } return new SoyMapData(toSoyCompatibleMap(obj)); } DefaultToSoyDataConve...
### Question: SoyAjaxController { @RequestMapping(value="/soy/compileJs", method=GET) public ResponseEntity<String> compile(@RequestParam(required = false, value="hash", defaultValue = "") final String hash, @RequestParam(required = true, value = "file") final String[] templateFileNames, @RequestParam(required = false,...
### Question: EmptyLocaleProvider implements LocaleProvider { @Override public Optional<Locale> resolveLocale(final HttpServletRequest request) { return Optional.absent(); } @Override Optional<Locale> resolveLocale(final HttpServletRequest request); }### Answer: @Test public void testShouldNotReturnNull() throws Exce...
### Question: DefaultLocaleProvider implements LocaleProvider { @Override public Optional<Locale> resolveLocale(final HttpServletRequest request) { return Optional.fromNullable(locale); } DefaultLocaleProvider(Locale locale); DefaultLocaleProvider(); @Override Optional<Locale> resolveLocale(final HttpServletRequest re...
### Question: AcceptHeaderLocaleProvider implements LocaleProvider { public Optional<Locale> resolveLocale(final HttpServletRequest request) { return Optional.fromNullable(request.getLocale()); } Optional<Locale> resolveLocale(final HttpServletRequest request); }### Answer: @Test public void shouldThrowNPE() throws E...
### Question: DefaultTemplateRenderer implements TemplateRenderer { public boolean isHotReloadMode() { return hotReloadMode; } @Override void render(final RenderRequest renderRequest); void setToSoyDataConverter(final ToSoyDataConverter toSoyDataConverter); void setHotReloadMode(boolean hotReloadMode); boolean isHotRe...
### Question: ConfigurableAuthManager implements AuthManager { @Override public boolean isAllowed(final String url) { return allowedTemplates.contains(url); } ConfigurableAuthManager(List<String> allowedTemplates); ConfigurableAuthManager(); void setAllowedTemplates(final List<String> allowedTemplates); @Override bool...
### Question: DefaultTemplateRenderer implements TemplateRenderer { @Override public void render(final RenderRequest renderRequest) throws Exception { if (!renderRequest.getCompiledTemplates().isPresent()) { logger.warn("compiled templates are not present, nothing to render!"); return; } final SoyTofu compiledTemplates...
### Question: EmptyTemplateRenderer implements TemplateRenderer { @Override public void render(final RenderRequest renderRequest) throws Exception { } @Override void render(final RenderRequest renderRequest); }### Answer: @Test public void testName() throws Exception { emptyTemplateRenderer.render(renderRequest); Moc...
### Question: DefaultContentNegotiator implements ContentNegotiator { @Override public List<String> contentTypes() { List<String> contentTypes = null; final HttpServletRequest request = getHttpRequest(); if (favorParameterOverAcceptHeader) { contentTypes = getFavoredParameterValueAsList(request); } else { contentTypes ...
### Question: DefaultTofuCompiler implements TofuCompiler { public boolean isHotReloadMode() { return hotReloadMode; } @Override SoyTofu compile(@Nullable final Collection<URL> urls); @Override final Optional<String> compileToJsSrc(@Nullable final URL url, @Nullable final SoyMsgBundle soyMsgBundle); @Override Collecti...
### Question: DefaultTofuCompiler implements TofuCompiler { public SoyJsSrcOptions getSoyJsSrcOptions() { return soyJsSrcOptions; } @Override SoyTofu compile(@Nullable final Collection<URL> urls); @Override final Optional<String> compileToJsSrc(@Nullable final URL url, @Nullable final SoyMsgBundle soyMsgBundle); @Over...
### Question: DefaultTofuCompiler implements TofuCompiler { @Override public SoyTofu compile(@Nullable final Collection<URL> urls) throws IOException { Preconditions.checkNotNull("compileTimeGlobalModelResolver", compileTimeGlobalModelResolver); if (urls == null || urls.isEmpty()) { throw new IOException("Unable to com...
### Question: PermissableAuthManager implements AuthManager { @Override public boolean isAllowed(String url) { return true; } @Override boolean isAllowed(String url); }### Answer: @Test public void testDefault() throws Exception { Assert.assertTrue("should allow all", permissableAuthManager.isAllowed("template")); }
### Question: CookieDataResolver implements RuntimeDataResolver { @Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { if (request.getCookies() == null) { logger.debug("no cookies!"); return; } for (fi...
### Question: RequestParametersDataResolver implements RuntimeDataResolver { @Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { for (final Enumeration e = request.getParameterNames(); e.hasMoreElemen...
### Question: RequestHeadersDataResolver implements RuntimeDataResolver { @Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, Map<String, ? extends Object> model, final SoyMapData root) { for (final Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { fin...
### Question: EmptyCompileTimeGlobalModelResolver implements CompileTimeGlobalModelResolver { public Optional<SoyMapData> resolveData() { return Optional.absent(); } Optional<SoyMapData> resolveData(); }### Answer: @Test public void notNull() throws Exception { Assert.assertNotNull("not null", defaultCompileTimeGloba...
### Question: DefaultCompileTimeGlobalModelResolver implements CompileTimeGlobalModelResolver { @Override public Optional<SoyMapData> resolveData() { if (data == null || data.isEmpty()) { return Optional.absent(); } return Optional.of(new SoyMapData(data)); } @Override Optional<SoyMapData> resolveData(); void setData(...
### Question: MD5HashFileGenerator implements HashFileGenerator, InitializingBean { public boolean isHotReloadMode() { return hotReloadMode; } void afterPropertiesSet(); @Override Optional<String> hash(final Optional<URL> url); @Override Optional<String> hashMulti(final Collection<URL> urls); static String getMD5Check...
### Question: DefaultCompileTimeGlobalModelResolver implements CompileTimeGlobalModelResolver { public void setProperties(final Properties properties) { data = new HashMap(); for (final String propertyName : properties.stringPropertyNames()) { data.put(propertyName, properties.getProperty(propertyName)); } } @Override...
### Question: ClasspathTemplateFilesResolver implements TemplateFilesResolver, InitializingBean { public boolean isHotReloadMode() { return hotReloadMode; } @Override void afterPropertiesSet(); @Override Collection<URL> resolve(); @Override Optional<URL> resolve(final @Nullable String templateFileName); void setTempla...
### Question: ClasspathTemplateFilesResolver implements TemplateFilesResolver, InitializingBean { public boolean isRecursive() { return recursive; } @Override void afterPropertiesSet(); @Override Collection<URL> resolve(); @Override Optional<URL> resolve(final @Nullable String templateFileName); void setTemplatesLocat...
### Question: ClasspathTemplateFilesResolver implements TemplateFilesResolver, InitializingBean { public void setRecursive(boolean recursive) { this.recursive = recursive; } @Override void afterPropertiesSet(); @Override Collection<URL> resolve(); @Override Optional<URL> resolve(final @Nullable String templateFileName...
### Question: ClasspathTemplateFilesResolver implements TemplateFilesResolver, InitializingBean { public String getTemplatesLocation() { return templatesLocation; } @Override void afterPropertiesSet(); @Override Collection<URL> resolve(); @Override Optional<URL> resolve(final @Nullable String templateFileName); void s...
### Question: ClasspathTemplateFilesResolver implements TemplateFilesResolver, InitializingBean { @Override public Collection<URL> resolve() throws IOException { Preconditions.checkNotNull(templatesLocation, "templatesLocation cannot be null!"); return Collections.unmodifiableCollection(handleResolution()); } @Overrid...
### Question: MD5HashFileGenerator implements HashFileGenerator, InitializingBean { public String getExpireAfterWriteUnit() { return expireAfterWriteUnit; } void afterPropertiesSet(); @Override Optional<String> hash(final Optional<URL> url); @Override Optional<String> hashMulti(final Collection<URL> urls); static Stri...
### Question: DefaultTemplateFilesResolver implements TemplateFilesResolver, ServletContextAware, InitializingBean { public boolean isHotReloadMode() { return hotReloadMode; } DefaultTemplateFilesResolver(); @Override void afterPropertiesSet(); @Override Collection<URL> resolve(); @Override Optional<URL> resolve(final ...
### Question: DefaultTemplateFilesResolver implements TemplateFilesResolver, ServletContextAware, InitializingBean { public boolean isRecursive() { return recursive; } DefaultTemplateFilesResolver(); @Override void afterPropertiesSet(); @Override Collection<URL> resolve(); @Override Optional<URL> resolve(final @Nullabl...
### Question: DefaultTemplateFilesResolver implements TemplateFilesResolver, ServletContextAware, InitializingBean { public void setRecursive(boolean recursive) { this.recursive = recursive; } DefaultTemplateFilesResolver(); @Override void afterPropertiesSet(); @Override Collection<URL> resolve(); @Override Optional<UR...
### Question: DefaultTemplateFilesResolver implements TemplateFilesResolver, ServletContextAware, InitializingBean { public Resource getTemplatesLocation() { return templatesLocation; } DefaultTemplateFilesResolver(); @Override void afterPropertiesSet(); @Override Collection<URL> resolve(); @Override Optional<URL> reso...
### Question: EmptyTemplateFilesResolver implements TemplateFilesResolver { @Override public Collection<URL> resolve() throws IOException { return Collections.emptyList(); } @Override Collection<URL> resolve(); @Override Optional<URL> resolve(final String templateName); }### Answer: @Test public void nonNull() throws...
### Question: MD5HashFileGenerator implements HashFileGenerator, InitializingBean { public int getExpireAfterWrite() { return expireAfterWrite; } void afterPropertiesSet(); @Override Optional<String> hash(final Optional<URL> url); @Override Optional<String> hashMulti(final Collection<URL> urls); static String getMD5Ch...
### Question: DefaultSoyMsgBundleResolver implements SoyMsgBundleResolver { public boolean isHotReloadMode() { return hotReloadMode; } Optional<SoyMsgBundle> resolve(final Optional<Locale> locale); void setMessagesPath(final String messagesPath); void setHotReloadMode(final boolean hotReloadMode); void setFallbackToEn...
### Question: DefaultSoyMsgBundleResolver implements SoyMsgBundleResolver { public String getMessagesPath() { return messagesPath; } Optional<SoyMsgBundle> resolve(final Optional<Locale> locale); void setMessagesPath(final String messagesPath); void setHotReloadMode(final boolean hotReloadMode); void setFallbackToEngl...
### Question: DefaultSoyMsgBundleResolver implements SoyMsgBundleResolver { public boolean isFallbackToEnglish() { return fallbackToEnglish; } Optional<SoyMsgBundle> resolve(final Optional<Locale> locale); void setMessagesPath(final String messagesPath); void setHotReloadMode(final boolean hotReloadMode); void setFall...
### Question: DefaultSoyMsgBundleResolver implements SoyMsgBundleResolver { public Optional<SoyMsgBundle> resolve(final Optional<Locale> locale) throws IOException { if (!locale.isPresent()) { return Optional.absent(); } synchronized (msgBundles) { SoyMsgBundle soyMsgBundle = null; if (isHotReloadModeOff()) { soyMsgBun...
### Question: EmptySoyMsgBundleResolver implements SoyMsgBundleResolver { @Override public Optional<SoyMsgBundle> resolve(final Optional<Locale> locale) throws IOException { return Optional.absent(); } @Override Optional<SoyMsgBundle> resolve(final Optional<Locale> locale); }### Answer: @Test public void defaultNull(...
### Question: MD5HashFileGenerator implements HashFileGenerator, InitializingBean { public int getCacheMaxSize() { return cacheMaxSize; } void afterPropertiesSet(); @Override Optional<String> hash(final Optional<URL> url); @Override Optional<String> hashMulti(final Collection<URL> urls); static String getMD5Checksum(f...
### Question: Value implements Cloneable { @Nonnull public final T get() { return value; } protected Value(@Nonnull final T value); @Nonnull abstract Class<T> type(); @Nonnull final T get(); @Nonnull final W map( @Nonnull final Function<? super T, ? extends W> mapper); @SuppressWarnings({"CloneDoesntCallSu...
### Question: XProperties extends OrderedProperties { @Nullable @Override public String getProperty(final String key) { final String value = super.getProperty(key); if (null == value) return null; return substitutor.replace(value); } XProperties(); XProperties(@Nonnull final Map<String, String> initial); @Nonnull stat...
### Question: XProperties extends OrderedProperties { @Nullable public <T> T getObject(@Nonnull final String key) { return getObjectOrDefault(key, null); } XProperties(); XProperties(@Nonnull final Map<String, String> initial); @Nonnull static XProperties from(@Nonnull @NonNull final String absolutePath); void registe...
### Question: XProperties extends OrderedProperties { @Nonnull public static XProperties from(@Nonnull @NonNull final String absolutePath) throws IOException { final Resource resource = new PathMatchingResourcePatternResolver() .getResource(absolutePath); try (final InputStream in = resource.getInputStream()) { final X...
### Question: StackTraceFocuser implements Function<E, E> { @Nonnull public static <E extends Throwable> StackTraceFocuser<E> ignoreJavaClasses() { return ignoreClassNames(defaultClassNameIgnores); } StackTraceFocuser(@Nonnull final Iterable<Predicate<StackTraceElement>> ignores); @SafeVarargs StackTraceFocuser(@Nonnu...
### Question: StackTraceFocuser implements Function<E, E> { @Nonnull public static Predicate<StackTraceElement> ignoreClassName(@Nonnull final Pattern className) { return frame -> className.matcher(frame.getClassName()).find(); } StackTraceFocuser(@Nonnull final Iterable<Predicate<StackTraceElement>> ignores); @SafeVar...
### Question: StackTraceFocuser implements Function<E, E> { @Nonnull public static Predicate<StackTraceElement> ignoreMethodName(@Nonnull final Pattern methodName) { return frame -> methodName.matcher(frame.getMethodName()).find(); } StackTraceFocuser(@Nonnull final Iterable<Predicate<StackTraceElement>> ignores); @Saf...
### Question: StackTraceFocuser implements Function<E, E> { @Nonnull public static Predicate<StackTraceElement> ignoreFileName(@Nonnull final Pattern fileName) { return frame -> fileName.matcher(frame.getFileName()).find(); } StackTraceFocuser(@Nonnull final Iterable<Predicate<StackTraceElement>> ignores); @SafeVarargs...
### Question: StackTraceFocuser implements Function<E, E> { @Nonnull public static Predicate<StackTraceElement> ignoreLineNumber(@Nonnull final Pattern lineNumber) { return frame -> lineNumber.matcher(String.valueOf(frame.getLineNumber())).find(); } StackTraceFocuser(@Nonnull final Iterable<Predicate<StackTraceElement>...
### Question: LinkedIterable implements Iterable<T> { @Nonnull public static <T> Iterable<T> over(@Nullable final T head, @Nonnull final Predicate<T> terminate, @Nonnull final Function<T, T> traverse) { return new LinkedIterable<>(head, terminate, traverse); } private LinkedIterable(final T head, final Predicate<T> te...
### Question: XProperties extends OrderedProperties { @Override public synchronized void load(@Nonnull final Reader reader) throws IOException { final ResourcePatternResolver loader = new PathMatchingResourcePatternResolver(); try (final CharArrayWriter writer = new CharArrayWriter()) { try (final BufferedReader lines ...
### Question: Converter { @Nonnull public <T> T convert(@Nonnull final Class<T> type, @Nonnull final String value) throws Exception { return convert(TypeToken.of(wrap(type)), value); } void register(@Nonnull final Class<T> type, @Nonnull final Conversion<T, ?> factory); void register(@Nonnull final TypeToken<T> type, ...
### Question: Converter { public <T> void register(@Nonnull final Class<T> type, @Nonnull final Conversion<T, ?> factory) throws DuplicateConversion { register(TypeToken.of(type), factory); } void register(@Nonnull final Class<T> type, @Nonnull final Conversion<T, ?> factory); void register(@Nonnull final TypeToken<T>...
### Question: XProperties extends OrderedProperties { @Nullable @Override public synchronized Object get(final Object key) { final Object value = super.get(key); if (null == value || !(value instanceof String)) return value; return substitutor.replace((String) value); } XProperties(); XProperties(@Nonnull final Map<St...
### Question: SPAlgorithms { public static List<Path> kShortestPaths(Graph g, Node origin, Node destination, Integer K) throws Exception{ List<Path> A = new LinkedList<Path>(); PriorityQueue<Path> B = new PriorityQueue<Path>(); A.add(SPAlgorithms.dijkstra(g, origin,destination)); if (A.get(0) == null) throw new Excepti...
### Question: Gateway3DSecureActivity extends AppCompatActivity { String getExtraTitle() { Bundle extras = getIntent().getExtras(); if (extras != null) { return extras.getString(EXTRA_TITLE); } return null; } static final String EXTRA_HTML; static final String EXTRA_TITLE; static final String EXTRA_ACS_RESULT; }### A...
### Question: GatewayMap extends LinkedHashMap<String, Object> { @Override public Object get(Object keyPath) { String[] keys = ((String) keyPath).split("\\."); if (keys.length <= 1) { Matcher m = arrayIndexPattern.matcher(keys[0]); if (!m.matches()) { return super.get(keys[0]); } else { String key = m.group(1); Object ...
### Question: Gateway { public Gateway setMerchantId(String merchantId) { if (merchantId == null) { throw new IllegalArgumentException("Merchant ID may not be null"); } this.merchantId = merchantId; return this; } Gateway(); String getMerchantId(); Gateway setMerchantId(String merchantId); Region getRegion(); Gateway s...
### Question: Gateway { public Gateway setRegion(Region region) { if (region == null) { throw new IllegalArgumentException("Region may not be null"); } this.region = region; return this; } Gateway(); String getMerchantId(); Gateway setMerchantId(String merchantId); Region getRegion(); Gateway setRegion(Region region); ...
### Question: Gateway { public static void start3DSecureActivity(Activity activity, String html) { start3DSecureActivity(activity, html, null); } Gateway(); String getMerchantId(); Gateway setMerchantId(String merchantId); Region getRegion(); Gateway setRegion(Region region); void updateSession(String sessionId, String...
### Question: Gateway { public static boolean handle3DSecureResult(int requestCode, int resultCode, Intent data, Gateway3DSecureCallback callback) { if (callback == null) { return false; } if (requestCode == REQUEST_3D_SECURE) { if (resultCode == Activity.RESULT_OK) { String acsResultJson = data.getStringExtra(Gateway3...
### Question: Gateway { public static boolean handleGooglePayResult(int requestCode, int resultCode, Intent data, GatewayGooglePayCallback callback) { if (callback == null) { return false; } if (requestCode == REQUEST_GOOGLE_PAY_LOAD_PAYMENT_DATA) { if (resultCode == Activity.RESULT_OK) { try { PaymentData paymentData ...
### Question: Gateway { String getApiUrl(String apiVersion) { if (Integer.valueOf(apiVersion) < MIN_API_VERSION) { throw new IllegalArgumentException("API version must be >= " + MIN_API_VERSION); } if (region == null) { throw new IllegalStateException("You must initialize the the Gateway instance with a Region before u...
### Question: Gateway3DSecureActivity extends AppCompatActivity { String getExtraHtml() { Bundle extras = getIntent().getExtras(); if (extras != null) { return extras.getString(EXTRA_HTML); } return null; } static final String EXTRA_HTML; static final String EXTRA_TITLE; static final String EXTRA_ACS_RESULT; }### Ans...
### Question: Gateway { String getUpdateSessionUrl(String sessionId, String apiVersion) { if (sessionId == null) { throw new IllegalArgumentException("Session Id may not be null"); } if (merchantId == null) { throw new IllegalStateException("You must initialize the the Gateway instance with a Merchant Id before use"); ...
### Question: Gateway { @SuppressWarnings("unchecked") boolean handleCallbackMessage(GatewayCallback callback, Object arg) { if (callback != null) { if (arg instanceof Throwable) { callback.onError((Throwable) arg); } else { callback.onSuccess((GatewayMap) arg); } } return true; } Gateway(); String getMerchantId(); Gat...
### Question: Gateway { boolean isStatusCodeOk(int statusCode) { return (statusCode >= 200 && statusCode < 300); } Gateway(); String getMerchantId(); Gateway setMerchantId(String merchantId); Region getRegion(); Gateway setRegion(Region region); void updateSession(String sessionId, String apiVersion, GatewayMap payload...
### Question: Gateway { String inputStreamToString(InputStream is) throws IOException { BufferedReader rd = new BufferedReader(new InputStreamReader(is)); StringBuilder total = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { total.append(line); } return total.toString(); } Gateway(); String g...
### Question: Gateway { String createAuthHeader(String sessionId) { String value = "merchant." + merchantId + ":" + sessionId; return "Basic " + Base64.encodeToString(value.getBytes(), Base64.NO_WRAP); } Gateway(); String getMerchantId(); Gateway setMerchantId(String merchantId); Region getRegion(); Gateway setRegion(R...
### Question: Gateway3DSecureActivity extends AppCompatActivity { void setWebViewHtml(String html) { String encoded = Base64.encodeToString(html.getBytes(), Base64.NO_PADDING | Base64.NO_WRAP); webView.loadData(encoded, "text/html", "base64"); } static final String EXTRA_HTML; static final String EXTRA_TITLE; static ...
### Question: Gateway3DSecureActivity extends AppCompatActivity { void intentToEmail(Uri uri) { Intent emailIntent = new Intent(Intent.ACTION_SENDTO); intentToEmail(uri, emailIntent); } static final String EXTRA_HTML; static final String EXTRA_TITLE; static final String EXTRA_ACS_RESULT; }### Answer: @Test public voi...
### Question: Gateway3DSecureActivity extends AppCompatActivity { void complete(String acsResult) { Intent intent = new Intent(); complete(acsResult, intent); } static final String EXTRA_HTML; static final String EXTRA_TITLE; static final String EXTRA_ACS_RESULT; }### Answer: @Test public void testCompleteWorksAsExpe...
### Question: Gateway3DSecureActivity extends AppCompatActivity { String getACSResultFromUri(Uri uri) { String result = null; Set<String> params = uri.getQueryParameterNames(); for (String param : params) { if ("acsResult".equalsIgnoreCase(param)) { result = uri.getQueryParameter(param); } } return result; } static f...
### Question: GatewaySSLContextProvider { X509Certificate readCertificate(String cert) throws CertificateException { byte[] bytes = cert.getBytes(); InputStream is = new ByteArrayInputStream(bytes); return (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(is); } GatewaySSLContextProvider(); ...
### Question: GatewayMap extends LinkedHashMap<String, Object> { @Override public Object put(String keyPath, Object value) { String[] properties = keyPath.split("\\."); Map<String, Object> destinationObject = this; if (properties.length > 1) { for (int i = 0; i < (properties.length - 1); i++) { String property = proper...
### Question: ForkedFrameworkFactory { public RemoteFramework fork(List<String> vmArgs, Map<String, String> systemProperties, Map<String, Object> frameworkProperties, List<String> beforeFrameworkClasspath, List<String> afterFrameworkClasspath) { port = getPort(); LOG.debug("using RMI registry at port {}", port); String...
### Question: ForkedFrameworkFactory { protected int getPort() { String configuredPort = System.getProperty(EXAM_FORKED_INVOKER_PORT); if (configuredPort != null) { return Integer.parseInt(configuredPort); } else { int lowerBound = Integer.parseInt(System.getProperty(EXAM_FORKED_INVOKER_PORT_RANGE_LOWERBOUND, "21000"))...
### Question: DependenciesDeployer { static void writeDependenciesFeature(Writer writer, ProvisionOption<?>... provisionOptions) { XMLOutputFactory xof = XMLOutputFactory.newInstance(); xof.setProperty("javax.xml.stream.isRepairingNamespaces", true); XMLStreamWriter sw = null; try { sw = xof.createXMLStreamWriter(write...
### Question: JavaVersionUtil { public static int getMajorVersion() { return getMajorVersion(System.getProperty("java.specification.version")); } static int getMajorVersion(); }### Answer: @Test public void testVersions() { assertEquals(8, JavaVersionUtil.getMajorVersion("1.8.0_171")); assertEquals(9, JavaVersionUtil...
### Question: KarafConfigFile extends KarafConfigurationFile { @Override public void store() throws IOException { final FileOutputStream fos = new FileOutputStream(file); ConfigurationHandler.write(fos, configuration); fos.close(); } KarafConfigFile(File karafHome, String location); @Override void store(); @SuppressWar...
### Question: KarafConfigFile extends KarafConfigurationFile { @SuppressWarnings("unchecked") @Override public void load() throws IOException { if (!file.exists()) { return; } final FileInputStream fis = new FileInputStream(file); configuration = ConfigurationHandler.read(fis); fis.close(); } KarafConfigFile(File karaf...
### Question: KarafConfigFile extends KarafConfigurationFile { @Override public void put(final String key, final Object value) { configuration.put(key, value); } KarafConfigFile(File karafHome, String location); @Override void store(); @SuppressWarnings("unchecked") @Override void load(); @Override void put(final Strin...
### Question: KarafConfigFile extends KarafConfigurationFile { @Override public Object get(final String key) { return configuration.get(key); } KarafConfigFile(File karafHome, String location); @Override void store(); @SuppressWarnings("unchecked") @Override void load(); @Override void put(final String key, final Objec...
### Question: FileFinder { public static File findFile(File rootDir, final String fileName) { FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.equals(fileName); } }; return findFile(rootDir, filter); } private FileFinder(); static File findFile(File ro...
### Question: WarBuilder { public URI buildWar() { if (option.getName() == null) { option.name(UUID.randomUUID().toString()); } processClassPath(); try { File webResourceDir = getWebResourceDir(); File probeWar = new File(tempDir, option.getName() + ".war"); ZipBuilder builder = new ZipBuilder(probeWar); for (String li...
### Question: RemoteBundleContextImpl implements RemoteBundleContext, Serializable { @Override public Object remoteCall(final Class<?> serviceType, final String methodName, final Class<?>[] methodParams, String filter, final RelativeTimeout timeout, final Object... actualParams) throws NoSuchServiceException, NoSuchMet...
### Question: ConfigurationManager { public void loadSystemProperties(String configurationKey) { String propertyRef = getProperty(configurationKey); if (propertyRef == null) { return; } if (propertyRef.startsWith("env:")) { propertyRef = propertyRef.substring(4); propertyRef = System.getenv(propertyRef); } if (!propert...
### Question: AdminHandler { public Result showAdmin(Context context) { return Results.html(); } Result showAdmin(Context context); Result showUsers(Context context); Result showSummedTransactions(Context context); Result pagedMTX(Context context, @Param("p") int page); Result deleteMTXProcess(@PathParam("time") Integ...
### Question: MailboxApiController extends AbstractApiController { public Result createMailbox(@JSR303Validation final MailboxData mailboxData, @Attribute("user") final User user, final Context context) { if (context.getValidation().hasViolations()) { return ApiResults.badRequest(context.getValidation().getViolations()...
### Question: MailboxApiController extends AbstractApiController { public Result getMailbox(@PathParam("mailboxAddress") @Email final String mailboxAddress, @Attribute("userId") @DbId final Long userId, final Context context) { return performAction(userId, mailboxAddress, context, mailbox -> { final MailboxData mailbox...
### Question: MailboxApiController extends AbstractApiController { public Result updateMailbox(@PathParam("mailboxAddress") @Email final String mailboxAddress, @JSR303Validation final MailboxData mailboxData, @Attribute("userId") @DbId final Long userId, final Context context) { return performAction(userId, mailboxAddr...
### Question: MailboxApiController extends AbstractApiController { public Result deleteMailbox(@PathParam("mailboxAddress") @Email final String mailboxAddress, @Attribute("userId") @DbId final Long userId, final Context context) { return performAction(userId, mailboxAddress, context, mailbox -> { mailbox.delete(); retu...
### Question: AdminHandler { public Result jsonUserSearch(Context context) { List<User> userList; String searchString = context.getParameter("s", ""); userList = (searchString.equals("")) ? new ArrayList<User>() : User.findUserLike(searchString); UserFormData userData; List<UserFormData> userDatalist = new ArrayList<Us...
### Question: MailApiController extends AbstractApiController { public Result getMail(@PathParam("mailId") @DbId final Long mailId, @Attribute("userId") @DbId final Long userId, final Context context) { return performAction(mailId, userId, context, mail -> { try { final MailData mailData = new MailData(mail); return Ap...
### Question: MailApiController extends AbstractApiController { public Result getMailAttachment(@PathParam("mailId") @DbId final Long mailId, @PathParam("attachmentName") @NotBlank final String attachmentName, @Attribute("userId") @DbId final Long userId, final Context context) { return performAction(mailId, userId, co...
### Question: MailApiController extends AbstractApiController { public Result deleteMail(@PathParam("mailId") @DbId final Long mailId, @Attribute("userId") @DbId final Long userId, final Context context) { return performAction(mailId, userId, context, mail -> { mail.delete(); return ApiResults.noContent(); }); } Resul...