repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
kawasima/moshas | moshas/src/test/java/net/unit8/moshas/MoshasEngineTest.java | // Path: moshas/src/main/java/net/unit8/moshas/context/Context.java
// public class Context extends AbstractContext {
//
// public Context() {
// super();
// }
//
// public Context(Map<String, Object> variables) {
// super();
// for (Map.Entry<String, Object> entry : variables.entrySet()) {
// setVariable(entry.getKey(), entry.getValue());
// }
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateNotFoundException.java
// public class TemplateNotFoundException extends RuntimeException {
// public TemplateNotFoundException(String msg) {
// super(msg);
// }
//
// public TemplateNotFoundException(String msg, Exception cause) {
// super(msg, cause);
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/RenderUtils.java
// public static RenderFunction text(String... keys) {
// return (el, ctx) -> el.text(ctx.getString(keys));
// }
| import net.unit8.moshas.context.Context;
import net.unit8.moshas.loader.TemplateNotFoundException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.io.StringWriter;
import java.util.Locale;
import static net.unit8.moshas.RenderUtils.text; | package net.unit8.moshas;
/**
* @author kawasima
*/
@RunWith(Parameterized.class)
public class MoshasEngineTest {
@Parameterized.Parameter(0)
public MoshasEngine engine;
@Parameterized.Parameters(name = "engine [{0}]")
public static Object[][] arguments() {
return new Object[][]{
{new MoshasEngine()},
{new MoshasEngine(new StandardTemplateManager(new ConcurrentHashMapTemplateCache()))}
};
}
@Test(expected = TemplateNotFoundException.class)
public void test() {
engine.describe("notfound", t -> {});
}
@Test
public void test1() {
Template template = engine.describe("META-INF/templates/index.html", t -> {});
Context context = new Context();
StringWriter writer = new StringWriter();
template.render(context, writer);
System.out.println(writer.toString());
}
@Test
public void variableNotFound() { | // Path: moshas/src/main/java/net/unit8/moshas/context/Context.java
// public class Context extends AbstractContext {
//
// public Context() {
// super();
// }
//
// public Context(Map<String, Object> variables) {
// super();
// for (Map.Entry<String, Object> entry : variables.entrySet()) {
// setVariable(entry.getKey(), entry.getValue());
// }
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateNotFoundException.java
// public class TemplateNotFoundException extends RuntimeException {
// public TemplateNotFoundException(String msg) {
// super(msg);
// }
//
// public TemplateNotFoundException(String msg, Exception cause) {
// super(msg, cause);
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/RenderUtils.java
// public static RenderFunction text(String... keys) {
// return (el, ctx) -> el.text(ctx.getString(keys));
// }
// Path: moshas/src/test/java/net/unit8/moshas/MoshasEngineTest.java
import net.unit8.moshas.context.Context;
import net.unit8.moshas.loader.TemplateNotFoundException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.io.StringWriter;
import java.util.Locale;
import static net.unit8.moshas.RenderUtils.text;
package net.unit8.moshas;
/**
* @author kawasima
*/
@RunWith(Parameterized.class)
public class MoshasEngineTest {
@Parameterized.Parameter(0)
public MoshasEngine engine;
@Parameterized.Parameters(name = "engine [{0}]")
public static Object[][] arguments() {
return new Object[][]{
{new MoshasEngine()},
{new MoshasEngine(new StandardTemplateManager(new ConcurrentHashMapTemplateCache()))}
};
}
@Test(expected = TemplateNotFoundException.class)
public void test() {
engine.describe("notfound", t -> {});
}
@Test
public void test1() {
Template template = engine.describe("META-INF/templates/index.html", t -> {});
Context context = new Context();
StringWriter writer = new StringWriter();
template.render(context, writer);
System.out.println(writer.toString());
}
@Test
public void variableNotFound() { | Template template = engine.describe("META-INF/templates/index.html", t -> t.select("#message", text("message", "japanese"))); |
kawasima/moshas | moshas-servlet/src/test/java/net/unit8/moshas/servlet/MoshasServletTest.java | // Path: moshas-servlet/src/main/java/net/unit8/moshas/ServletMoshasEngineProvier.java
// public class ServletMoshasEngineProvier {
// private static MoshasEngine engine = new MoshasEngine();
//
// public static void init(Consumer<MoshasEngine> initializer) {
// initializer.accept(engine);
// }
//
// public static MoshasEngine get() {
// return engine;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/RenderUtils.java
// public static RenderFunction text(String... keys) {
// return (el, ctx) -> el.text(ctx.getString(keys));
// }
| import net.unit8.moshas.ServletMoshasEngineProvier;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import static net.unit8.moshas.RenderUtils.text;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; | package net.unit8.moshas.servlet;
/**
* @author kawasima
*/
public class MoshasServletTest {
@Test
public void test() throws IOException, ServletException {
MoshasServlet servlet = new MoshasServlet();
ServletConfig config = mock(ServletConfig.class);
ServletContext context = mock(ServletContext.class);
when(config.getServletContext()).thenReturn(context);
servlet.init(config);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletPath()).thenReturn("/test.html");
when(context.getResourceAsStream(anyString())).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
return ClassLoader.getSystemResourceAsStream(args[0].toString());
}); | // Path: moshas-servlet/src/main/java/net/unit8/moshas/ServletMoshasEngineProvier.java
// public class ServletMoshasEngineProvier {
// private static MoshasEngine engine = new MoshasEngine();
//
// public static void init(Consumer<MoshasEngine> initializer) {
// initializer.accept(engine);
// }
//
// public static MoshasEngine get() {
// return engine;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/RenderUtils.java
// public static RenderFunction text(String... keys) {
// return (el, ctx) -> el.text(ctx.getString(keys));
// }
// Path: moshas-servlet/src/test/java/net/unit8/moshas/servlet/MoshasServletTest.java
import net.unit8.moshas.ServletMoshasEngineProvier;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import static net.unit8.moshas.RenderUtils.text;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
package net.unit8.moshas.servlet;
/**
* @author kawasima
*/
public class MoshasServletTest {
@Test
public void test() throws IOException, ServletException {
MoshasServlet servlet = new MoshasServlet();
ServletConfig config = mock(ServletConfig.class);
ServletContext context = mock(ServletContext.class);
when(config.getServletContext()).thenReturn(context);
servlet.init(config);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletPath()).thenReturn("/test.html");
when(context.getResourceAsStream(anyString())).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
return ClassLoader.getSystemResourceAsStream(args[0].toString());
}); | ServletMoshasEngineProvier.get().describe("/test.html", t -> { |
kawasima/moshas | moshas-servlet/src/test/java/net/unit8/moshas/servlet/MoshasServletTest.java | // Path: moshas-servlet/src/main/java/net/unit8/moshas/ServletMoshasEngineProvier.java
// public class ServletMoshasEngineProvier {
// private static MoshasEngine engine = new MoshasEngine();
//
// public static void init(Consumer<MoshasEngine> initializer) {
// initializer.accept(engine);
// }
//
// public static MoshasEngine get() {
// return engine;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/RenderUtils.java
// public static RenderFunction text(String... keys) {
// return (el, ctx) -> el.text(ctx.getString(keys));
// }
| import net.unit8.moshas.ServletMoshasEngineProvier;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import static net.unit8.moshas.RenderUtils.text;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; | package net.unit8.moshas.servlet;
/**
* @author kawasima
*/
public class MoshasServletTest {
@Test
public void test() throws IOException, ServletException {
MoshasServlet servlet = new MoshasServlet();
ServletConfig config = mock(ServletConfig.class);
ServletContext context = mock(ServletContext.class);
when(config.getServletContext()).thenReturn(context);
servlet.init(config);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletPath()).thenReturn("/test.html");
when(context.getResourceAsStream(anyString())).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
return ClassLoader.getSystemResourceAsStream(args[0].toString());
});
ServletMoshasEngineProvier.get().describe("/test.html", t -> { | // Path: moshas-servlet/src/main/java/net/unit8/moshas/ServletMoshasEngineProvier.java
// public class ServletMoshasEngineProvier {
// private static MoshasEngine engine = new MoshasEngine();
//
// public static void init(Consumer<MoshasEngine> initializer) {
// initializer.accept(engine);
// }
//
// public static MoshasEngine get() {
// return engine;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/RenderUtils.java
// public static RenderFunction text(String... keys) {
// return (el, ctx) -> el.text(ctx.getString(keys));
// }
// Path: moshas-servlet/src/test/java/net/unit8/moshas/servlet/MoshasServletTest.java
import net.unit8.moshas.ServletMoshasEngineProvier;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import static net.unit8.moshas.RenderUtils.text;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
package net.unit8.moshas.servlet;
/**
* @author kawasima
*/
public class MoshasServletTest {
@Test
public void test() throws IOException, ServletException {
MoshasServlet servlet = new MoshasServlet();
ServletConfig config = mock(ServletConfig.class);
ServletContext context = mock(ServletContext.class);
when(config.getServletContext()).thenReturn(context);
servlet.init(config);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletPath()).thenReturn("/test.html");
when(context.getResourceAsStream(anyString())).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
return ClassLoader.getSystemResourceAsStream(args[0].toString());
});
ServletMoshasEngineProvier.get().describe("/test.html", t -> { | t.select("#message", (el, ctx) -> el.text("HELLO SERVLET")); |
kawasima/moshas | moshas/src/main/java/net/unit8/moshas/StandardTemplateManager.java | // Path: moshas/src/main/java/net/unit8/moshas/cache/JCacheTemplateCache.java
// public class JCacheTemplateCache implements TemplateCache {
// private final Cache<String, Template> cache;
//
// public JCacheTemplateCache() {
// Iterator<CachingProvider> cachingProviders = Caching.getCachingProviders().iterator();
// if (cachingProviders.hasNext()) {
// CachingProvider cachingProvider = cachingProviders.next();
// CacheManager cacheManager = cachingProvider.getCacheManager();
// Configuration<String, Template> config = new MutableConfiguration<String, Template>()
// .setTypes(String.class, Template.class)
// .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));
// Cache<String, Template> cache = cacheManager.getCache("TemplateCache", String.class, Template.class);
// if (cache == null) {
// this.cache = cacheManager.createCache("TemplateCache", config);
// } else {
// this.cache = cache;
// }
// } else {
// this.cache = null; // to keep compatibility with 0.1.0, but ugly
// }
// }
//
// @Override
// public Template getTemplate(String source) {
// if (this.cache == null) {
// return null;
// }
// return this.cache.get(source);
// }
//
// @Override
// public void putTemplate(String source, Template template) {
// if (this.cache == null) {
// return;
// }
// this.cache.put(source, template);
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/cache/TemplateCache.java
// public interface TemplateCache {
// Template getTemplate(String source);
//
// void putTemplate(String source, Template template);
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/ResourceTemplateLoader.java
// public class ResourceTemplateLoader extends TemplateLoader {
// private String prefix;
// private String suffix;
//
// @Override
// public InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// if (cl == null) {
// cl = getClass().getClassLoader();
// }
//
// if (prefix != null) {
// templateSource = prefix + templateSource;
// }
// if (suffix != null) {
// templateSource = templateSource + suffix;
// }
//
// if (templateSource.startsWith("/")) {
// templateSource = templateSource.replaceAll("^/(.*)", "$1");
// }
// InputStream is = cl.getResourceAsStream(templateSource);
// if (is == null) {
// throw new TemplateNotFoundException("Can't find template " + templateSource);
// }
//
// return is;
// }
//
// public void setPrefix(String prefix) {
// this.prefix = prefix;
// }
//
// public void setSuffix(String suffix) {
// this.suffix = suffix;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateLoader.java
// public abstract class TemplateLoader {
// public abstract InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException;
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateNotFoundException.java
// public class TemplateNotFoundException extends RuntimeException {
// public TemplateNotFoundException(String msg) {
// super(msg);
// }
//
// public TemplateNotFoundException(String msg, Exception cause) {
// super(msg, cause);
// }
// }
| import net.unit8.moshas.cache.JCacheTemplateCache;
import net.unit8.moshas.cache.TemplateCache;
import net.unit8.moshas.loader.ResourceTemplateLoader;
import net.unit8.moshas.loader.TemplateLoader;
import net.unit8.moshas.loader.TemplateNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; | package net.unit8.moshas;
/**
*
* @author kawasima
*/
public class StandardTemplateManager implements TemplateManager {
private List<TemplateLoader> templateLoaders; | // Path: moshas/src/main/java/net/unit8/moshas/cache/JCacheTemplateCache.java
// public class JCacheTemplateCache implements TemplateCache {
// private final Cache<String, Template> cache;
//
// public JCacheTemplateCache() {
// Iterator<CachingProvider> cachingProviders = Caching.getCachingProviders().iterator();
// if (cachingProviders.hasNext()) {
// CachingProvider cachingProvider = cachingProviders.next();
// CacheManager cacheManager = cachingProvider.getCacheManager();
// Configuration<String, Template> config = new MutableConfiguration<String, Template>()
// .setTypes(String.class, Template.class)
// .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));
// Cache<String, Template> cache = cacheManager.getCache("TemplateCache", String.class, Template.class);
// if (cache == null) {
// this.cache = cacheManager.createCache("TemplateCache", config);
// } else {
// this.cache = cache;
// }
// } else {
// this.cache = null; // to keep compatibility with 0.1.0, but ugly
// }
// }
//
// @Override
// public Template getTemplate(String source) {
// if (this.cache == null) {
// return null;
// }
// return this.cache.get(source);
// }
//
// @Override
// public void putTemplate(String source, Template template) {
// if (this.cache == null) {
// return;
// }
// this.cache.put(source, template);
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/cache/TemplateCache.java
// public interface TemplateCache {
// Template getTemplate(String source);
//
// void putTemplate(String source, Template template);
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/ResourceTemplateLoader.java
// public class ResourceTemplateLoader extends TemplateLoader {
// private String prefix;
// private String suffix;
//
// @Override
// public InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// if (cl == null) {
// cl = getClass().getClassLoader();
// }
//
// if (prefix != null) {
// templateSource = prefix + templateSource;
// }
// if (suffix != null) {
// templateSource = templateSource + suffix;
// }
//
// if (templateSource.startsWith("/")) {
// templateSource = templateSource.replaceAll("^/(.*)", "$1");
// }
// InputStream is = cl.getResourceAsStream(templateSource);
// if (is == null) {
// throw new TemplateNotFoundException("Can't find template " + templateSource);
// }
//
// return is;
// }
//
// public void setPrefix(String prefix) {
// this.prefix = prefix;
// }
//
// public void setSuffix(String suffix) {
// this.suffix = suffix;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateLoader.java
// public abstract class TemplateLoader {
// public abstract InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException;
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateNotFoundException.java
// public class TemplateNotFoundException extends RuntimeException {
// public TemplateNotFoundException(String msg) {
// super(msg);
// }
//
// public TemplateNotFoundException(String msg, Exception cause) {
// super(msg, cause);
// }
// }
// Path: moshas/src/main/java/net/unit8/moshas/StandardTemplateManager.java
import net.unit8.moshas.cache.JCacheTemplateCache;
import net.unit8.moshas.cache.TemplateCache;
import net.unit8.moshas.loader.ResourceTemplateLoader;
import net.unit8.moshas.loader.TemplateLoader;
import net.unit8.moshas.loader.TemplateNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
package net.unit8.moshas;
/**
*
* @author kawasima
*/
public class StandardTemplateManager implements TemplateManager {
private List<TemplateLoader> templateLoaders; | private final TemplateCache cache; |
kawasima/moshas | moshas/src/main/java/net/unit8/moshas/StandardTemplateManager.java | // Path: moshas/src/main/java/net/unit8/moshas/cache/JCacheTemplateCache.java
// public class JCacheTemplateCache implements TemplateCache {
// private final Cache<String, Template> cache;
//
// public JCacheTemplateCache() {
// Iterator<CachingProvider> cachingProviders = Caching.getCachingProviders().iterator();
// if (cachingProviders.hasNext()) {
// CachingProvider cachingProvider = cachingProviders.next();
// CacheManager cacheManager = cachingProvider.getCacheManager();
// Configuration<String, Template> config = new MutableConfiguration<String, Template>()
// .setTypes(String.class, Template.class)
// .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));
// Cache<String, Template> cache = cacheManager.getCache("TemplateCache", String.class, Template.class);
// if (cache == null) {
// this.cache = cacheManager.createCache("TemplateCache", config);
// } else {
// this.cache = cache;
// }
// } else {
// this.cache = null; // to keep compatibility with 0.1.0, but ugly
// }
// }
//
// @Override
// public Template getTemplate(String source) {
// if (this.cache == null) {
// return null;
// }
// return this.cache.get(source);
// }
//
// @Override
// public void putTemplate(String source, Template template) {
// if (this.cache == null) {
// return;
// }
// this.cache.put(source, template);
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/cache/TemplateCache.java
// public interface TemplateCache {
// Template getTemplate(String source);
//
// void putTemplate(String source, Template template);
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/ResourceTemplateLoader.java
// public class ResourceTemplateLoader extends TemplateLoader {
// private String prefix;
// private String suffix;
//
// @Override
// public InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// if (cl == null) {
// cl = getClass().getClassLoader();
// }
//
// if (prefix != null) {
// templateSource = prefix + templateSource;
// }
// if (suffix != null) {
// templateSource = templateSource + suffix;
// }
//
// if (templateSource.startsWith("/")) {
// templateSource = templateSource.replaceAll("^/(.*)", "$1");
// }
// InputStream is = cl.getResourceAsStream(templateSource);
// if (is == null) {
// throw new TemplateNotFoundException("Can't find template " + templateSource);
// }
//
// return is;
// }
//
// public void setPrefix(String prefix) {
// this.prefix = prefix;
// }
//
// public void setSuffix(String suffix) {
// this.suffix = suffix;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateLoader.java
// public abstract class TemplateLoader {
// public abstract InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException;
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateNotFoundException.java
// public class TemplateNotFoundException extends RuntimeException {
// public TemplateNotFoundException(String msg) {
// super(msg);
// }
//
// public TemplateNotFoundException(String msg, Exception cause) {
// super(msg, cause);
// }
// }
| import net.unit8.moshas.cache.JCacheTemplateCache;
import net.unit8.moshas.cache.TemplateCache;
import net.unit8.moshas.loader.ResourceTemplateLoader;
import net.unit8.moshas.loader.TemplateLoader;
import net.unit8.moshas.loader.TemplateNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; | package net.unit8.moshas;
/**
*
* @author kawasima
*/
public class StandardTemplateManager implements TemplateManager {
private List<TemplateLoader> templateLoaders;
private final TemplateCache cache;
public StandardTemplateManager(TemplateCache templateCache) {
templateLoaders = new ArrayList<>(); | // Path: moshas/src/main/java/net/unit8/moshas/cache/JCacheTemplateCache.java
// public class JCacheTemplateCache implements TemplateCache {
// private final Cache<String, Template> cache;
//
// public JCacheTemplateCache() {
// Iterator<CachingProvider> cachingProviders = Caching.getCachingProviders().iterator();
// if (cachingProviders.hasNext()) {
// CachingProvider cachingProvider = cachingProviders.next();
// CacheManager cacheManager = cachingProvider.getCacheManager();
// Configuration<String, Template> config = new MutableConfiguration<String, Template>()
// .setTypes(String.class, Template.class)
// .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));
// Cache<String, Template> cache = cacheManager.getCache("TemplateCache", String.class, Template.class);
// if (cache == null) {
// this.cache = cacheManager.createCache("TemplateCache", config);
// } else {
// this.cache = cache;
// }
// } else {
// this.cache = null; // to keep compatibility with 0.1.0, but ugly
// }
// }
//
// @Override
// public Template getTemplate(String source) {
// if (this.cache == null) {
// return null;
// }
// return this.cache.get(source);
// }
//
// @Override
// public void putTemplate(String source, Template template) {
// if (this.cache == null) {
// return;
// }
// this.cache.put(source, template);
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/cache/TemplateCache.java
// public interface TemplateCache {
// Template getTemplate(String source);
//
// void putTemplate(String source, Template template);
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/ResourceTemplateLoader.java
// public class ResourceTemplateLoader extends TemplateLoader {
// private String prefix;
// private String suffix;
//
// @Override
// public InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// if (cl == null) {
// cl = getClass().getClassLoader();
// }
//
// if (prefix != null) {
// templateSource = prefix + templateSource;
// }
// if (suffix != null) {
// templateSource = templateSource + suffix;
// }
//
// if (templateSource.startsWith("/")) {
// templateSource = templateSource.replaceAll("^/(.*)", "$1");
// }
// InputStream is = cl.getResourceAsStream(templateSource);
// if (is == null) {
// throw new TemplateNotFoundException("Can't find template " + templateSource);
// }
//
// return is;
// }
//
// public void setPrefix(String prefix) {
// this.prefix = prefix;
// }
//
// public void setSuffix(String suffix) {
// this.suffix = suffix;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateLoader.java
// public abstract class TemplateLoader {
// public abstract InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException;
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateNotFoundException.java
// public class TemplateNotFoundException extends RuntimeException {
// public TemplateNotFoundException(String msg) {
// super(msg);
// }
//
// public TemplateNotFoundException(String msg, Exception cause) {
// super(msg, cause);
// }
// }
// Path: moshas/src/main/java/net/unit8/moshas/StandardTemplateManager.java
import net.unit8.moshas.cache.JCacheTemplateCache;
import net.unit8.moshas.cache.TemplateCache;
import net.unit8.moshas.loader.ResourceTemplateLoader;
import net.unit8.moshas.loader.TemplateLoader;
import net.unit8.moshas.loader.TemplateNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
package net.unit8.moshas;
/**
*
* @author kawasima
*/
public class StandardTemplateManager implements TemplateManager {
private List<TemplateLoader> templateLoaders;
private final TemplateCache cache;
public StandardTemplateManager(TemplateCache templateCache) {
templateLoaders = new ArrayList<>(); | templateLoaders.add(new ResourceTemplateLoader()); |
kawasima/moshas | moshas/src/main/java/net/unit8/moshas/StandardTemplateManager.java | // Path: moshas/src/main/java/net/unit8/moshas/cache/JCacheTemplateCache.java
// public class JCacheTemplateCache implements TemplateCache {
// private final Cache<String, Template> cache;
//
// public JCacheTemplateCache() {
// Iterator<CachingProvider> cachingProviders = Caching.getCachingProviders().iterator();
// if (cachingProviders.hasNext()) {
// CachingProvider cachingProvider = cachingProviders.next();
// CacheManager cacheManager = cachingProvider.getCacheManager();
// Configuration<String, Template> config = new MutableConfiguration<String, Template>()
// .setTypes(String.class, Template.class)
// .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));
// Cache<String, Template> cache = cacheManager.getCache("TemplateCache", String.class, Template.class);
// if (cache == null) {
// this.cache = cacheManager.createCache("TemplateCache", config);
// } else {
// this.cache = cache;
// }
// } else {
// this.cache = null; // to keep compatibility with 0.1.0, but ugly
// }
// }
//
// @Override
// public Template getTemplate(String source) {
// if (this.cache == null) {
// return null;
// }
// return this.cache.get(source);
// }
//
// @Override
// public void putTemplate(String source, Template template) {
// if (this.cache == null) {
// return;
// }
// this.cache.put(source, template);
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/cache/TemplateCache.java
// public interface TemplateCache {
// Template getTemplate(String source);
//
// void putTemplate(String source, Template template);
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/ResourceTemplateLoader.java
// public class ResourceTemplateLoader extends TemplateLoader {
// private String prefix;
// private String suffix;
//
// @Override
// public InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// if (cl == null) {
// cl = getClass().getClassLoader();
// }
//
// if (prefix != null) {
// templateSource = prefix + templateSource;
// }
// if (suffix != null) {
// templateSource = templateSource + suffix;
// }
//
// if (templateSource.startsWith("/")) {
// templateSource = templateSource.replaceAll("^/(.*)", "$1");
// }
// InputStream is = cl.getResourceAsStream(templateSource);
// if (is == null) {
// throw new TemplateNotFoundException("Can't find template " + templateSource);
// }
//
// return is;
// }
//
// public void setPrefix(String prefix) {
// this.prefix = prefix;
// }
//
// public void setSuffix(String suffix) {
// this.suffix = suffix;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateLoader.java
// public abstract class TemplateLoader {
// public abstract InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException;
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateNotFoundException.java
// public class TemplateNotFoundException extends RuntimeException {
// public TemplateNotFoundException(String msg) {
// super(msg);
// }
//
// public TemplateNotFoundException(String msg, Exception cause) {
// super(msg, cause);
// }
// }
| import net.unit8.moshas.cache.JCacheTemplateCache;
import net.unit8.moshas.cache.TemplateCache;
import net.unit8.moshas.loader.ResourceTemplateLoader;
import net.unit8.moshas.loader.TemplateLoader;
import net.unit8.moshas.loader.TemplateNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; | package net.unit8.moshas;
/**
*
* @author kawasima
*/
public class StandardTemplateManager implements TemplateManager {
private List<TemplateLoader> templateLoaders;
private final TemplateCache cache;
public StandardTemplateManager(TemplateCache templateCache) {
templateLoaders = new ArrayList<>();
templateLoaders.add(new ResourceTemplateLoader());
cache = templateCache;
}
public StandardTemplateManager() { | // Path: moshas/src/main/java/net/unit8/moshas/cache/JCacheTemplateCache.java
// public class JCacheTemplateCache implements TemplateCache {
// private final Cache<String, Template> cache;
//
// public JCacheTemplateCache() {
// Iterator<CachingProvider> cachingProviders = Caching.getCachingProviders().iterator();
// if (cachingProviders.hasNext()) {
// CachingProvider cachingProvider = cachingProviders.next();
// CacheManager cacheManager = cachingProvider.getCacheManager();
// Configuration<String, Template> config = new MutableConfiguration<String, Template>()
// .setTypes(String.class, Template.class)
// .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));
// Cache<String, Template> cache = cacheManager.getCache("TemplateCache", String.class, Template.class);
// if (cache == null) {
// this.cache = cacheManager.createCache("TemplateCache", config);
// } else {
// this.cache = cache;
// }
// } else {
// this.cache = null; // to keep compatibility with 0.1.0, but ugly
// }
// }
//
// @Override
// public Template getTemplate(String source) {
// if (this.cache == null) {
// return null;
// }
// return this.cache.get(source);
// }
//
// @Override
// public void putTemplate(String source, Template template) {
// if (this.cache == null) {
// return;
// }
// this.cache.put(source, template);
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/cache/TemplateCache.java
// public interface TemplateCache {
// Template getTemplate(String source);
//
// void putTemplate(String source, Template template);
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/ResourceTemplateLoader.java
// public class ResourceTemplateLoader extends TemplateLoader {
// private String prefix;
// private String suffix;
//
// @Override
// public InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// if (cl == null) {
// cl = getClass().getClassLoader();
// }
//
// if (prefix != null) {
// templateSource = prefix + templateSource;
// }
// if (suffix != null) {
// templateSource = templateSource + suffix;
// }
//
// if (templateSource.startsWith("/")) {
// templateSource = templateSource.replaceAll("^/(.*)", "$1");
// }
// InputStream is = cl.getResourceAsStream(templateSource);
// if (is == null) {
// throw new TemplateNotFoundException("Can't find template " + templateSource);
// }
//
// return is;
// }
//
// public void setPrefix(String prefix) {
// this.prefix = prefix;
// }
//
// public void setSuffix(String suffix) {
// this.suffix = suffix;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateLoader.java
// public abstract class TemplateLoader {
// public abstract InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException;
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateNotFoundException.java
// public class TemplateNotFoundException extends RuntimeException {
// public TemplateNotFoundException(String msg) {
// super(msg);
// }
//
// public TemplateNotFoundException(String msg, Exception cause) {
// super(msg, cause);
// }
// }
// Path: moshas/src/main/java/net/unit8/moshas/StandardTemplateManager.java
import net.unit8.moshas.cache.JCacheTemplateCache;
import net.unit8.moshas.cache.TemplateCache;
import net.unit8.moshas.loader.ResourceTemplateLoader;
import net.unit8.moshas.loader.TemplateLoader;
import net.unit8.moshas.loader.TemplateNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
package net.unit8.moshas;
/**
*
* @author kawasima
*/
public class StandardTemplateManager implements TemplateManager {
private List<TemplateLoader> templateLoaders;
private final TemplateCache cache;
public StandardTemplateManager(TemplateCache templateCache) {
templateLoaders = new ArrayList<>();
templateLoaders.add(new ResourceTemplateLoader());
cache = templateCache;
}
public StandardTemplateManager() { | this(new JCacheTemplateCache()); |
kawasima/moshas | moshas/src/main/java/net/unit8/moshas/StandardTemplateManager.java | // Path: moshas/src/main/java/net/unit8/moshas/cache/JCacheTemplateCache.java
// public class JCacheTemplateCache implements TemplateCache {
// private final Cache<String, Template> cache;
//
// public JCacheTemplateCache() {
// Iterator<CachingProvider> cachingProviders = Caching.getCachingProviders().iterator();
// if (cachingProviders.hasNext()) {
// CachingProvider cachingProvider = cachingProviders.next();
// CacheManager cacheManager = cachingProvider.getCacheManager();
// Configuration<String, Template> config = new MutableConfiguration<String, Template>()
// .setTypes(String.class, Template.class)
// .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));
// Cache<String, Template> cache = cacheManager.getCache("TemplateCache", String.class, Template.class);
// if (cache == null) {
// this.cache = cacheManager.createCache("TemplateCache", config);
// } else {
// this.cache = cache;
// }
// } else {
// this.cache = null; // to keep compatibility with 0.1.0, but ugly
// }
// }
//
// @Override
// public Template getTemplate(String source) {
// if (this.cache == null) {
// return null;
// }
// return this.cache.get(source);
// }
//
// @Override
// public void putTemplate(String source, Template template) {
// if (this.cache == null) {
// return;
// }
// this.cache.put(source, template);
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/cache/TemplateCache.java
// public interface TemplateCache {
// Template getTemplate(String source);
//
// void putTemplate(String source, Template template);
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/ResourceTemplateLoader.java
// public class ResourceTemplateLoader extends TemplateLoader {
// private String prefix;
// private String suffix;
//
// @Override
// public InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// if (cl == null) {
// cl = getClass().getClassLoader();
// }
//
// if (prefix != null) {
// templateSource = prefix + templateSource;
// }
// if (suffix != null) {
// templateSource = templateSource + suffix;
// }
//
// if (templateSource.startsWith("/")) {
// templateSource = templateSource.replaceAll("^/(.*)", "$1");
// }
// InputStream is = cl.getResourceAsStream(templateSource);
// if (is == null) {
// throw new TemplateNotFoundException("Can't find template " + templateSource);
// }
//
// return is;
// }
//
// public void setPrefix(String prefix) {
// this.prefix = prefix;
// }
//
// public void setSuffix(String suffix) {
// this.suffix = suffix;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateLoader.java
// public abstract class TemplateLoader {
// public abstract InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException;
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateNotFoundException.java
// public class TemplateNotFoundException extends RuntimeException {
// public TemplateNotFoundException(String msg) {
// super(msg);
// }
//
// public TemplateNotFoundException(String msg, Exception cause) {
// super(msg, cause);
// }
// }
| import net.unit8.moshas.cache.JCacheTemplateCache;
import net.unit8.moshas.cache.TemplateCache;
import net.unit8.moshas.loader.ResourceTemplateLoader;
import net.unit8.moshas.loader.TemplateLoader;
import net.unit8.moshas.loader.TemplateNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; | package net.unit8.moshas;
/**
*
* @author kawasima
*/
public class StandardTemplateManager implements TemplateManager {
private List<TemplateLoader> templateLoaders;
private final TemplateCache cache;
public StandardTemplateManager(TemplateCache templateCache) {
templateLoaders = new ArrayList<>();
templateLoaders.add(new ResourceTemplateLoader());
cache = templateCache;
}
public StandardTemplateManager() {
this(new JCacheTemplateCache());
}
@Override
public Template loadTemplate(String templateName) {
try (InputStream is = findTemplate(templateName)) {
Template newTemplate = new DefaultTemplate(is);
return newTemplate;
} catch (IOException e) { | // Path: moshas/src/main/java/net/unit8/moshas/cache/JCacheTemplateCache.java
// public class JCacheTemplateCache implements TemplateCache {
// private final Cache<String, Template> cache;
//
// public JCacheTemplateCache() {
// Iterator<CachingProvider> cachingProviders = Caching.getCachingProviders().iterator();
// if (cachingProviders.hasNext()) {
// CachingProvider cachingProvider = cachingProviders.next();
// CacheManager cacheManager = cachingProvider.getCacheManager();
// Configuration<String, Template> config = new MutableConfiguration<String, Template>()
// .setTypes(String.class, Template.class)
// .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));
// Cache<String, Template> cache = cacheManager.getCache("TemplateCache", String.class, Template.class);
// if (cache == null) {
// this.cache = cacheManager.createCache("TemplateCache", config);
// } else {
// this.cache = cache;
// }
// } else {
// this.cache = null; // to keep compatibility with 0.1.0, but ugly
// }
// }
//
// @Override
// public Template getTemplate(String source) {
// if (this.cache == null) {
// return null;
// }
// return this.cache.get(source);
// }
//
// @Override
// public void putTemplate(String source, Template template) {
// if (this.cache == null) {
// return;
// }
// this.cache.put(source, template);
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/cache/TemplateCache.java
// public interface TemplateCache {
// Template getTemplate(String source);
//
// void putTemplate(String source, Template template);
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/ResourceTemplateLoader.java
// public class ResourceTemplateLoader extends TemplateLoader {
// private String prefix;
// private String suffix;
//
// @Override
// public InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// if (cl == null) {
// cl = getClass().getClassLoader();
// }
//
// if (prefix != null) {
// templateSource = prefix + templateSource;
// }
// if (suffix != null) {
// templateSource = templateSource + suffix;
// }
//
// if (templateSource.startsWith("/")) {
// templateSource = templateSource.replaceAll("^/(.*)", "$1");
// }
// InputStream is = cl.getResourceAsStream(templateSource);
// if (is == null) {
// throw new TemplateNotFoundException("Can't find template " + templateSource);
// }
//
// return is;
// }
//
// public void setPrefix(String prefix) {
// this.prefix = prefix;
// }
//
// public void setSuffix(String suffix) {
// this.suffix = suffix;
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateLoader.java
// public abstract class TemplateLoader {
// public abstract InputStream getTemplateStream(String templateSource) throws TemplateNotFoundException;
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/loader/TemplateNotFoundException.java
// public class TemplateNotFoundException extends RuntimeException {
// public TemplateNotFoundException(String msg) {
// super(msg);
// }
//
// public TemplateNotFoundException(String msg, Exception cause) {
// super(msg, cause);
// }
// }
// Path: moshas/src/main/java/net/unit8/moshas/StandardTemplateManager.java
import net.unit8.moshas.cache.JCacheTemplateCache;
import net.unit8.moshas.cache.TemplateCache;
import net.unit8.moshas.loader.ResourceTemplateLoader;
import net.unit8.moshas.loader.TemplateLoader;
import net.unit8.moshas.loader.TemplateNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
package net.unit8.moshas;
/**
*
* @author kawasima
*/
public class StandardTemplateManager implements TemplateManager {
private List<TemplateLoader> templateLoaders;
private final TemplateCache cache;
public StandardTemplateManager(TemplateCache templateCache) {
templateLoaders = new ArrayList<>();
templateLoaders.add(new ResourceTemplateLoader());
cache = templateCache;
}
public StandardTemplateManager() {
this(new JCacheTemplateCache());
}
@Override
public Template loadTemplate(String templateName) {
try (InputStream is = findTemplate(templateName)) {
Template newTemplate = new DefaultTemplate(is);
return newTemplate;
} catch (IOException e) { | throw new TemplateNotFoundException(templateName, e); |
kawasima/moshas | moshas/src/test/java/net/unit8/moshas/TemplateTest.java | // Path: moshas/src/main/java/net/unit8/moshas/context/Context.java
// public class Context extends AbstractContext {
//
// public Context() {
// super();
// }
//
// public Context(Map<String, Object> variables) {
// super();
// for (Map.Entry<String, Object> entry : variables.entrySet()) {
// setVariable(entry.getKey(), entry.getValue());
// }
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/RenderUtils.java
// public class RenderUtils {
// public static RenderFunction text(String... keys) {
// return (el, ctx) -> el.text(ctx.getString(keys));
// }
//
// public static RenderFunction attr(String attrName, String... keys) {
// return (el, ctx) -> el.attr(attrName, ctx.getString(keys));
// }
//
// public static RenderFunction doAll(RenderFunction... funcs) {
// return (el, ctx) -> {
// for (RenderFunction func : funcs) {
// func.render(el, ctx);
// }
// };
// }
// }
| import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import net.unit8.moshas.context.Context;
import org.junit.Test;
import java.io.StringWriter;
import static net.unit8.moshas.RenderUtils.*; | package net.unit8.moshas;
/**
*
* @author kawasima
*/
public class TemplateTest {
@Test
public void test() {
MoshasEngine engine = new MoshasEngine();
Template index = engine.describe("META-INF/templates/index.html", t -> t.select("p#message", text("message"))); | // Path: moshas/src/main/java/net/unit8/moshas/context/Context.java
// public class Context extends AbstractContext {
//
// public Context() {
// super();
// }
//
// public Context(Map<String, Object> variables) {
// super();
// for (Map.Entry<String, Object> entry : variables.entrySet()) {
// setVariable(entry.getKey(), entry.getValue());
// }
// }
// }
//
// Path: moshas/src/main/java/net/unit8/moshas/RenderUtils.java
// public class RenderUtils {
// public static RenderFunction text(String... keys) {
// return (el, ctx) -> el.text(ctx.getString(keys));
// }
//
// public static RenderFunction attr(String attrName, String... keys) {
// return (el, ctx) -> el.attr(attrName, ctx.getString(keys));
// }
//
// public static RenderFunction doAll(RenderFunction... funcs) {
// return (el, ctx) -> {
// for (RenderFunction func : funcs) {
// func.render(el, ctx);
// }
// };
// }
// }
// Path: moshas/src/test/java/net/unit8/moshas/TemplateTest.java
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import net.unit8.moshas.context.Context;
import org.junit.Test;
import java.io.StringWriter;
import static net.unit8.moshas.RenderUtils.*;
package net.unit8.moshas;
/**
*
* @author kawasima
*/
public class TemplateTest {
@Test
public void test() {
MoshasEngine engine = new MoshasEngine();
Template index = engine.describe("META-INF/templates/index.html", t -> t.select("p#message", text("message"))); | Context context = new Context(); |
kawasima/moshas | moshas/src/test/java/net/unit8/moshas/AttributesTest.java | // Path: moshas/src/main/java/net/unit8/moshas/context/Context.java
// public class Context extends AbstractContext {
//
// public Context() {
// super();
// }
//
// public Context(Map<String, Object> variables) {
// super();
// for (Map.Entry<String, Object> entry : variables.entrySet()) {
// setVariable(entry.getKey(), entry.getValue());
// }
// }
// }
| import net.unit8.moshas.context.Context;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; | package net.unit8.moshas;
/**
* @author kawasima
*/
public class AttributesTest {
MoshasEngine moshas = new MoshasEngine();
@Test
public void removeAttribute() {
moshas.describe("META-INF/templates/attributes.html", t -> {
t.select("#container", (el, ctx) -> {
el.removeAttr("id");
el.attr("class", "container");
});
t.select(".column", (el, ctx) -> el.addClass("red"));
});
| // Path: moshas/src/main/java/net/unit8/moshas/context/Context.java
// public class Context extends AbstractContext {
//
// public Context() {
// super();
// }
//
// public Context(Map<String, Object> variables) {
// super();
// for (Map.Entry<String, Object> entry : variables.entrySet()) {
// setVariable(entry.getKey(), entry.getValue());
// }
// }
// }
// Path: moshas/src/test/java/net/unit8/moshas/AttributesTest.java
import net.unit8.moshas.context.Context;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
package net.unit8.moshas;
/**
* @author kawasima
*/
public class AttributesTest {
MoshasEngine moshas = new MoshasEngine();
@Test
public void removeAttribute() {
moshas.describe("META-INF/templates/attributes.html", t -> {
t.select("#container", (el, ctx) -> {
el.removeAttr("id");
el.attr("class", "container");
});
t.select(".column", (el, ctx) -> el.addClass("red"));
});
| Context ctx = new Context(); |
kawasima/moshas | moshas/src/main/java/net/unit8/moshas/parser/XmlTreeBuilder.java | // Path: moshas/src/main/java/net/unit8/moshas/helper/Validate.java
// public class Validate {
//
// private Validate() {}
//
// /**
// * Validates that the object is not null
// * @param obj object to test
// */
// public static void notNull(Object obj) {
// if (obj == null)
// throw new IllegalArgumentException("Object must not be null");
// }
//
// /**
// * Validates that the object is not null
// * @param obj object to test
// * @param msg message to output if validation fails
// */
// public static void notNull(Object obj, String msg) {
// if (obj == null)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the value is true
// * @param val object to test
// */
// public static void isTrue(boolean val) {
// if (!val)
// throw new IllegalArgumentException("Must be true");
// }
//
// /**
// * Validates that the value is true
// * @param val object to test
// * @param msg message to output if validation fails
// */
// public static void isTrue(boolean val, String msg) {
// if (!val)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the value is false
// * @param val object to test
// */
// public static void isFalse(boolean val) {
// if (val)
// throw new IllegalArgumentException("Must be false");
// }
//
// /**
// * Validates that the value is false
// * @param val object to test
// * @param msg message to output if validation fails
// */
// public static void isFalse(boolean val, String msg) {
// if (val)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the array contains no null elements
// * @param objects the array to test
// */
// public static void noNullElements(Object[] objects) {
// noNullElements(objects, "Array must not contain any null objects");
// }
//
// /**
// * Validates that the array contains no null elements
// * @param objects the array to test
// * @param msg message to output if validation fails
// */
// public static void noNullElements(Object[] objects, String msg) {
// for (Object obj : objects)
// if (obj == null)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the string is not empty
// * @param string the string to test
// */
// public static void notEmpty(String string) {
// if (string == null || string.length() == 0)
// throw new IllegalArgumentException("String must not be empty");
// }
//
// /**
// * Validates that the string is not empty
// * @param string the string to test
// * @param msg message to output if validation fails
// */
// public static void notEmpty(String string, String msg) {
// if (string == null || string.length() == 0)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// Cause a failure.
// @param msg message to output.
// */
// public static void fail(String msg) {
// throw new IllegalArgumentException(msg);
// }
// }
| import net.unit8.moshas.dom.*;
import net.unit8.moshas.helper.Validate;
import java.util.List; | package net.unit8.moshas.parser;
/**
*
* @author kawasima
*/
public class XmlTreeBuilder extends TreeBuilder {
@Override
protected void initialiseParse(String input, String baseUri, ParseErrorList errors) {
super.initialiseParse(input, baseUri, errors);
stack.add(doc); // place the document onto the stack. differs from HtmlTreeBuilder (not on stack)
doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
}
@Override
protected boolean process(Token token) {
// start tag, end tag, doctype, comment, character, eof
switch (token.type) {
case StartTag:
insert(token.asStartTag());
break;
case EndTag:
popStackToClose(token.asEndTag());
break;
case Comment:
insert(token.asComment());
break;
case Character:
insert(token.asCharacter());
break;
case Doctype:
insert(token.asDoctype());
break;
case EOF: // could put some normalisation here if desired
break;
default: | // Path: moshas/src/main/java/net/unit8/moshas/helper/Validate.java
// public class Validate {
//
// private Validate() {}
//
// /**
// * Validates that the object is not null
// * @param obj object to test
// */
// public static void notNull(Object obj) {
// if (obj == null)
// throw new IllegalArgumentException("Object must not be null");
// }
//
// /**
// * Validates that the object is not null
// * @param obj object to test
// * @param msg message to output if validation fails
// */
// public static void notNull(Object obj, String msg) {
// if (obj == null)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the value is true
// * @param val object to test
// */
// public static void isTrue(boolean val) {
// if (!val)
// throw new IllegalArgumentException("Must be true");
// }
//
// /**
// * Validates that the value is true
// * @param val object to test
// * @param msg message to output if validation fails
// */
// public static void isTrue(boolean val, String msg) {
// if (!val)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the value is false
// * @param val object to test
// */
// public static void isFalse(boolean val) {
// if (val)
// throw new IllegalArgumentException("Must be false");
// }
//
// /**
// * Validates that the value is false
// * @param val object to test
// * @param msg message to output if validation fails
// */
// public static void isFalse(boolean val, String msg) {
// if (val)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the array contains no null elements
// * @param objects the array to test
// */
// public static void noNullElements(Object[] objects) {
// noNullElements(objects, "Array must not contain any null objects");
// }
//
// /**
// * Validates that the array contains no null elements
// * @param objects the array to test
// * @param msg message to output if validation fails
// */
// public static void noNullElements(Object[] objects, String msg) {
// for (Object obj : objects)
// if (obj == null)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the string is not empty
// * @param string the string to test
// */
// public static void notEmpty(String string) {
// if (string == null || string.length() == 0)
// throw new IllegalArgumentException("String must not be empty");
// }
//
// /**
// * Validates that the string is not empty
// * @param string the string to test
// * @param msg message to output if validation fails
// */
// public static void notEmpty(String string, String msg) {
// if (string == null || string.length() == 0)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// Cause a failure.
// @param msg message to output.
// */
// public static void fail(String msg) {
// throw new IllegalArgumentException(msg);
// }
// }
// Path: moshas/src/main/java/net/unit8/moshas/parser/XmlTreeBuilder.java
import net.unit8.moshas.dom.*;
import net.unit8.moshas.helper.Validate;
import java.util.List;
package net.unit8.moshas.parser;
/**
*
* @author kawasima
*/
public class XmlTreeBuilder extends TreeBuilder {
@Override
protected void initialiseParse(String input, String baseUri, ParseErrorList errors) {
super.initialiseParse(input, baseUri, errors);
stack.add(doc); // place the document onto the stack. differs from HtmlTreeBuilder (not on stack)
doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
}
@Override
protected boolean process(Token token) {
// start tag, end tag, doctype, comment, character, eof
switch (token.type) {
case StartTag:
insert(token.asStartTag());
break;
case EndTag:
popStackToClose(token.asEndTag());
break;
case Comment:
insert(token.asComment());
break;
case Character:
insert(token.asCharacter());
break;
case Doctype:
insert(token.asDoctype());
break;
case EOF: // could put some normalisation here if desired
break;
default: | Validate.fail("Unexpected token type: " + token.type); |
kawasima/moshas | moshas/src/main/java/net/unit8/moshas/select/Evaluator.java | // Path: moshas/src/main/java/net/unit8/moshas/helper/Validate.java
// public class Validate {
//
// private Validate() {}
//
// /**
// * Validates that the object is not null
// * @param obj object to test
// */
// public static void notNull(Object obj) {
// if (obj == null)
// throw new IllegalArgumentException("Object must not be null");
// }
//
// /**
// * Validates that the object is not null
// * @param obj object to test
// * @param msg message to output if validation fails
// */
// public static void notNull(Object obj, String msg) {
// if (obj == null)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the value is true
// * @param val object to test
// */
// public static void isTrue(boolean val) {
// if (!val)
// throw new IllegalArgumentException("Must be true");
// }
//
// /**
// * Validates that the value is true
// * @param val object to test
// * @param msg message to output if validation fails
// */
// public static void isTrue(boolean val, String msg) {
// if (!val)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the value is false
// * @param val object to test
// */
// public static void isFalse(boolean val) {
// if (val)
// throw new IllegalArgumentException("Must be false");
// }
//
// /**
// * Validates that the value is false
// * @param val object to test
// * @param msg message to output if validation fails
// */
// public static void isFalse(boolean val, String msg) {
// if (val)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the array contains no null elements
// * @param objects the array to test
// */
// public static void noNullElements(Object[] objects) {
// noNullElements(objects, "Array must not contain any null objects");
// }
//
// /**
// * Validates that the array contains no null elements
// * @param objects the array to test
// * @param msg message to output if validation fails
// */
// public static void noNullElements(Object[] objects, String msg) {
// for (Object obj : objects)
// if (obj == null)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the string is not empty
// * @param string the string to test
// */
// public static void notEmpty(String string) {
// if (string == null || string.length() == 0)
// throw new IllegalArgumentException("String must not be empty");
// }
//
// /**
// * Validates that the string is not empty
// * @param string the string to test
// * @param msg message to output if validation fails
// */
// public static void notEmpty(String string, String msg) {
// if (string == null || string.length() == 0)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// Cause a failure.
// @param msg message to output.
// */
// public static void fail(String msg) {
// throw new IllegalArgumentException(msg);
// }
// }
| import net.unit8.moshas.dom.*;
import net.unit8.moshas.helper.Validate;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern; | */
public static final class AttributeWithValueMatching extends Evaluator {
final String key;
final Pattern pattern;
public AttributeWithValueMatching(String key, Pattern pattern) {
this.key = key.trim().toLowerCase();
this.pattern = pattern;
}
@Override
public boolean matches(Element root, Element element) {
return element.hasAttr(key) && pattern.matcher(element.attr(key)).find();
}
@Override
public String toString() {
return String.format("[%s~=%s]", key, pattern.toString());
}
}
/**
* Abstract evaluator for attribute name/value matching
*/
public abstract static class AttributeKeyPair extends Evaluator {
final String key;
final String value;
public AttributeKeyPair(String key, String value) { | // Path: moshas/src/main/java/net/unit8/moshas/helper/Validate.java
// public class Validate {
//
// private Validate() {}
//
// /**
// * Validates that the object is not null
// * @param obj object to test
// */
// public static void notNull(Object obj) {
// if (obj == null)
// throw new IllegalArgumentException("Object must not be null");
// }
//
// /**
// * Validates that the object is not null
// * @param obj object to test
// * @param msg message to output if validation fails
// */
// public static void notNull(Object obj, String msg) {
// if (obj == null)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the value is true
// * @param val object to test
// */
// public static void isTrue(boolean val) {
// if (!val)
// throw new IllegalArgumentException("Must be true");
// }
//
// /**
// * Validates that the value is true
// * @param val object to test
// * @param msg message to output if validation fails
// */
// public static void isTrue(boolean val, String msg) {
// if (!val)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the value is false
// * @param val object to test
// */
// public static void isFalse(boolean val) {
// if (val)
// throw new IllegalArgumentException("Must be false");
// }
//
// /**
// * Validates that the value is false
// * @param val object to test
// * @param msg message to output if validation fails
// */
// public static void isFalse(boolean val, String msg) {
// if (val)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the array contains no null elements
// * @param objects the array to test
// */
// public static void noNullElements(Object[] objects) {
// noNullElements(objects, "Array must not contain any null objects");
// }
//
// /**
// * Validates that the array contains no null elements
// * @param objects the array to test
// * @param msg message to output if validation fails
// */
// public static void noNullElements(Object[] objects, String msg) {
// for (Object obj : objects)
// if (obj == null)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// * Validates that the string is not empty
// * @param string the string to test
// */
// public static void notEmpty(String string) {
// if (string == null || string.length() == 0)
// throw new IllegalArgumentException("String must not be empty");
// }
//
// /**
// * Validates that the string is not empty
// * @param string the string to test
// * @param msg message to output if validation fails
// */
// public static void notEmpty(String string, String msg) {
// if (string == null || string.length() == 0)
// throw new IllegalArgumentException(msg);
// }
//
// /**
// Cause a failure.
// @param msg message to output.
// */
// public static void fail(String msg) {
// throw new IllegalArgumentException(msg);
// }
// }
// Path: moshas/src/main/java/net/unit8/moshas/select/Evaluator.java
import net.unit8.moshas.dom.*;
import net.unit8.moshas.helper.Validate;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
*/
public static final class AttributeWithValueMatching extends Evaluator {
final String key;
final Pattern pattern;
public AttributeWithValueMatching(String key, Pattern pattern) {
this.key = key.trim().toLowerCase();
this.pattern = pattern;
}
@Override
public boolean matches(Element root, Element element) {
return element.hasAttr(key) && pattern.matcher(element.attr(key)).find();
}
@Override
public String toString() {
return String.format("[%s~=%s]", key, pattern.toString());
}
}
/**
* Abstract evaluator for attribute name/value matching
*/
public abstract static class AttributeKeyPair extends Evaluator {
final String key;
final String value;
public AttributeKeyPair(String key, String value) { | Validate.notEmpty(key); |
openxc/diagnostic-tool | src/com/openxc/openxcdiagnostic/dash/DashboardActivity.java | // Path: src/com/openxc/openxcdiagnostic/util/ActivityLauncher.java
// public class ActivityLauncher {
//
// public static Map<Integer, Class<?>> sActivityMap = new HashMap<>();
//
// static {
// sActivityMap.put(R.id.Diagnostic, DiagnosticActivity.class);
// sActivityMap.put(R.id.Menu, MenuActivity.class);
// sActivityMap.put(R.id.Dashboard, DashboardActivity.class);
// sActivityMap.put(R.id.Dump, DumpActivity.class);
// }
//
// public static void launchActivity(Activity activity, int itemId) {
//
// Class<?> newActivityClass = sActivityMap.get(Integer.valueOf(itemId));
// if (!activity.getClass().equals(newActivityClass)) {
// activity.startActivity(new Intent(activity, newActivityClass));
// }
// }
//
// }
| import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.openxc.VehicleManager;
import com.openxc.measurements.AcceleratorPedalPosition;
import com.openxc.measurements.BrakePedalStatus;
import com.openxc.measurements.EngineSpeed;
import com.openxc.measurements.FuelConsumed;
import com.openxc.measurements.FuelLevel;
import com.openxc.measurements.HeadlampStatus;
import com.openxc.measurements.IgnitionStatus;
import com.openxc.measurements.Latitude;
import com.openxc.measurements.Longitude;
import com.openxc.measurements.Measurement;
import com.openxc.measurements.Odometer;
import com.openxc.measurements.ParkingBrakeStatus;
import com.openxc.measurements.SteeringWheelAngle;
import com.openxc.measurements.TorqueAtTransmission;
import com.openxc.measurements.TransmissionGearPosition;
import com.openxc.measurements.UnrecognizedMeasurementTypeException;
import com.openxc.measurements.VehicleSpeed;
import com.openxc.measurements.WindshieldWiperStatus;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.util.ActivityLauncher;
import com.openxc.remote.VehicleServiceException; |
@Override
public void onResume() {
super.onResume();
bindService(new Intent(this, VehicleManager.class),
mConnection, Context.BIND_AUTO_CREATE);
try {
mLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0,
mAndroidLocationListener);
} catch(IllegalArgumentException e) {
Log.w(TAG, "Vehicle location provider is unavailable");
}
}
@Override
public void onPause() {
super.onPause();
if(mIsBound) {
Log.i(TAG, "Unbinding from vehicle service");
unbindService(mConnection);
mIsBound = false;
}
mLocationManager.removeUpdates(mAndroidLocationListener);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) { | // Path: src/com/openxc/openxcdiagnostic/util/ActivityLauncher.java
// public class ActivityLauncher {
//
// public static Map<Integer, Class<?>> sActivityMap = new HashMap<>();
//
// static {
// sActivityMap.put(R.id.Diagnostic, DiagnosticActivity.class);
// sActivityMap.put(R.id.Menu, MenuActivity.class);
// sActivityMap.put(R.id.Dashboard, DashboardActivity.class);
// sActivityMap.put(R.id.Dump, DumpActivity.class);
// }
//
// public static void launchActivity(Activity activity, int itemId) {
//
// Class<?> newActivityClass = sActivityMap.get(Integer.valueOf(itemId));
// if (!activity.getClass().equals(newActivityClass)) {
// activity.startActivity(new Intent(activity, newActivityClass));
// }
// }
//
// }
// Path: src/com/openxc/openxcdiagnostic/dash/DashboardActivity.java
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.openxc.VehicleManager;
import com.openxc.measurements.AcceleratorPedalPosition;
import com.openxc.measurements.BrakePedalStatus;
import com.openxc.measurements.EngineSpeed;
import com.openxc.measurements.FuelConsumed;
import com.openxc.measurements.FuelLevel;
import com.openxc.measurements.HeadlampStatus;
import com.openxc.measurements.IgnitionStatus;
import com.openxc.measurements.Latitude;
import com.openxc.measurements.Longitude;
import com.openxc.measurements.Measurement;
import com.openxc.measurements.Odometer;
import com.openxc.measurements.ParkingBrakeStatus;
import com.openxc.measurements.SteeringWheelAngle;
import com.openxc.measurements.TorqueAtTransmission;
import com.openxc.measurements.TransmissionGearPosition;
import com.openxc.measurements.UnrecognizedMeasurementTypeException;
import com.openxc.measurements.VehicleSpeed;
import com.openxc.measurements.WindshieldWiperStatus;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.util.ActivityLauncher;
import com.openxc.remote.VehicleServiceException;
@Override
public void onResume() {
super.onResume();
bindService(new Intent(this, VehicleManager.class),
mConnection, Context.BIND_AUTO_CREATE);
try {
mLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0,
mAndroidLocationListener);
} catch(IllegalArgumentException e) {
Log.w(TAG, "Vehicle location provider is unavailable");
}
}
@Override
public void onPause() {
super.onPause();
if(mIsBound) {
Log.i(TAG, "Unbinding from vehicle service");
unbindService(mConnection);
mIsBound = false;
}
mLocationManager.removeUpdates(mAndroidLocationListener);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) { | ActivityLauncher.launchActivity(this, item.getItemId()); |
openxc/diagnostic-tool | src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java | // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
| import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher; | package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Class for managing all of the static buttons for the diagnostic activity UI.
*
*/
public class ButtonManager implements DiagnosticManager {
private DiagnosticActivity mContext;
private boolean mDisplayCommands;
private Resources mResources;
public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
mContext = context;
mResources = mContext.getResources();
setRequestCommandState(displayCommands);
initButtons();
}
@Override
public void setRequestCommandState(boolean displayCommands) {
mDisplayCommands = displayCommands;
if (displayCommands) {
initCommandInfoButton();
} else {
initRequestInfoButtons();
}
setRequestButtonText();
}
private void initButtons() {
setRequestButtonText();
| // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
// Path: src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java
import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher;
package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Class for managing all of the static buttons for the diagnostic activity UI.
*
*/
public class ButtonManager implements DiagnosticManager {
private DiagnosticActivity mContext;
private boolean mDisplayCommands;
private Resources mResources;
public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
mContext = context;
mResources = mContext.getResources();
setRequestCommandState(displayCommands);
initButtons();
}
@Override
public void setRequestCommandState(boolean displayCommands) {
mDisplayCommands = displayCommands;
if (displayCommands) {
initCommandInfoButton();
} else {
initRequestInfoButtons();
}
setRequestButtonText();
}
private void initButtons() {
setRequestButtonText();
| Map<Integer, ButtonCommand> buttonActions = new HashMap<>(); |
openxc/diagnostic-tool | src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java | // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
| import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher; | package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Class for managing all of the static buttons for the diagnostic activity UI.
*
*/
public class ButtonManager implements DiagnosticManager {
private DiagnosticActivity mContext;
private boolean mDisplayCommands;
private Resources mResources;
public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
mContext = context;
mResources = mContext.getResources();
setRequestCommandState(displayCommands);
initButtons();
}
@Override
public void setRequestCommandState(boolean displayCommands) {
mDisplayCommands = displayCommands;
if (displayCommands) {
initCommandInfoButton();
} else {
initRequestInfoButtons();
}
setRequestButtonText();
}
private void initButtons() {
setRequestButtonText();
Map<Integer, ButtonCommand> buttonActions = new HashMap<>(); | // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
// Path: src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java
import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher;
package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Class for managing all of the static buttons for the diagnostic activity UI.
*
*/
public class ButtonManager implements DiagnosticManager {
private DiagnosticActivity mContext;
private boolean mDisplayCommands;
private Resources mResources;
public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
mContext = context;
mResources = mContext.getResources();
setRequestCommandState(displayCommands);
initButtons();
}
@Override
public void setRequestCommandState(boolean displayCommands) {
mDisplayCommands = displayCommands;
if (displayCommands) {
initCommandInfoButton();
} else {
initRequestInfoButtons();
}
setRequestButtonText();
}
private void initButtons() {
setRequestButtonText();
Map<Integer, ButtonCommand> buttonActions = new HashMap<>(); | buttonActions.put(R.id.sendRequestButton, new RequestSendCommand( |
openxc/diagnostic-tool | src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java | // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
| import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher; | package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Class for managing all of the static buttons for the diagnostic activity UI.
*
*/
public class ButtonManager implements DiagnosticManager {
private DiagnosticActivity mContext;
private boolean mDisplayCommands;
private Resources mResources;
public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
mContext = context;
mResources = mContext.getResources();
setRequestCommandState(displayCommands);
initButtons();
}
@Override
public void setRequestCommandState(boolean displayCommands) {
mDisplayCommands = displayCommands;
if (displayCommands) {
initCommandInfoButton();
} else {
initRequestInfoButtons();
}
setRequestButtonText();
}
private void initButtons() {
setRequestButtonText();
Map<Integer, ButtonCommand> buttonActions = new HashMap<>();
buttonActions.put(R.id.sendRequestButton, new RequestSendCommand(
mContext)); | // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
// Path: src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java
import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher;
package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Class for managing all of the static buttons for the diagnostic activity UI.
*
*/
public class ButtonManager implements DiagnosticManager {
private DiagnosticActivity mContext;
private boolean mDisplayCommands;
private Resources mResources;
public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
mContext = context;
mResources = mContext.getResources();
setRequestCommandState(displayCommands);
initButtons();
}
@Override
public void setRequestCommandState(boolean displayCommands) {
mDisplayCommands = displayCommands;
if (displayCommands) {
initCommandInfoButton();
} else {
initRequestInfoButtons();
}
setRequestButtonText();
}
private void initButtons() {
setRequestButtonText();
Map<Integer, ButtonCommand> buttonActions = new HashMap<>();
buttonActions.put(R.id.sendRequestButton, new RequestSendCommand(
mContext)); | buttonActions.put(R.id.clearButton, new ClearInputFieldsCommand( |
openxc/diagnostic-tool | src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java | // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
| import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher; | package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Class for managing all of the static buttons for the diagnostic activity UI.
*
*/
public class ButtonManager implements DiagnosticManager {
private DiagnosticActivity mContext;
private boolean mDisplayCommands;
private Resources mResources;
public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
mContext = context;
mResources = mContext.getResources();
setRequestCommandState(displayCommands);
initButtons();
}
@Override
public void setRequestCommandState(boolean displayCommands) {
mDisplayCommands = displayCommands;
if (displayCommands) {
initCommandInfoButton();
} else {
initRequestInfoButtons();
}
setRequestButtonText();
}
private void initButtons() {
setRequestButtonText();
Map<Integer, ButtonCommand> buttonActions = new HashMap<>();
buttonActions.put(R.id.sendRequestButton, new RequestSendCommand(
mContext));
buttonActions.put(R.id.clearButton, new ClearInputFieldsCommand(
mContext));
buttonActions.put(R.id.favoritesButton, | // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
// Path: src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java
import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher;
package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Class for managing all of the static buttons for the diagnostic activity UI.
*
*/
public class ButtonManager implements DiagnosticManager {
private DiagnosticActivity mContext;
private boolean mDisplayCommands;
private Resources mResources;
public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
mContext = context;
mResources = mContext.getResources();
setRequestCommandState(displayCommands);
initButtons();
}
@Override
public void setRequestCommandState(boolean displayCommands) {
mDisplayCommands = displayCommands;
if (displayCommands) {
initCommandInfoButton();
} else {
initRequestInfoButtons();
}
setRequestButtonText();
}
private void initButtons() {
setRequestButtonText();
Map<Integer, ButtonCommand> buttonActions = new HashMap<>();
buttonActions.put(R.id.sendRequestButton, new RequestSendCommand(
mContext));
buttonActions.put(R.id.clearButton, new ClearInputFieldsCommand(
mContext));
buttonActions.put(R.id.favoritesButton, | new LaunchFavoritesDialogCommand(mContext)); |
openxc/diagnostic-tool | src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java | // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
| import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher; | package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Class for managing all of the static buttons for the diagnostic activity UI.
*
*/
public class ButtonManager implements DiagnosticManager {
private DiagnosticActivity mContext;
private boolean mDisplayCommands;
private Resources mResources;
public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
mContext = context;
mResources = mContext.getResources();
setRequestCommandState(displayCommands);
initButtons();
}
@Override
public void setRequestCommandState(boolean displayCommands) {
mDisplayCommands = displayCommands;
if (displayCommands) {
initCommandInfoButton();
} else {
initRequestInfoButtons();
}
setRequestButtonText();
}
private void initButtons() {
setRequestButtonText();
Map<Integer, ButtonCommand> buttonActions = new HashMap<>();
buttonActions.put(R.id.sendRequestButton, new RequestSendCommand(
mContext));
buttonActions.put(R.id.clearButton, new ClearInputFieldsCommand(
mContext));
buttonActions.put(R.id.favoritesButton,
new LaunchFavoritesDialogCommand(mContext)); | // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
// Path: src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java
import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher;
package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Class for managing all of the static buttons for the diagnostic activity UI.
*
*/
public class ButtonManager implements DiagnosticManager {
private DiagnosticActivity mContext;
private boolean mDisplayCommands;
private Resources mResources;
public ButtonManager(DiagnosticActivity context, boolean displayCommands) {
mContext = context;
mResources = mContext.getResources();
setRequestCommandState(displayCommands);
initButtons();
}
@Override
public void setRequestCommandState(boolean displayCommands) {
mDisplayCommands = displayCommands;
if (displayCommands) {
initCommandInfoButton();
} else {
initRequestInfoButtons();
}
setRequestButtonText();
}
private void initButtons() {
setRequestButtonText();
Map<Integer, ButtonCommand> buttonActions = new HashMap<>();
buttonActions.put(R.id.sendRequestButton, new RequestSendCommand(
mContext));
buttonActions.put(R.id.clearButton, new ClearInputFieldsCommand(
mContext));
buttonActions.put(R.id.favoritesButton,
new LaunchFavoritesDialogCommand(mContext)); | buttonActions.put(R.id.settingsButton, new LaunchSettingsDialogCommand( |
openxc/diagnostic-tool | src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java | // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
| import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher; | setRequestButtonText();
Map<Integer, ButtonCommand> buttonActions = new HashMap<>();
buttonActions.put(R.id.sendRequestButton, new RequestSendCommand(
mContext));
buttonActions.put(R.id.clearButton, new ClearInputFieldsCommand(
mContext));
buttonActions.put(R.id.favoritesButton,
new LaunchFavoritesDialogCommand(mContext));
buttonActions.put(R.id.settingsButton, new LaunchSettingsDialogCommand(
mContext));
for (final Map.Entry<Integer, ButtonCommand> entry : buttonActions
.entrySet()) {
((Button) mContext.findViewById(entry.getKey()))
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
entry.getValue().execute();
}
});
}
}
private void initCommandInfoButton() {
Button commandInfoButton = (Button) mContext
.findViewById(R.id.commandQuestionButton);
commandInfoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) { | // Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ButtonCommand.java
// public interface ButtonCommand {
//
// /**
// * Perform the command.
// */
// public void execute();
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/ClearInputFieldsCommand.java
// public class ClearInputFieldsCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public ClearInputFieldsCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and clears all displaying inputfields.
// */
// @Override
// public void execute() {
// mContext.hideKeyboard();
// mContext.clearFields();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchFavoritesDialogCommand.java
// public class LaunchFavoritesDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchFavoritesDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the favorites dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchFavorites();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/LaunchSettingsDialogCommand.java
// public class LaunchSettingsDialogCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public LaunchSettingsDialogCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard and launches the settings dialog.
// */
// public void execute() {
// mContext.hideKeyboard();
// mContext.launchSettings();
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/diagnostic/command/RequestSendCommand.java
// public class RequestSendCommand implements ButtonCommand {
//
// DiagnosticActivity mContext;
//
// public RequestSendCommand(DiagnosticActivity context) {
// mContext = context;
// }
//
// /**
// * Hides the keyboard if displaying. Generates a
// * <code>DiagnosticRequest</code> or <code>Command</code> from the input,
// * depending on what is being displayed, and sends the generated command if
// * successful
// */
// public void execute() {
// mContext.hideKeyboard();
//
// VehicleMessage request;
// if (mContext.isDisplayingCommands()) {
// request = mContext.generateCommandFromInput();
// } else {
// request = mContext.generateDiagnosticRequestFromInput();
// }
// if (request != null) {
// mContext.send(request);
// }
// }
//
// }
//
// Path: src/com/openxc/openxcdiagnostic/util/DialogLauncher.java
// public class DialogLauncher {
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that says "OK" to
// * dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message) {
// launchAlert(context, title, message, "OK");
// }
//
// /**
// * Launch an alert with the given <code>title</code> and
// * <code>message</code>. The alert will have one button that has the value
// * of <code>doneButton</code> to dismiss it.
// *
// * @param context
// * @param title
// * @param message
// */
// public static void launchAlert(Activity context, String title,
// String message, String doneButton) {
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
// builder.setMessage(message);
// builder.setTitle(title);
// builder.setPositiveButton(doneButton, null);
// builder.create().show();
// }
//
// }
// Path: src/com/openxc/openxcdiagnostic/diagnostic/ButtonManager.java
import java.util.HashMap;
import java.util.Map;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.diagnostic.command.ButtonCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.ClearInputFieldsCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchFavoritesDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.LaunchSettingsDialogCommand;
import com.openxc.openxcdiagnostic.diagnostic.command.RequestSendCommand;
import com.openxc.openxcdiagnostic.util.DialogLauncher;
setRequestButtonText();
Map<Integer, ButtonCommand> buttonActions = new HashMap<>();
buttonActions.put(R.id.sendRequestButton, new RequestSendCommand(
mContext));
buttonActions.put(R.id.clearButton, new ClearInputFieldsCommand(
mContext));
buttonActions.put(R.id.favoritesButton,
new LaunchFavoritesDialogCommand(mContext));
buttonActions.put(R.id.settingsButton, new LaunchSettingsDialogCommand(
mContext));
for (final Map.Entry<Integer, ButtonCommand> entry : buttonActions
.entrySet()) {
((Button) mContext.findViewById(entry.getKey()))
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
entry.getValue().execute();
}
});
}
}
private void initCommandInfoButton() {
Button commandInfoButton = (Button) mContext
.findViewById(R.id.commandQuestionButton);
commandInfoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) { | DialogLauncher.launchAlert(mContext, |
openxc/diagnostic-tool | src/com/openxc/openxcdiagnostic/menu/MenuActivity.java | // Path: src/com/openxc/openxcdiagnostic/util/ActivityLauncher.java
// public class ActivityLauncher {
//
// public static Map<Integer, Class<?>> sActivityMap = new HashMap<>();
//
// static {
// sActivityMap.put(R.id.Diagnostic, DiagnosticActivity.class);
// sActivityMap.put(R.id.Menu, MenuActivity.class);
// sActivityMap.put(R.id.Dashboard, DashboardActivity.class);
// sActivityMap.put(R.id.Dump, DumpActivity.class);
// }
//
// public static void launchActivity(Activity activity, int itemId) {
//
// Class<?> newActivityClass = sActivityMap.get(Integer.valueOf(itemId));
// if (!activity.getClass().equals(newActivityClass)) {
// activity.startActivity(new Intent(activity, newActivityClass));
// }
// }
//
// }
| import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.util.ActivityLauncher; | MenuActivity.this.startActivity(intent);
Log.i(TAG, "Launching Grapher Activity");
}
});
}
private void flipButtonBackground(View v) {
Drawable pressed = getResources().getDrawable(GridManager.MenuButtonPressedImgID);
Drawable unpressed = getResources().getDrawable(GridManager.MenuButtonUnpressedImgID);
if (GridManager.drawablesAreEqual(v.getBackground(), pressed)) {
v.setBackground(unpressed);
} else if (GridManager.drawablesAreEqual(v.getBackground(), unpressed)) {
v.setBackground(pressed);
}
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) { | // Path: src/com/openxc/openxcdiagnostic/util/ActivityLauncher.java
// public class ActivityLauncher {
//
// public static Map<Integer, Class<?>> sActivityMap = new HashMap<>();
//
// static {
// sActivityMap.put(R.id.Diagnostic, DiagnosticActivity.class);
// sActivityMap.put(R.id.Menu, MenuActivity.class);
// sActivityMap.put(R.id.Dashboard, DashboardActivity.class);
// sActivityMap.put(R.id.Dump, DumpActivity.class);
// }
//
// public static void launchActivity(Activity activity, int itemId) {
//
// Class<?> newActivityClass = sActivityMap.get(Integer.valueOf(itemId));
// if (!activity.getClass().equals(newActivityClass)) {
// activity.startActivity(new Intent(activity, newActivityClass));
// }
// }
//
// }
// Path: src/com/openxc/openxcdiagnostic/menu/MenuActivity.java
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.util.ActivityLauncher;
MenuActivity.this.startActivity(intent);
Log.i(TAG, "Launching Grapher Activity");
}
});
}
private void flipButtonBackground(View v) {
Drawable pressed = getResources().getDrawable(GridManager.MenuButtonPressedImgID);
Drawable unpressed = getResources().getDrawable(GridManager.MenuButtonUnpressedImgID);
if (GridManager.drawablesAreEqual(v.getBackground(), pressed)) {
v.setBackground(unpressed);
} else if (GridManager.drawablesAreEqual(v.getBackground(), unpressed)) {
v.setBackground(pressed);
}
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) { | ActivityLauncher.launchActivity(this, item.getItemId()); |
openxc/diagnostic-tool | src/com/openxc/openxcdiagnostic/diagnostic/FavoritesManager.java | // Path: src/com/openxc/openxcdiagnostic/util/MessageAnalyzer.java
// public class MessageAnalyzer {
//
// public static boolean isCommand(VehicleMessage msg) {
// return msg instanceof Command;
// }
//
// public static boolean isDiagnosticRequest(VehicleMessage msg) {
// return msg instanceof DiagnosticRequest;
// }
//
// public static boolean isDiagnosticResponse(VehicleMessage msg) {
// return msg instanceof DiagnosticResponse;
// }
//
// public static boolean isCommandResponse(VehicleMessage msg) {
// return msg instanceof CommandResponse;
// }
//
// public static boolean canBeSent(VehicleMessage msg) {
// return isDiagnosticRequest(msg) || isCommand(msg);
// }
//
// /**
// * Determines if the given messages have equal bus, mode, and pid.
// *
// * @param msg1
// * @param msg2
// * @return
// */
// public static boolean exactMatchExceptId(DiagnosticMessage msg1,
// DiagnosticMessage msg2) {
// return msg1.getBusId() == msg2.getBusId()
// && msg1.getMode() == msg2.getMode()
// && msg1.getPid() == msg2.getPid();
// }
//
// /**
// * Finds a matching <code>KeyedMessage</code> in <code>arr</code>. Matching
// * is determined by matcher.matches(KeyedMessage)
// *
// * @param matcher
// * @param arr
// * @return
// */
// public static VehicleMessage findMatching(ExactKeyMatcher matcher,
// ArrayList<? extends KeyedMessage> arr) {
//
// if (matcher != null) {
// for (int i = 0; i < arr.size(); i++) {
// KeyedMessage request = arr.get(i);
// if (matcher.matches(request)) {
// return request;
// }
// }
// }
// return null;
// }
//
// }
| import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.util.Log;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.openxc.messages.Command;
import com.openxc.messages.DiagnosticRequest;
import com.openxc.messages.VehicleMessage;
import com.openxc.openxcdiagnostic.util.MessageAnalyzer; | package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Manager for storing favorite requests and commands.
*
*/
public class FavoritesManager {
private static String TAG = "DiagnosticFavoritesManager";
private static ArrayList<DiagnosticRequest> sFavoriteRequests;
private static ArrayList<Command> sFavoriteCommands;
private static SharedPreferences sPreferences;
// Don't like having to pass in a context to a static class on init, but
// advantageous this way so you can access favorites from any class.
public static void init(DiagnosticActivity context) {
sPreferences = PreferenceManager.getDefaultSharedPreferences(context);
sFavoriteRequests = loadFavoriteRequests();
sFavoriteCommands = loadFavoriteCommands();
}
/**
* Add the given <code>req</code> to favorites. The method will decide
* whether it should be added as a <code>DiagnosticRequest</code> or a
* <code>Command</code>.
*
* @param req
* The request/command to add.
*/
public static void add(VehicleMessage req) { | // Path: src/com/openxc/openxcdiagnostic/util/MessageAnalyzer.java
// public class MessageAnalyzer {
//
// public static boolean isCommand(VehicleMessage msg) {
// return msg instanceof Command;
// }
//
// public static boolean isDiagnosticRequest(VehicleMessage msg) {
// return msg instanceof DiagnosticRequest;
// }
//
// public static boolean isDiagnosticResponse(VehicleMessage msg) {
// return msg instanceof DiagnosticResponse;
// }
//
// public static boolean isCommandResponse(VehicleMessage msg) {
// return msg instanceof CommandResponse;
// }
//
// public static boolean canBeSent(VehicleMessage msg) {
// return isDiagnosticRequest(msg) || isCommand(msg);
// }
//
// /**
// * Determines if the given messages have equal bus, mode, and pid.
// *
// * @param msg1
// * @param msg2
// * @return
// */
// public static boolean exactMatchExceptId(DiagnosticMessage msg1,
// DiagnosticMessage msg2) {
// return msg1.getBusId() == msg2.getBusId()
// && msg1.getMode() == msg2.getMode()
// && msg1.getPid() == msg2.getPid();
// }
//
// /**
// * Finds a matching <code>KeyedMessage</code> in <code>arr</code>. Matching
// * is determined by matcher.matches(KeyedMessage)
// *
// * @param matcher
// * @param arr
// * @return
// */
// public static VehicleMessage findMatching(ExactKeyMatcher matcher,
// ArrayList<? extends KeyedMessage> arr) {
//
// if (matcher != null) {
// for (int i = 0; i < arr.size(); i++) {
// KeyedMessage request = arr.get(i);
// if (matcher.matches(request)) {
// return request;
// }
// }
// }
// return null;
// }
//
// }
// Path: src/com/openxc/openxcdiagnostic/diagnostic/FavoritesManager.java
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.util.Log;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.openxc.messages.Command;
import com.openxc.messages.DiagnosticRequest;
import com.openxc.messages.VehicleMessage;
import com.openxc.openxcdiagnostic.util.MessageAnalyzer;
package com.openxc.openxcdiagnostic.diagnostic;
/**
*
* Manager for storing favorite requests and commands.
*
*/
public class FavoritesManager {
private static String TAG = "DiagnosticFavoritesManager";
private static ArrayList<DiagnosticRequest> sFavoriteRequests;
private static ArrayList<Command> sFavoriteCommands;
private static SharedPreferences sPreferences;
// Don't like having to pass in a context to a static class on init, but
// advantageous this way so you can access favorites from any class.
public static void init(DiagnosticActivity context) {
sPreferences = PreferenceManager.getDefaultSharedPreferences(context);
sFavoriteRequests = loadFavoriteRequests();
sFavoriteCommands = loadFavoriteCommands();
}
/**
* Add the given <code>req</code> to favorites. The method will decide
* whether it should be added as a <code>DiagnosticRequest</code> or a
* <code>Command</code>.
*
* @param req
* The request/command to add.
*/
public static void add(VehicleMessage req) { | if (MessageAnalyzer.isDiagnosticRequest(req)) { |
openxc/diagnostic-tool | src/com/openxc/openxcdiagnostic/dump/DumpActivity.java | // Path: src/com/openxc/openxcdiagnostic/util/ActivityLauncher.java
// public class ActivityLauncher {
//
// public static Map<Integer, Class<?>> sActivityMap = new HashMap<>();
//
// static {
// sActivityMap.put(R.id.Diagnostic, DiagnosticActivity.class);
// sActivityMap.put(R.id.Menu, MenuActivity.class);
// sActivityMap.put(R.id.Dashboard, DashboardActivity.class);
// sActivityMap.put(R.id.Dump, DumpActivity.class);
// }
//
// public static void launchActivity(Activity activity, int itemId) {
//
// Class<?> newActivityClass = sActivityMap.get(Integer.valueOf(itemId));
// if (!activity.getClass().equals(newActivityClass)) {
// activity.startActivity(new Intent(activity, newActivityClass));
// }
// }
//
// }
| import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.openxc.VehicleManager;
import com.openxc.messages.KeyMatcher;
import com.openxc.messages.VehicleMessage;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.util.ActivityLauncher; | }
@Override
public void onDestroy() {
super.onDestroy();
if (mVehicleManager != null) {
mVehicleManager.removeListener(KeyMatcher.getWildcardMatcher(),
mDumpListener);
}
}
@Override
public void onResume() {
super.onResume();
bindService(new Intent(this, VehicleManager.class), mConnection,
Context.BIND_AUTO_CREATE);
}
@Override
public void onPause() {
super.onPause();
if (mIsBound) {
Log.i(TAG, "Unbinding from vehicle service");
unbindService(mConnection);
mIsBound = false;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) { | // Path: src/com/openxc/openxcdiagnostic/util/ActivityLauncher.java
// public class ActivityLauncher {
//
// public static Map<Integer, Class<?>> sActivityMap = new HashMap<>();
//
// static {
// sActivityMap.put(R.id.Diagnostic, DiagnosticActivity.class);
// sActivityMap.put(R.id.Menu, MenuActivity.class);
// sActivityMap.put(R.id.Dashboard, DashboardActivity.class);
// sActivityMap.put(R.id.Dump, DumpActivity.class);
// }
//
// public static void launchActivity(Activity activity, int itemId) {
//
// Class<?> newActivityClass = sActivityMap.get(Integer.valueOf(itemId));
// if (!activity.getClass().equals(newActivityClass)) {
// activity.startActivity(new Intent(activity, newActivityClass));
// }
// }
//
// }
// Path: src/com/openxc/openxcdiagnostic/dump/DumpActivity.java
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.openxc.VehicleManager;
import com.openxc.messages.KeyMatcher;
import com.openxc.messages.VehicleMessage;
import com.openxc.openxcdiagnostic.R;
import com.openxc.openxcdiagnostic.util.ActivityLauncher;
}
@Override
public void onDestroy() {
super.onDestroy();
if (mVehicleManager != null) {
mVehicleManager.removeListener(KeyMatcher.getWildcardMatcher(),
mDumpListener);
}
}
@Override
public void onResume() {
super.onResume();
bindService(new Intent(this, VehicleManager.class), mConnection,
Context.BIND_AUTO_CREATE);
}
@Override
public void onPause() {
super.onPause();
if (mIsBound) {
Log.i(TAG, "Unbinding from vehicle service");
unbindService(mConnection);
mIsBound = false;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) { | ActivityLauncher.launchActivity(this, item.getItemId()); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/ForeverExampleTest.java | // Path: src/test/java/org/simondean/vertx/async/unit/examples/ForeverExample.java
// public class ForeverExample extends BaseExample {
// public void foreverExample(AsyncResultHandler<String> handler) {
// Async.forever()
// .task(taskHandler -> {
// someAsyncMethodThatTakesAHandler(taskHandler);
// })
// .run(vertx, result -> {
// handler.handle(DefaultAsyncResult.fail(result));
// });
// }
//
// private void someAsyncMethodThatTakesAHandler(AsyncResultHandler<Void> handler) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.unit.examples.ForeverExample;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class ForeverExampleTest {
@Test
public void itHandlesFailure() { | // Path: src/test/java/org/simondean/vertx/async/unit/examples/ForeverExample.java
// public class ForeverExample extends BaseExample {
// public void foreverExample(AsyncResultHandler<String> handler) {
// Async.forever()
// .task(taskHandler -> {
// someAsyncMethodThatTakesAHandler(taskHandler);
// })
// .run(vertx, result -> {
// handler.handle(DefaultAsyncResult.fail(result));
// });
// }
//
// private void someAsyncMethodThatTakesAHandler(AsyncResultHandler<Void> handler) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/ForeverExampleTest.java
import org.junit.Test;
import org.simondean.vertx.async.unit.examples.ForeverExample;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class ForeverExampleTest {
@Test
public void itHandlesFailure() { | ForeverExample example = new ForeverExample(); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/ForeverTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeVertx.java
// public class FakeVertx implements Vertx {
// @Override
// public NetServer createNetServer() {
// return null;
// }
//
// @Override
// public NetClient createNetClient() {
// return null;
// }
//
// @Override
// public HttpServer createHttpServer() {
// return null;
// }
//
// @Override
// public HttpClient createHttpClient() {
// return null;
// }
//
// @Override
// public DatagramSocket createDatagramSocket(InternetProtocolFamily internetProtocolFamily) {
// return null;
// }
//
// @Override
// public SockJSServer createSockJSServer(HttpServer httpServer) {
// return null;
// }
//
// @Override
// public FileSystem fileSystem() {
// return null;
// }
//
// @Override
// public EventBus eventBus() {
// return null;
// }
//
// @Override
// public DnsClient createDnsClient(InetSocketAddress... inetSocketAddresses) {
// return null;
// }
//
// @Override
// public SharedData sharedData() {
// return null;
// }
//
// @Override
// public long setTimer(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public long setPeriodic(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public boolean cancelTimer(long l) {
// return false;
// }
//
// @Override
// public Context currentContext() {
// return null;
// }
//
// @Override
// public void runOnContext(Handler<Void> handler) {
// handler.handle(null);
// }
//
// @Override
// public boolean isEventLoop() {
// return false;
// }
//
// @Override
// public boolean isWorker() {
// return false;
// }
//
// @Override
// public void stop() {
//
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeVertx;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class ForeverTest {
@Test
public void itExecutesTheTaskUntilItFails() { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeVertx.java
// public class FakeVertx implements Vertx {
// @Override
// public NetServer createNetServer() {
// return null;
// }
//
// @Override
// public NetClient createNetClient() {
// return null;
// }
//
// @Override
// public HttpServer createHttpServer() {
// return null;
// }
//
// @Override
// public HttpClient createHttpClient() {
// return null;
// }
//
// @Override
// public DatagramSocket createDatagramSocket(InternetProtocolFamily internetProtocolFamily) {
// return null;
// }
//
// @Override
// public SockJSServer createSockJSServer(HttpServer httpServer) {
// return null;
// }
//
// @Override
// public FileSystem fileSystem() {
// return null;
// }
//
// @Override
// public EventBus eventBus() {
// return null;
// }
//
// @Override
// public DnsClient createDnsClient(InetSocketAddress... inetSocketAddresses) {
// return null;
// }
//
// @Override
// public SharedData sharedData() {
// return null;
// }
//
// @Override
// public long setTimer(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public long setPeriodic(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public boolean cancelTimer(long l) {
// return false;
// }
//
// @Override
// public Context currentContext() {
// return null;
// }
//
// @Override
// public void runOnContext(Handler<Void> handler) {
// handler.handle(null);
// }
//
// @Override
// public boolean isEventLoop() {
// return false;
// }
//
// @Override
// public boolean isWorker() {
// return false;
// }
//
// @Override
// public void stop() {
//
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/ForeverTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeVertx;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class ForeverTest {
@Test
public void itExecutesTheTaskUntilItFails() { | FakeFailingAsyncSupplier<Void> task1 = new FakeFailingAsyncSupplier<>(2, null, new Throwable("Failed")); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/ForeverTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeVertx.java
// public class FakeVertx implements Vertx {
// @Override
// public NetServer createNetServer() {
// return null;
// }
//
// @Override
// public NetClient createNetClient() {
// return null;
// }
//
// @Override
// public HttpServer createHttpServer() {
// return null;
// }
//
// @Override
// public HttpClient createHttpClient() {
// return null;
// }
//
// @Override
// public DatagramSocket createDatagramSocket(InternetProtocolFamily internetProtocolFamily) {
// return null;
// }
//
// @Override
// public SockJSServer createSockJSServer(HttpServer httpServer) {
// return null;
// }
//
// @Override
// public FileSystem fileSystem() {
// return null;
// }
//
// @Override
// public EventBus eventBus() {
// return null;
// }
//
// @Override
// public DnsClient createDnsClient(InetSocketAddress... inetSocketAddresses) {
// return null;
// }
//
// @Override
// public SharedData sharedData() {
// return null;
// }
//
// @Override
// public long setTimer(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public long setPeriodic(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public boolean cancelTimer(long l) {
// return false;
// }
//
// @Override
// public Context currentContext() {
// return null;
// }
//
// @Override
// public void runOnContext(Handler<Void> handler) {
// handler.handle(null);
// }
//
// @Override
// public boolean isEventLoop() {
// return false;
// }
//
// @Override
// public boolean isWorker() {
// return false;
// }
//
// @Override
// public void stop() {
//
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeVertx;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class ForeverTest {
@Test
public void itExecutesTheTaskUntilItFails() {
FakeFailingAsyncSupplier<Void> task1 = new FakeFailingAsyncSupplier<>(2, null, new Throwable("Failed"));
| // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeVertx.java
// public class FakeVertx implements Vertx {
// @Override
// public NetServer createNetServer() {
// return null;
// }
//
// @Override
// public NetClient createNetClient() {
// return null;
// }
//
// @Override
// public HttpServer createHttpServer() {
// return null;
// }
//
// @Override
// public HttpClient createHttpClient() {
// return null;
// }
//
// @Override
// public DatagramSocket createDatagramSocket(InternetProtocolFamily internetProtocolFamily) {
// return null;
// }
//
// @Override
// public SockJSServer createSockJSServer(HttpServer httpServer) {
// return null;
// }
//
// @Override
// public FileSystem fileSystem() {
// return null;
// }
//
// @Override
// public EventBus eventBus() {
// return null;
// }
//
// @Override
// public DnsClient createDnsClient(InetSocketAddress... inetSocketAddresses) {
// return null;
// }
//
// @Override
// public SharedData sharedData() {
// return null;
// }
//
// @Override
// public long setTimer(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public long setPeriodic(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public boolean cancelTimer(long l) {
// return false;
// }
//
// @Override
// public Context currentContext() {
// return null;
// }
//
// @Override
// public void runOnContext(Handler<Void> handler) {
// handler.handle(null);
// }
//
// @Override
// public boolean isEventLoop() {
// return false;
// }
//
// @Override
// public boolean isWorker() {
// return false;
// }
//
// @Override
// public void stop() {
//
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/ForeverTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeVertx;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class ForeverTest {
@Test
public void itExecutesTheTaskUntilItFails() {
FakeFailingAsyncSupplier<Void> task1 = new FakeFailingAsyncSupplier<>(2, null, new Throwable("Failed"));
| ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/ForeverTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeVertx.java
// public class FakeVertx implements Vertx {
// @Override
// public NetServer createNetServer() {
// return null;
// }
//
// @Override
// public NetClient createNetClient() {
// return null;
// }
//
// @Override
// public HttpServer createHttpServer() {
// return null;
// }
//
// @Override
// public HttpClient createHttpClient() {
// return null;
// }
//
// @Override
// public DatagramSocket createDatagramSocket(InternetProtocolFamily internetProtocolFamily) {
// return null;
// }
//
// @Override
// public SockJSServer createSockJSServer(HttpServer httpServer) {
// return null;
// }
//
// @Override
// public FileSystem fileSystem() {
// return null;
// }
//
// @Override
// public EventBus eventBus() {
// return null;
// }
//
// @Override
// public DnsClient createDnsClient(InetSocketAddress... inetSocketAddresses) {
// return null;
// }
//
// @Override
// public SharedData sharedData() {
// return null;
// }
//
// @Override
// public long setTimer(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public long setPeriodic(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public boolean cancelTimer(long l) {
// return false;
// }
//
// @Override
// public Context currentContext() {
// return null;
// }
//
// @Override
// public void runOnContext(Handler<Void> handler) {
// handler.handle(null);
// }
//
// @Override
// public boolean isEventLoop() {
// return false;
// }
//
// @Override
// public boolean isWorker() {
// return false;
// }
//
// @Override
// public void stop() {
//
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeVertx;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class ForeverTest {
@Test
public void itExecutesTheTaskUntilItFails() {
FakeFailingAsyncSupplier<Void> task1 = new FakeFailingAsyncSupplier<>(2, null, new Throwable("Failed"));
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
| // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeVertx.java
// public class FakeVertx implements Vertx {
// @Override
// public NetServer createNetServer() {
// return null;
// }
//
// @Override
// public NetClient createNetClient() {
// return null;
// }
//
// @Override
// public HttpServer createHttpServer() {
// return null;
// }
//
// @Override
// public HttpClient createHttpClient() {
// return null;
// }
//
// @Override
// public DatagramSocket createDatagramSocket(InternetProtocolFamily internetProtocolFamily) {
// return null;
// }
//
// @Override
// public SockJSServer createSockJSServer(HttpServer httpServer) {
// return null;
// }
//
// @Override
// public FileSystem fileSystem() {
// return null;
// }
//
// @Override
// public EventBus eventBus() {
// return null;
// }
//
// @Override
// public DnsClient createDnsClient(InetSocketAddress... inetSocketAddresses) {
// return null;
// }
//
// @Override
// public SharedData sharedData() {
// return null;
// }
//
// @Override
// public long setTimer(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public long setPeriodic(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public boolean cancelTimer(long l) {
// return false;
// }
//
// @Override
// public Context currentContext() {
// return null;
// }
//
// @Override
// public void runOnContext(Handler<Void> handler) {
// handler.handle(null);
// }
//
// @Override
// public boolean isEventLoop() {
// return false;
// }
//
// @Override
// public boolean isWorker() {
// return false;
// }
//
// @Override
// public void stop() {
//
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/ForeverTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeVertx;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class ForeverTest {
@Test
public void itExecutesTheTaskUntilItFails() {
FakeFailingAsyncSupplier<Void> task1 = new FakeFailingAsyncSupplier<>(2, null, new Throwable("Failed"));
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
| Async.forever() |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/ForeverTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeVertx.java
// public class FakeVertx implements Vertx {
// @Override
// public NetServer createNetServer() {
// return null;
// }
//
// @Override
// public NetClient createNetClient() {
// return null;
// }
//
// @Override
// public HttpServer createHttpServer() {
// return null;
// }
//
// @Override
// public HttpClient createHttpClient() {
// return null;
// }
//
// @Override
// public DatagramSocket createDatagramSocket(InternetProtocolFamily internetProtocolFamily) {
// return null;
// }
//
// @Override
// public SockJSServer createSockJSServer(HttpServer httpServer) {
// return null;
// }
//
// @Override
// public FileSystem fileSystem() {
// return null;
// }
//
// @Override
// public EventBus eventBus() {
// return null;
// }
//
// @Override
// public DnsClient createDnsClient(InetSocketAddress... inetSocketAddresses) {
// return null;
// }
//
// @Override
// public SharedData sharedData() {
// return null;
// }
//
// @Override
// public long setTimer(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public long setPeriodic(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public boolean cancelTimer(long l) {
// return false;
// }
//
// @Override
// public Context currentContext() {
// return null;
// }
//
// @Override
// public void runOnContext(Handler<Void> handler) {
// handler.handle(null);
// }
//
// @Override
// public boolean isEventLoop() {
// return false;
// }
//
// @Override
// public boolean isWorker() {
// return false;
// }
//
// @Override
// public void stop() {
//
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeVertx;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class ForeverTest {
@Test
public void itExecutesTheTaskUntilItFails() {
FakeFailingAsyncSupplier<Void> task1 = new FakeFailingAsyncSupplier<>(2, null, new Throwable("Failed"));
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
Async.forever()
.task(task1) | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeVertx.java
// public class FakeVertx implements Vertx {
// @Override
// public NetServer createNetServer() {
// return null;
// }
//
// @Override
// public NetClient createNetClient() {
// return null;
// }
//
// @Override
// public HttpServer createHttpServer() {
// return null;
// }
//
// @Override
// public HttpClient createHttpClient() {
// return null;
// }
//
// @Override
// public DatagramSocket createDatagramSocket(InternetProtocolFamily internetProtocolFamily) {
// return null;
// }
//
// @Override
// public SockJSServer createSockJSServer(HttpServer httpServer) {
// return null;
// }
//
// @Override
// public FileSystem fileSystem() {
// return null;
// }
//
// @Override
// public EventBus eventBus() {
// return null;
// }
//
// @Override
// public DnsClient createDnsClient(InetSocketAddress... inetSocketAddresses) {
// return null;
// }
//
// @Override
// public SharedData sharedData() {
// return null;
// }
//
// @Override
// public long setTimer(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public long setPeriodic(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public boolean cancelTimer(long l) {
// return false;
// }
//
// @Override
// public Context currentContext() {
// return null;
// }
//
// @Override
// public void runOnContext(Handler<Void> handler) {
// handler.handle(null);
// }
//
// @Override
// public boolean isEventLoop() {
// return false;
// }
//
// @Override
// public boolean isWorker() {
// return false;
// }
//
// @Override
// public void stop() {
//
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/ForeverTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeVertx;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class ForeverTest {
@Test
public void itExecutesTheTaskUntilItFails() {
FakeFailingAsyncSupplier<Void> task1 = new FakeFailingAsyncSupplier<>(2, null, new Throwable("Failed"));
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
Async.forever()
.task(task1) | .run(new FakeVertx(), result -> { |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/examples/WaterfallExample.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult; | package org.simondean.vertx.async.unit.examples;
public class WaterfallExample extends BaseExample {
private final boolean succeed;
private Integer result;
public WaterfallExample(boolean succeed) {
this.succeed = succeed;
}
public void waterfallExample(AsyncResultHandler<Integer> handler) { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/examples/WaterfallExample.java
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
package org.simondean.vertx.async.unit.examples;
public class WaterfallExample extends BaseExample {
private final boolean succeed;
private Integer result;
public WaterfallExample(boolean succeed) {
this.succeed = succeed;
}
public void waterfallExample(AsyncResultHandler<Integer> handler) { | Async.waterfall() |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/examples/WaterfallExample.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult; | package org.simondean.vertx.async.unit.examples;
public class WaterfallExample extends BaseExample {
private final boolean succeed;
private Integer result;
public WaterfallExample(boolean succeed) {
this.succeed = succeed;
}
public void waterfallExample(AsyncResultHandler<Integer> handler) {
Async.waterfall()
.<String>task(taskHandler -> {
String result = getSomeResult(); | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/examples/WaterfallExample.java
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
package org.simondean.vertx.async.unit.examples;
public class WaterfallExample extends BaseExample {
private final boolean succeed;
private Integer result;
public WaterfallExample(boolean succeed) {
this.succeed = succeed;
}
public void waterfallExample(AsyncResultHandler<Integer> handler) {
Async.waterfall()
.<String>task(taskHandler -> {
String result = getSomeResult(); | taskHandler.handle(DefaultAsyncResult.succeed(result)); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/IterableBuilderImpl.java | // Path: src/main/java/org/simondean/vertx/async/EachBuilder.java
// public interface EachBuilder {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/IterableBuilder.java
// public interface IterableBuilder<T> {
// EachBuilder each(BiConsumer<T, AsyncResultHandler<Void>> each);
// }
| import org.simondean.vertx.async.EachBuilder;
import org.simondean.vertx.async.IterableBuilder;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.BiConsumer; | package org.simondean.vertx.async.internal;
public class IterableBuilderImpl<T> implements IterableBuilder<T> {
private final Iterable<T> iterable;
public IterableBuilderImpl(Iterable<T> iterable) {
this.iterable = iterable;
}
@Override | // Path: src/main/java/org/simondean/vertx/async/EachBuilder.java
// public interface EachBuilder {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/IterableBuilder.java
// public interface IterableBuilder<T> {
// EachBuilder each(BiConsumer<T, AsyncResultHandler<Void>> each);
// }
// Path: src/main/java/org/simondean/vertx/async/internal/IterableBuilderImpl.java
import org.simondean.vertx.async.EachBuilder;
import org.simondean.vertx.async.IterableBuilder;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.BiConsumer;
package org.simondean.vertx.async.internal;
public class IterableBuilderImpl<T> implements IterableBuilder<T> {
private final Iterable<T> iterable;
public IterableBuilderImpl(Iterable<T> iterable) {
this.iterable = iterable;
}
@Override | public EachBuilder each(BiConsumer<T, AsyncResultHandler<Void>> each) { |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/RetryImpl.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Retry.java
// public interface Retry<T> {
// void run(AsyncResultHandler<T> handler);
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.FunctionWrapper;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.Retry;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer; | package org.simondean.vertx.async.internal;
public class RetryImpl<T> implements Retry<T> {
private final Consumer<AsyncResultHandler<T>> task;
private final int times;
public RetryImpl(Consumer<AsyncResultHandler<T>> task, int times) {
this.task = task;
this.times = times;
}
@Override
public void run(AsyncResultHandler<T> handler) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Retry.java
// public interface Retry<T> {
// void run(AsyncResultHandler<T> handler);
// }
// Path: src/main/java/org/simondean/vertx/async/internal/RetryImpl.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.FunctionWrapper;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.Retry;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer;
package org.simondean.vertx.async.internal;
public class RetryImpl<T> implements Retry<T> {
private final Consumer<AsyncResultHandler<T>> task;
private final int times;
public RetryImpl(Consumer<AsyncResultHandler<T>> task, int times) {
this.task = task;
this.times = times;
}
@Override
public void run(AsyncResultHandler<T> handler) { | ObjectWrapper<Integer> count = new ObjectWrapper<>(0); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/RetryImpl.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Retry.java
// public interface Retry<T> {
// void run(AsyncResultHandler<T> handler);
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.FunctionWrapper;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.Retry;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer; | package org.simondean.vertx.async.internal;
public class RetryImpl<T> implements Retry<T> {
private final Consumer<AsyncResultHandler<T>> task;
private final int times;
public RetryImpl(Consumer<AsyncResultHandler<T>> task, int times) {
this.task = task;
this.times = times;
}
@Override
public void run(AsyncResultHandler<T> handler) {
ObjectWrapper<Integer> count = new ObjectWrapper<>(0);
| // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Retry.java
// public interface Retry<T> {
// void run(AsyncResultHandler<T> handler);
// }
// Path: src/main/java/org/simondean/vertx/async/internal/RetryImpl.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.FunctionWrapper;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.Retry;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer;
package org.simondean.vertx.async.internal;
public class RetryImpl<T> implements Retry<T> {
private final Consumer<AsyncResultHandler<T>> task;
private final int times;
public RetryImpl(Consumer<AsyncResultHandler<T>> task, int times) {
this.task = task;
this.times = times;
}
@Override
public void run(AsyncResultHandler<T> handler) {
ObjectWrapper<Integer> count = new ObjectWrapper<>(0);
| FunctionWrapper<Runnable> visitor = new FunctionWrapper<>(); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/RetryImpl.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Retry.java
// public interface Retry<T> {
// void run(AsyncResultHandler<T> handler);
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.FunctionWrapper;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.Retry;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer; | package org.simondean.vertx.async.internal;
public class RetryImpl<T> implements Retry<T> {
private final Consumer<AsyncResultHandler<T>> task;
private final int times;
public RetryImpl(Consumer<AsyncResultHandler<T>> task, int times) {
this.task = task;
this.times = times;
}
@Override
public void run(AsyncResultHandler<T> handler) {
ObjectWrapper<Integer> count = new ObjectWrapper<>(0);
FunctionWrapper<Runnable> visitor = new FunctionWrapper<>();
visitor.wrap(() -> task.accept(result -> {
if (result.failed()) {
count.setObject(count.getObject() + 1);
if (count.getObject() > times) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Retry.java
// public interface Retry<T> {
// void run(AsyncResultHandler<T> handler);
// }
// Path: src/main/java/org/simondean/vertx/async/internal/RetryImpl.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.FunctionWrapper;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.Retry;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer;
package org.simondean.vertx.async.internal;
public class RetryImpl<T> implements Retry<T> {
private final Consumer<AsyncResultHandler<T>> task;
private final int times;
public RetryImpl(Consumer<AsyncResultHandler<T>> task, int times) {
this.task = task;
this.times = times;
}
@Override
public void run(AsyncResultHandler<T> handler) {
ObjectWrapper<Integer> count = new ObjectWrapper<>(0);
FunctionWrapper<Runnable> visitor = new FunctionWrapper<>();
visitor.wrap(() -> task.accept(result -> {
if (result.failed()) {
count.setObject(count.getObject() + 1);
if (count.getObject() > times) { | handler.handle(DefaultAsyncResult.fail(result)); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/examples/RetryExample.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler; | package org.simondean.vertx.async.unit.examples;
public class RetryExample extends BaseExample {
private final boolean succeed;
private String result;
public RetryExample(boolean succeed) {
this.succeed = succeed;
}
public void retryExample(AsyncResultHandler<String> handler) { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/examples/RetryExample.java
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
package org.simondean.vertx.async.unit.examples;
public class RetryExample extends BaseExample {
private final boolean succeed;
private String result;
public RetryExample(boolean succeed) {
this.succeed = succeed;
}
public void retryExample(AsyncResultHandler<String> handler) { | Async.retry() |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/examples/RetryExample.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler; | package org.simondean.vertx.async.unit.examples;
public class RetryExample extends BaseExample {
private final boolean succeed;
private String result;
public RetryExample(boolean succeed) {
this.succeed = succeed;
}
public void retryExample(AsyncResultHandler<String> handler) {
Async.retry()
.<String>task(taskHandler -> {
someAsyncMethodThatTakesAHandler(taskHandler);
})
.times(5)
.run(result -> {
if (result.failed()) { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/examples/RetryExample.java
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
package org.simondean.vertx.async.unit.examples;
public class RetryExample extends BaseExample {
private final boolean succeed;
private String result;
public RetryExample(boolean succeed) {
this.succeed = succeed;
}
public void retryExample(AsyncResultHandler<String> handler) {
Async.retry()
.<String>task(taskHandler -> {
someAsyncMethodThatTakesAHandler(taskHandler);
})
.times(5)
.run(result -> {
if (result.failed()) { | handler.handle(DefaultAsyncResult.fail(result)); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/SeriesExampleTest.java | // Path: src/test/java/org/simondean/vertx/async/unit/examples/SeriesExample.java
// public class SeriesExample extends BaseExample {
// private final boolean succeed;
// private List<String> results;
//
// public SeriesExample(boolean succeed) {
// this.succeed = succeed;
// }
//
// public void seriesExample(AsyncResultHandler<List<String>> handler) {
// Async.<String>series()
// .task(taskHandler -> {
// String result = getSomeResult();
// taskHandler.handle(DefaultAsyncResult.succeed(result));
// })
// .task(taskHandler -> {
// someAsyncMethodThatTakesAHandler(taskHandler);
// })
// .run(result -> {
// if (result.failed()) {
// handler.handle(DefaultAsyncResult.fail(result));
// return;
// }
//
// List<String> resultList = result.result();
// doSomethingWithTheResults(resultList);
//
// handler.handle(DefaultAsyncResult.succeed(resultList));
// });
// }
//
// private String getSomeResult() {
// return "Result";
// }
//
// private void someAsyncMethodThatTakesAHandler(AsyncResultHandler<String> handler) {
// if (!succeed) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// return;
// }
//
// handler.handle(DefaultAsyncResult.succeed("Async result"));
// }
//
// private void doSomethingWithTheResults(List<String> results) {
// this.results = results;
// }
//
// public List<String> results() {
// return results;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.unit.examples.SeriesExample;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class SeriesExampleTest {
@Test
public void itHandlesSuccess() { | // Path: src/test/java/org/simondean/vertx/async/unit/examples/SeriesExample.java
// public class SeriesExample extends BaseExample {
// private final boolean succeed;
// private List<String> results;
//
// public SeriesExample(boolean succeed) {
// this.succeed = succeed;
// }
//
// public void seriesExample(AsyncResultHandler<List<String>> handler) {
// Async.<String>series()
// .task(taskHandler -> {
// String result = getSomeResult();
// taskHandler.handle(DefaultAsyncResult.succeed(result));
// })
// .task(taskHandler -> {
// someAsyncMethodThatTakesAHandler(taskHandler);
// })
// .run(result -> {
// if (result.failed()) {
// handler.handle(DefaultAsyncResult.fail(result));
// return;
// }
//
// List<String> resultList = result.result();
// doSomethingWithTheResults(resultList);
//
// handler.handle(DefaultAsyncResult.succeed(resultList));
// });
// }
//
// private String getSomeResult() {
// return "Result";
// }
//
// private void someAsyncMethodThatTakesAHandler(AsyncResultHandler<String> handler) {
// if (!succeed) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// return;
// }
//
// handler.handle(DefaultAsyncResult.succeed("Async result"));
// }
//
// private void doSomethingWithTheResults(List<String> results) {
// this.results = results;
// }
//
// public List<String> results() {
// return results;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/SeriesExampleTest.java
import org.junit.Test;
import org.simondean.vertx.async.unit.examples.SeriesExample;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class SeriesExampleTest {
@Test
public void itHandlesSuccess() { | SeriesExample example = new SeriesExample(true); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/WaterfallTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncFunction.java
// public class FakeFailingAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int successCount;
// private final R result;
// private final Throwable cause;
//
// public FakeFailingAsyncFunction(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncFunction(int successCount, R result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncFunction.java
// public class FakeSuccessfulAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int failureCount;
// private final R result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncFunction(R result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncFunction(int failureCount, Throwable cause, R result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public R result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class WaterfallTest {
@Test
public void itExecutesOneTask() { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncFunction.java
// public class FakeFailingAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int successCount;
// private final R result;
// private final Throwable cause;
//
// public FakeFailingAsyncFunction(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncFunction(int successCount, R result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncFunction.java
// public class FakeSuccessfulAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int failureCount;
// private final R result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncFunction(R result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncFunction(int failureCount, Throwable cause, R result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public R result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/WaterfallTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class WaterfallTest {
@Test
public void itExecutesOneTask() { | FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1"); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/WaterfallTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncFunction.java
// public class FakeFailingAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int successCount;
// private final R result;
// private final Throwable cause;
//
// public FakeFailingAsyncFunction(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncFunction(int successCount, R result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncFunction.java
// public class FakeSuccessfulAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int failureCount;
// private final R result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncFunction(R result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncFunction(int failureCount, Throwable cause, R result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public R result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class WaterfallTest {
@Test
public void itExecutesOneTask() {
FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1");
| // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncFunction.java
// public class FakeFailingAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int successCount;
// private final R result;
// private final Throwable cause;
//
// public FakeFailingAsyncFunction(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncFunction(int successCount, R result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncFunction.java
// public class FakeSuccessfulAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int failureCount;
// private final R result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncFunction(R result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncFunction(int failureCount, Throwable cause, R result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public R result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/WaterfallTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class WaterfallTest {
@Test
public void itExecutesOneTask() {
FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1");
| ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/WaterfallTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncFunction.java
// public class FakeFailingAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int successCount;
// private final R result;
// private final Throwable cause;
//
// public FakeFailingAsyncFunction(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncFunction(int successCount, R result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncFunction.java
// public class FakeSuccessfulAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int failureCount;
// private final R result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncFunction(R result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncFunction(int failureCount, Throwable cause, R result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public R result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class WaterfallTest {
@Test
public void itExecutesOneTask() {
FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1");
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
| // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncFunction.java
// public class FakeFailingAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int successCount;
// private final R result;
// private final Throwable cause;
//
// public FakeFailingAsyncFunction(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncFunction(int successCount, R result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncFunction.java
// public class FakeSuccessfulAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
// private final int failureCount;
// private final R result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncFunction(R result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncFunction(int failureCount, Throwable cause, R result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(T value, AsyncResultHandler<R> handler) {
// addConsumedValue(value);
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public R result() {
// return result;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/WaterfallTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncFunction;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class WaterfallTest {
@Test
public void itExecutesOneTask() {
FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1");
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
| Async.waterfall() |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/WaterfallExampleTest.java | // Path: src/test/java/org/simondean/vertx/async/unit/examples/WaterfallExample.java
// public class WaterfallExample extends BaseExample {
// private final boolean succeed;
// private Integer result;
//
// public WaterfallExample(boolean succeed) {
// this.succeed = succeed;
// }
//
// public void waterfallExample(AsyncResultHandler<Integer> handler) {
// Async.waterfall()
// .<String>task(taskHandler -> {
// String result = getSomeResult();
// taskHandler.handle(DefaultAsyncResult.succeed(result));
// })
// .<Integer>task((result, taskHandler) -> {
// someAsyncMethodThatTakesAResultAndHandler(result, taskHandler);
// })
// .run(result -> {
// if (result.failed()) {
// handler.handle(DefaultAsyncResult.fail(result.cause()));
// return;
// }
//
// Integer resultValue = result.result();
// doSomethingWithTheResults(resultValue);
//
// handler.handle(DefaultAsyncResult.succeed(resultValue));
// });
// }
//
// private String getSomeResult() {
// return "42";
// }
//
// private void someAsyncMethodThatTakesAResultAndHandler(String result, AsyncResultHandler<Integer> handler) {
// if (!succeed) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// return;
// }
//
// handler.handle(DefaultAsyncResult.succeed(Integer.parseInt(result)));
// }
//
// private void doSomethingWithTheResults(Integer result) {
// this.result = result;
// }
//
// public Integer result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.unit.examples.WaterfallExample;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class WaterfallExampleTest {
@Test
public void itHandlesSuccess() { | // Path: src/test/java/org/simondean/vertx/async/unit/examples/WaterfallExample.java
// public class WaterfallExample extends BaseExample {
// private final boolean succeed;
// private Integer result;
//
// public WaterfallExample(boolean succeed) {
// this.succeed = succeed;
// }
//
// public void waterfallExample(AsyncResultHandler<Integer> handler) {
// Async.waterfall()
// .<String>task(taskHandler -> {
// String result = getSomeResult();
// taskHandler.handle(DefaultAsyncResult.succeed(result));
// })
// .<Integer>task((result, taskHandler) -> {
// someAsyncMethodThatTakesAResultAndHandler(result, taskHandler);
// })
// .run(result -> {
// if (result.failed()) {
// handler.handle(DefaultAsyncResult.fail(result.cause()));
// return;
// }
//
// Integer resultValue = result.result();
// doSomethingWithTheResults(resultValue);
//
// handler.handle(DefaultAsyncResult.succeed(resultValue));
// });
// }
//
// private String getSomeResult() {
// return "42";
// }
//
// private void someAsyncMethodThatTakesAResultAndHandler(String result, AsyncResultHandler<Integer> handler) {
// if (!succeed) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// return;
// }
//
// handler.handle(DefaultAsyncResult.succeed(Integer.parseInt(result)));
// }
//
// private void doSomethingWithTheResults(Integer result) {
// this.result = result;
// }
//
// public Integer result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/WaterfallExampleTest.java
import org.junit.Test;
import org.simondean.vertx.async.unit.examples.WaterfallExample;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class WaterfallExampleTest {
@Test
public void itHandlesSuccess() { | WaterfallExample example = new WaterfallExample(true); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/SeriesTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class SeriesTest {
@Test
public void itStillExecutesWhenThereAreNoTasks() { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/SeriesTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class SeriesTest {
@Test
public void itStillExecutesWhenThereAreNoTasks() { | ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/SeriesTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class SeriesTest {
@Test
public void itStillExecutesWhenThereAreNoTasks() {
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
| // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/SeriesTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class SeriesTest {
@Test
public void itStillExecutesWhenThereAreNoTasks() {
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
| Async.series() |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/SeriesTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class SeriesTest {
@Test
public void itStillExecutesWhenThereAreNoTasks() {
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
Async.series()
.run(result -> {
handlerCallCount.setObject(handlerCallCount.getObject() + 1);
assertThat(result).isNotNull();
assertThat(result.succeeded()).isTrue();
List<Object> resultList = result.result();
assertThat(resultList).isNotNull();
assertThat(resultList).isEmpty();
});
assertThat(handlerCallCount.getObject()).isEqualTo(1);
}
@Test
public void itExecutesOneTask() { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/SeriesTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class SeriesTest {
@Test
public void itStillExecutesWhenThereAreNoTasks() {
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
Async.series()
.run(result -> {
handlerCallCount.setObject(handlerCallCount.getObject() + 1);
assertThat(result).isNotNull();
assertThat(result.succeeded()).isTrue();
List<Object> resultList = result.result();
assertThat(resultList).isNotNull();
assertThat(resultList).isEmpty();
});
assertThat(handlerCallCount.getObject()).isEqualTo(1);
}
@Test
public void itExecutesOneTask() { | FakeSuccessfulAsyncSupplier<Object> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1"); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/SeriesTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; | }
@Test
public void itExecutesTwoTasks() {
FakeSuccessfulAsyncSupplier<Object> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1");
FakeSuccessfulAsyncSupplier<Object> task2 = new FakeSuccessfulAsyncSupplier<>("Task 2");
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
Async.series()
.task(task1)
.task(task2)
.run(result -> {
handlerCallCount.setObject(handlerCallCount.getObject() + 1);
assertThat(task1.runCount()).isEqualTo(1);
assertThat(task2.runCount()).isEqualTo(1);
assertThat(result).isNotNull();
assertThat(result.succeeded()).isTrue();
List<Object> resultList = result.result();
assertThat(resultList).isNotNull();
assertThat(resultList).containsExactly(task1.result(), task2.result());
});
assertThat(handlerCallCount.getObject()).isEqualTo(1);
}
@Test
public void itFailsWhenATaskFails() { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/SeriesTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
}
@Test
public void itExecutesTwoTasks() {
FakeSuccessfulAsyncSupplier<Object> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1");
FakeSuccessfulAsyncSupplier<Object> task2 = new FakeSuccessfulAsyncSupplier<>("Task 2");
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
Async.series()
.task(task1)
.task(task2)
.run(result -> {
handlerCallCount.setObject(handlerCallCount.getObject() + 1);
assertThat(task1.runCount()).isEqualTo(1);
assertThat(task2.runCount()).isEqualTo(1);
assertThat(result).isNotNull();
assertThat(result.succeeded()).isTrue();
List<Object> resultList = result.result();
assertThat(resultList).isNotNull();
assertThat(resultList).containsExactly(task1.result(), task2.result());
});
assertThat(handlerCallCount.getObject()).isEqualTo(1);
}
@Test
public void itFailsWhenATaskFails() { | FakeFailingAsyncSupplier<Object> task1 = new FakeFailingAsyncSupplier<>(new Throwable("Failed")); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/EachTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.*;
import java.util.ArrayList;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class EachTest {
@Test
public void itStillExecutesWhenThereAreNoItems() {
ArrayList<String> items = new ArrayList<>();
FakeFailingAsyncFunction<String, Void> each = new FakeFailingAsyncFunction<>(new Throwable("Failed"));
| // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/EachTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.*;
import java.util.ArrayList;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class EachTest {
@Test
public void itStillExecutesWhenThereAreNoItems() {
ArrayList<String> items = new ArrayList<>();
FakeFailingAsyncFunction<String, Void> each = new FakeFailingAsyncFunction<>(new Throwable("Failed"));
| ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/EachTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.*;
import java.util.ArrayList;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class EachTest {
@Test
public void itStillExecutesWhenThereAreNoItems() {
ArrayList<String> items = new ArrayList<>();
FakeFailingAsyncFunction<String, Void> each = new FakeFailingAsyncFunction<>(new Throwable("Failed"));
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
| // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/EachTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.*;
import java.util.ArrayList;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class EachTest {
@Test
public void itStillExecutesWhenThereAreNoItems() {
ArrayList<String> items = new ArrayList<>();
FakeFailingAsyncFunction<String, Void> each = new FakeFailingAsyncFunction<>(new Throwable("Failed"));
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
| Async.iterable(items) |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/examples/EachExample.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; | package org.simondean.vertx.async.unit.examples;
public class EachExample extends BaseExample {
private final boolean succeed;
private ArrayList<String> items = new ArrayList<>();
public EachExample(boolean succeed) {
this.succeed = succeed;
}
public void eachExample(AsyncResultHandler<Void> handler) {
List<String> list = Arrays.asList("one", "two", "three");
| // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/examples/EachExample.java
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
package org.simondean.vertx.async.unit.examples;
public class EachExample extends BaseExample {
private final boolean succeed;
private ArrayList<String> items = new ArrayList<>();
public EachExample(boolean succeed) {
this.succeed = succeed;
}
public void eachExample(AsyncResultHandler<Void> handler) {
List<String> list = Arrays.asList("one", "two", "three");
| Async.iterable(list) |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/examples/EachExample.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; | package org.simondean.vertx.async.unit.examples;
public class EachExample extends BaseExample {
private final boolean succeed;
private ArrayList<String> items = new ArrayList<>();
public EachExample(boolean succeed) {
this.succeed = succeed;
}
public void eachExample(AsyncResultHandler<Void> handler) {
List<String> list = Arrays.asList("one", "two", "three");
Async.iterable(list)
.each((item, eachHandler) -> {
doSomethingWithItem(item, eachHandler);
})
.run(vertx, handler);
}
private void doSomethingWithItem(String item, AsyncResultHandler<Void> handler) {
if (!succeed) { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/examples/EachExample.java
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
package org.simondean.vertx.async.unit.examples;
public class EachExample extends BaseExample {
private final boolean succeed;
private ArrayList<String> items = new ArrayList<>();
public EachExample(boolean succeed) {
this.succeed = succeed;
}
public void eachExample(AsyncResultHandler<Void> handler) {
List<String> list = Arrays.asList("one", "two", "three");
Async.iterable(list)
.each((item, eachHandler) -> {
doSomethingWithItem(item, eachHandler);
})
.run(vertx, handler);
}
private void doSomethingWithItem(String item, AsyncResultHandler<Void> handler) {
if (!succeed) { | handler.handle(DefaultAsyncResult.fail(new Exception("Fail"))); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/examples/ForeverExample.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler; | package org.simondean.vertx.async.unit.examples;
public class ForeverExample extends BaseExample {
public void foreverExample(AsyncResultHandler<String> handler) { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/examples/ForeverExample.java
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
package org.simondean.vertx.async.unit.examples;
public class ForeverExample extends BaseExample {
public void foreverExample(AsyncResultHandler<String> handler) { | Async.forever() |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/examples/ForeverExample.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler; | package org.simondean.vertx.async.unit.examples;
public class ForeverExample extends BaseExample {
public void foreverExample(AsyncResultHandler<String> handler) {
Async.forever()
.task(taskHandler -> {
someAsyncMethodThatTakesAHandler(taskHandler);
})
.run(vertx, result -> { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/examples/ForeverExample.java
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
package org.simondean.vertx.async.unit.examples;
public class ForeverExample extends BaseExample {
public void foreverExample(AsyncResultHandler<String> handler) {
Async.forever()
.task(taskHandler -> {
someAsyncMethodThatTakesAHandler(taskHandler);
})
.run(vertx, result -> { | handler.handle(DefaultAsyncResult.fail(result)); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncFunction.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult; | package org.simondean.vertx.async.unit.fakes;
public class FakeFailingAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
private final int successCount;
private final R result;
private final Throwable cause;
public FakeFailingAsyncFunction(Throwable cause) {
this(0, null, cause);
}
public FakeFailingAsyncFunction(int successCount, R result, Throwable cause) {
this.successCount = successCount;
this.result = result;
this.cause = cause;
}
@Override
public void accept(T value, AsyncResultHandler<R> handler) {
addConsumedValue(value);
incrementRunCount();
if (runCount() > successCount) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncFunction.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
package org.simondean.vertx.async.unit.fakes;
public class FakeFailingAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
private final int successCount;
private final R result;
private final Throwable cause;
public FakeFailingAsyncFunction(Throwable cause) {
this(0, null, cause);
}
public FakeFailingAsyncFunction(int successCount, R result, Throwable cause) {
this.successCount = successCount;
this.result = result;
this.cause = cause;
}
@Override
public void accept(T value, AsyncResultHandler<R> handler) {
addConsumedValue(value);
incrementRunCount();
if (runCount() > successCount) { | handler.handle(DefaultAsyncResult.fail(cause)); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult; | package org.simondean.vertx.async.unit.fakes;
public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
private final int successCount;
private final T result;
private final Throwable cause;
public FakeFailingAsyncSupplier(Throwable cause) {
this(0, null, cause);
}
public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
this.successCount = successCount;
this.result = result;
this.cause = cause;
}
@Override
public void accept(AsyncResultHandler<T> handler) {
incrementRunCount();
if (runCount() > successCount) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
package org.simondean.vertx.async.unit.fakes;
public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
private final int successCount;
private final T result;
private final Throwable cause;
public FakeFailingAsyncSupplier(Throwable cause) {
this(0, null, cause);
}
public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
this.successCount = successCount;
this.result = result;
this.cause = cause;
}
@Override
public void accept(AsyncResultHandler<T> handler) {
incrementRunCount();
if (runCount() > successCount) { | handler.handle(DefaultAsyncResult.fail(cause)); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/EachExampleTest.java | // Path: src/test/java/org/simondean/vertx/async/unit/examples/EachExample.java
// public class EachExample extends BaseExample {
// private final boolean succeed;
// private ArrayList<String> items = new ArrayList<>();
//
// public EachExample(boolean succeed) {
// this.succeed = succeed;
// }
//
// public void eachExample(AsyncResultHandler<Void> handler) {
// List<String> list = Arrays.asList("one", "two", "three");
//
// Async.iterable(list)
// .each((item, eachHandler) -> {
// doSomethingWithItem(item, eachHandler);
// })
// .run(vertx, handler);
// }
//
// private void doSomethingWithItem(String item, AsyncResultHandler<Void> handler) {
// if (!succeed) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// return;
// }
//
// items.add(item);
// handler.handle(DefaultAsyncResult.succeed());
// }
//
// public List<String> items() {
// return items;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/examples/SeriesExample.java
// public class SeriesExample extends BaseExample {
// private final boolean succeed;
// private List<String> results;
//
// public SeriesExample(boolean succeed) {
// this.succeed = succeed;
// }
//
// public void seriesExample(AsyncResultHandler<List<String>> handler) {
// Async.<String>series()
// .task(taskHandler -> {
// String result = getSomeResult();
// taskHandler.handle(DefaultAsyncResult.succeed(result));
// })
// .task(taskHandler -> {
// someAsyncMethodThatTakesAHandler(taskHandler);
// })
// .run(result -> {
// if (result.failed()) {
// handler.handle(DefaultAsyncResult.fail(result));
// return;
// }
//
// List<String> resultList = result.result();
// doSomethingWithTheResults(resultList);
//
// handler.handle(DefaultAsyncResult.succeed(resultList));
// });
// }
//
// private String getSomeResult() {
// return "Result";
// }
//
// private void someAsyncMethodThatTakesAHandler(AsyncResultHandler<String> handler) {
// if (!succeed) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// return;
// }
//
// handler.handle(DefaultAsyncResult.succeed("Async result"));
// }
//
// private void doSomethingWithTheResults(List<String> results) {
// this.results = results;
// }
//
// public List<String> results() {
// return results;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.unit.examples.EachExample;
import org.simondean.vertx.async.unit.examples.SeriesExample;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class EachExampleTest {
@Test
public void itHandlesSuccess() { | // Path: src/test/java/org/simondean/vertx/async/unit/examples/EachExample.java
// public class EachExample extends BaseExample {
// private final boolean succeed;
// private ArrayList<String> items = new ArrayList<>();
//
// public EachExample(boolean succeed) {
// this.succeed = succeed;
// }
//
// public void eachExample(AsyncResultHandler<Void> handler) {
// List<String> list = Arrays.asList("one", "two", "three");
//
// Async.iterable(list)
// .each((item, eachHandler) -> {
// doSomethingWithItem(item, eachHandler);
// })
// .run(vertx, handler);
// }
//
// private void doSomethingWithItem(String item, AsyncResultHandler<Void> handler) {
// if (!succeed) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// return;
// }
//
// items.add(item);
// handler.handle(DefaultAsyncResult.succeed());
// }
//
// public List<String> items() {
// return items;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/examples/SeriesExample.java
// public class SeriesExample extends BaseExample {
// private final boolean succeed;
// private List<String> results;
//
// public SeriesExample(boolean succeed) {
// this.succeed = succeed;
// }
//
// public void seriesExample(AsyncResultHandler<List<String>> handler) {
// Async.<String>series()
// .task(taskHandler -> {
// String result = getSomeResult();
// taskHandler.handle(DefaultAsyncResult.succeed(result));
// })
// .task(taskHandler -> {
// someAsyncMethodThatTakesAHandler(taskHandler);
// })
// .run(result -> {
// if (result.failed()) {
// handler.handle(DefaultAsyncResult.fail(result));
// return;
// }
//
// List<String> resultList = result.result();
// doSomethingWithTheResults(resultList);
//
// handler.handle(DefaultAsyncResult.succeed(resultList));
// });
// }
//
// private String getSomeResult() {
// return "Result";
// }
//
// private void someAsyncMethodThatTakesAHandler(AsyncResultHandler<String> handler) {
// if (!succeed) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// return;
// }
//
// handler.handle(DefaultAsyncResult.succeed("Async result"));
// }
//
// private void doSomethingWithTheResults(List<String> results) {
// this.results = results;
// }
//
// public List<String> results() {
// return results;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/EachExampleTest.java
import org.junit.Test;
import org.simondean.vertx.async.unit.examples.EachExample;
import org.simondean.vertx.async.unit.examples.SeriesExample;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class EachExampleTest {
@Test
public void itHandlesSuccess() { | EachExample example = new EachExample(true); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/SeriesImpl.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Series.java
// public interface Series<T> {
// Series<T> task(Consumer<AsyncResultHandler<T>> task);
//
// void run(AsyncResultHandler<List<T>> handler);
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.FunctionWrapper;
import org.simondean.vertx.async.Series;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer; |
package org.simondean.vertx.async.internal;
public class SeriesImpl<T> implements Series<T> {
private ArrayList<Consumer<AsyncResultHandler<T>>> tasks = new ArrayList<>();
@Override
public Series<T> task(Consumer<AsyncResultHandler<T>> task) {
tasks.add(task);
return this;
}
@Override
public void run(AsyncResultHandler<List<T>> handler) {
Iterator<Consumer<AsyncResultHandler<T>>> iterator = tasks.iterator();
List<T> results = new ArrayList<>();
| // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Series.java
// public interface Series<T> {
// Series<T> task(Consumer<AsyncResultHandler<T>> task);
//
// void run(AsyncResultHandler<List<T>> handler);
// }
// Path: src/main/java/org/simondean/vertx/async/internal/SeriesImpl.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.FunctionWrapper;
import org.simondean.vertx.async.Series;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
package org.simondean.vertx.async.internal;
public class SeriesImpl<T> implements Series<T> {
private ArrayList<Consumer<AsyncResultHandler<T>>> tasks = new ArrayList<>();
@Override
public Series<T> task(Consumer<AsyncResultHandler<T>> task) {
tasks.add(task);
return this;
}
@Override
public void run(AsyncResultHandler<List<T>> handler) {
Iterator<Consumer<AsyncResultHandler<T>>> iterator = tasks.iterator();
List<T> results = new ArrayList<>();
| FunctionWrapper<Runnable> visitor = new FunctionWrapper<>(); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/SeriesImpl.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Series.java
// public interface Series<T> {
// Series<T> task(Consumer<AsyncResultHandler<T>> task);
//
// void run(AsyncResultHandler<List<T>> handler);
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.FunctionWrapper;
import org.simondean.vertx.async.Series;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer; |
package org.simondean.vertx.async.internal;
public class SeriesImpl<T> implements Series<T> {
private ArrayList<Consumer<AsyncResultHandler<T>>> tasks = new ArrayList<>();
@Override
public Series<T> task(Consumer<AsyncResultHandler<T>> task) {
tasks.add(task);
return this;
}
@Override
public void run(AsyncResultHandler<List<T>> handler) {
Iterator<Consumer<AsyncResultHandler<T>>> iterator = tasks.iterator();
List<T> results = new ArrayList<>();
FunctionWrapper<Runnable> visitor = new FunctionWrapper<>();
visitor.wrap(() -> {
if (!iterator.hasNext()) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Series.java
// public interface Series<T> {
// Series<T> task(Consumer<AsyncResultHandler<T>> task);
//
// void run(AsyncResultHandler<List<T>> handler);
// }
// Path: src/main/java/org/simondean/vertx/async/internal/SeriesImpl.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.FunctionWrapper;
import org.simondean.vertx.async.Series;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
package org.simondean.vertx.async.internal;
public class SeriesImpl<T> implements Series<T> {
private ArrayList<Consumer<AsyncResultHandler<T>>> tasks = new ArrayList<>();
@Override
public Series<T> task(Consumer<AsyncResultHandler<T>> task) {
tasks.add(task);
return this;
}
@Override
public void run(AsyncResultHandler<List<T>> handler) {
Iterator<Consumer<AsyncResultHandler<T>>> iterator = tasks.iterator();
List<T> results = new ArrayList<>();
FunctionWrapper<Runnable> visitor = new FunctionWrapper<>();
visitor.wrap(() -> {
if (!iterator.hasNext()) { | handler.handle(DefaultAsyncResult.succeed(results)); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/RetryTimesBuilderImpl.java | // Path: src/main/java/org/simondean/vertx/async/Retry.java
// public interface Retry<T> {
// void run(AsyncResultHandler<T> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/RetryTimesBuilder.java
// public interface RetryTimesBuilder<T> {
// Retry<T> times(int times);
// }
| import org.simondean.vertx.async.Retry;
import org.simondean.vertx.async.RetryTimesBuilder;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer; | package org.simondean.vertx.async.internal;
public class RetryTimesBuilderImpl<T> implements RetryTimesBuilder<T> {
private final Consumer<AsyncResultHandler<T>> task;
public RetryTimesBuilderImpl(Consumer<AsyncResultHandler<T>> task) {
this.task = task;
}
@Override | // Path: src/main/java/org/simondean/vertx/async/Retry.java
// public interface Retry<T> {
// void run(AsyncResultHandler<T> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/RetryTimesBuilder.java
// public interface RetryTimesBuilder<T> {
// Retry<T> times(int times);
// }
// Path: src/main/java/org/simondean/vertx/async/internal/RetryTimesBuilderImpl.java
import org.simondean.vertx.async.Retry;
import org.simondean.vertx.async.RetryTimesBuilder;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer;
package org.simondean.vertx.async.internal;
public class RetryTimesBuilderImpl<T> implements RetryTimesBuilder<T> {
private final Consumer<AsyncResultHandler<T>> task;
public RetryTimesBuilderImpl(Consumer<AsyncResultHandler<T>> task) {
this.task = task;
}
@Override | public Retry<T> times(int times) { |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/examples/SeriesExample.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.List; | package org.simondean.vertx.async.unit.examples;
public class SeriesExample extends BaseExample {
private final boolean succeed;
private List<String> results;
public SeriesExample(boolean succeed) {
this.succeed = succeed;
}
public void seriesExample(AsyncResultHandler<List<String>> handler) { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/examples/SeriesExample.java
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.List;
package org.simondean.vertx.async.unit.examples;
public class SeriesExample extends BaseExample {
private final boolean succeed;
private List<String> results;
public SeriesExample(boolean succeed) {
this.succeed = succeed;
}
public void seriesExample(AsyncResultHandler<List<String>> handler) { | Async.<String>series() |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/examples/SeriesExample.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.List; | package org.simondean.vertx.async.unit.examples;
public class SeriesExample extends BaseExample {
private final boolean succeed;
private List<String> results;
public SeriesExample(boolean succeed) {
this.succeed = succeed;
}
public void seriesExample(AsyncResultHandler<List<String>> handler) {
Async.<String>series()
.task(taskHandler -> {
String result = getSomeResult(); | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/examples/SeriesExample.java
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
import java.util.List;
package org.simondean.vertx.async.unit.examples;
public class SeriesExample extends BaseExample {
private final boolean succeed;
private List<String> results;
public SeriesExample(boolean succeed) {
this.succeed = succeed;
}
public void seriesExample(AsyncResultHandler<List<String>> handler) {
Async.<String>series()
.task(taskHandler -> {
String result = getSomeResult(); | taskHandler.handle(DefaultAsyncResult.succeed(result)); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncFunction.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult; | package org.simondean.vertx.async.unit.fakes;
public class FakeSuccessfulAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
private final int failureCount;
private final R result;
private final Throwable cause;
public FakeSuccessfulAsyncFunction(R result) {
this(0, null, result);
}
public FakeSuccessfulAsyncFunction(int failureCount, Throwable cause, R result) {
this.failureCount = failureCount;
this.result = result;
this.cause = cause;
}
@Override
public void accept(T value, AsyncResultHandler<R> handler) {
addConsumedValue(value);
incrementRunCount();
if (runCount() > failureCount) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncFunction.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
package org.simondean.vertx.async.unit.fakes;
public class FakeSuccessfulAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
private final int failureCount;
private final R result;
private final Throwable cause;
public FakeSuccessfulAsyncFunction(R result) {
this(0, null, result);
}
public FakeSuccessfulAsyncFunction(int failureCount, Throwable cause, R result) {
this.failureCount = failureCount;
this.result = result;
this.cause = cause;
}
@Override
public void accept(T value, AsyncResultHandler<R> handler) {
addConsumedValue(value);
incrementRunCount();
if (runCount() > failureCount) { | handler.handle(DefaultAsyncResult.succeed(result)); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/ForeverBuilderImpl.java | // Path: src/main/java/org/simondean/vertx/async/Forever.java
// public interface Forever {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/ForeverBuilder.java
// public interface ForeverBuilder {
// Forever task(Consumer<AsyncResultHandler<Void>> task);
// }
| import org.simondean.vertx.async.Forever;
import org.simondean.vertx.async.ForeverBuilder;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer; | package org.simondean.vertx.async.internal;
public class ForeverBuilderImpl implements ForeverBuilder {
@Override | // Path: src/main/java/org/simondean/vertx/async/Forever.java
// public interface Forever {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/ForeverBuilder.java
// public interface ForeverBuilder {
// Forever task(Consumer<AsyncResultHandler<Void>> task);
// }
// Path: src/main/java/org/simondean/vertx/async/internal/ForeverBuilderImpl.java
import org.simondean.vertx.async.Forever;
import org.simondean.vertx.async.ForeverBuilder;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer;
package org.simondean.vertx.async.internal;
public class ForeverBuilderImpl implements ForeverBuilder {
@Override | public Forever task(Consumer<AsyncResultHandler<Void>> task) { |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/examples/BaseExample.java | // Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeVertx.java
// public class FakeVertx implements Vertx {
// @Override
// public NetServer createNetServer() {
// return null;
// }
//
// @Override
// public NetClient createNetClient() {
// return null;
// }
//
// @Override
// public HttpServer createHttpServer() {
// return null;
// }
//
// @Override
// public HttpClient createHttpClient() {
// return null;
// }
//
// @Override
// public DatagramSocket createDatagramSocket(InternetProtocolFamily internetProtocolFamily) {
// return null;
// }
//
// @Override
// public SockJSServer createSockJSServer(HttpServer httpServer) {
// return null;
// }
//
// @Override
// public FileSystem fileSystem() {
// return null;
// }
//
// @Override
// public EventBus eventBus() {
// return null;
// }
//
// @Override
// public DnsClient createDnsClient(InetSocketAddress... inetSocketAddresses) {
// return null;
// }
//
// @Override
// public SharedData sharedData() {
// return null;
// }
//
// @Override
// public long setTimer(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public long setPeriodic(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public boolean cancelTimer(long l) {
// return false;
// }
//
// @Override
// public Context currentContext() {
// return null;
// }
//
// @Override
// public void runOnContext(Handler<Void> handler) {
// handler.handle(null);
// }
//
// @Override
// public boolean isEventLoop() {
// return false;
// }
//
// @Override
// public boolean isWorker() {
// return false;
// }
//
// @Override
// public void stop() {
//
// }
// }
| import org.simondean.vertx.async.unit.fakes.FakeVertx;
import org.vertx.java.core.Vertx; | package org.simondean.vertx.async.unit.examples;
public class BaseExample {
protected Vertx vertx;
public BaseExample() { | // Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeVertx.java
// public class FakeVertx implements Vertx {
// @Override
// public NetServer createNetServer() {
// return null;
// }
//
// @Override
// public NetClient createNetClient() {
// return null;
// }
//
// @Override
// public HttpServer createHttpServer() {
// return null;
// }
//
// @Override
// public HttpClient createHttpClient() {
// return null;
// }
//
// @Override
// public DatagramSocket createDatagramSocket(InternetProtocolFamily internetProtocolFamily) {
// return null;
// }
//
// @Override
// public SockJSServer createSockJSServer(HttpServer httpServer) {
// return null;
// }
//
// @Override
// public FileSystem fileSystem() {
// return null;
// }
//
// @Override
// public EventBus eventBus() {
// return null;
// }
//
// @Override
// public DnsClient createDnsClient(InetSocketAddress... inetSocketAddresses) {
// return null;
// }
//
// @Override
// public SharedData sharedData() {
// return null;
// }
//
// @Override
// public long setTimer(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public long setPeriodic(long l, Handler<Long> handler) {
// return 0;
// }
//
// @Override
// public boolean cancelTimer(long l) {
// return false;
// }
//
// @Override
// public Context currentContext() {
// return null;
// }
//
// @Override
// public void runOnContext(Handler<Void> handler) {
// handler.handle(null);
// }
//
// @Override
// public boolean isEventLoop() {
// return false;
// }
//
// @Override
// public boolean isWorker() {
// return false;
// }
//
// @Override
// public void stop() {
//
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/examples/BaseExample.java
import org.simondean.vertx.async.unit.fakes.FakeVertx;
import org.vertx.java.core.Vertx;
package org.simondean.vertx.async.unit.examples;
public class BaseExample {
protected Vertx vertx;
public BaseExample() { | this.vertx = new FakeVertx(); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult; | package org.simondean.vertx.async.unit.fakes;
public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
private final int failureCount;
private final T result;
private final Throwable cause;
public FakeSuccessfulAsyncSupplier(T result) {
this(0, null, result);
}
public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
this.failureCount = failureCount;
this.result = result;
this.cause = cause;
}
@Override
public void accept(AsyncResultHandler<T> handler) {
incrementRunCount();
if (runCount() > failureCount) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
package org.simondean.vertx.async.unit.fakes;
public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
private final int failureCount;
private final T result;
private final Throwable cause;
public FakeSuccessfulAsyncSupplier(T result) {
this(0, null, result);
}
public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
this.failureCount = failureCount;
this.result = result;
this.cause = cause;
}
@Override
public void accept(AsyncResultHandler<T> handler) {
incrementRunCount();
if (runCount() > failureCount) { | handler.handle(DefaultAsyncResult.succeed(result)); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/WaterfallBuilderImpl.java | // Path: src/main/java/org/simondean/vertx/async/WaterfallBuilder.java
// public interface WaterfallBuilder {
// public <R> Waterfall<R> task(Consumer<AsyncResultHandler<R>> task);
// }
//
// Path: src/main/java/org/simondean/vertx/async/Waterfall.java
// public interface Waterfall<T> {
// public <R> Waterfall<R> task(BiConsumer<T, AsyncResultHandler<R>> task);
//
// public void run(AsyncResultHandler<T> handler);
// }
| import org.simondean.vertx.async.WaterfallBuilder;
import org.simondean.vertx.async.Waterfall;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer; | package org.simondean.vertx.async.internal;
public class WaterfallBuilderImpl implements WaterfallBuilder {
@Override | // Path: src/main/java/org/simondean/vertx/async/WaterfallBuilder.java
// public interface WaterfallBuilder {
// public <R> Waterfall<R> task(Consumer<AsyncResultHandler<R>> task);
// }
//
// Path: src/main/java/org/simondean/vertx/async/Waterfall.java
// public interface Waterfall<T> {
// public <R> Waterfall<R> task(BiConsumer<T, AsyncResultHandler<R>> task);
//
// public void run(AsyncResultHandler<T> handler);
// }
// Path: src/main/java/org/simondean/vertx/async/internal/WaterfallBuilderImpl.java
import org.simondean.vertx.async.WaterfallBuilder;
import org.simondean.vertx.async.Waterfall;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer;
package org.simondean.vertx.async.internal;
public class WaterfallBuilderImpl implements WaterfallBuilder {
@Override | public <T> Waterfall<T> task(Consumer<AsyncResultHandler<T>> task) { |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/RetryExampleTest.java | // Path: src/test/java/org/simondean/vertx/async/unit/examples/RetryExample.java
// public class RetryExample extends BaseExample {
// private final boolean succeed;
// private String result;
//
// public RetryExample(boolean succeed) {
// this.succeed = succeed;
// }
//
// public void retryExample(AsyncResultHandler<String> handler) {
// Async.retry()
// .<String>task(taskHandler -> {
// someAsyncMethodThatTakesAHandler(taskHandler);
// })
// .times(5)
// .run(result -> {
// if (result.failed()) {
// handler.handle(DefaultAsyncResult.fail(result));
// return;
// }
//
// String resultValue = result.result();
//
// doSomethingWithTheResults(resultValue);
//
// handler.handle(DefaultAsyncResult.succeed(resultValue));
// });
// }
//
// private void someAsyncMethodThatTakesAHandler(AsyncResultHandler<String> handler) {
// if (!succeed) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// return;
// }
//
// handler.handle(DefaultAsyncResult.succeed("Async result"));
// }
//
// private void doSomethingWithTheResults(String result) {
// this.result = result;
// }
//
// public String result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.unit.examples.RetryExample;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class RetryExampleTest {
@Test
public void itHandlesSuccess() { | // Path: src/test/java/org/simondean/vertx/async/unit/examples/RetryExample.java
// public class RetryExample extends BaseExample {
// private final boolean succeed;
// private String result;
//
// public RetryExample(boolean succeed) {
// this.succeed = succeed;
// }
//
// public void retryExample(AsyncResultHandler<String> handler) {
// Async.retry()
// .<String>task(taskHandler -> {
// someAsyncMethodThatTakesAHandler(taskHandler);
// })
// .times(5)
// .run(result -> {
// if (result.failed()) {
// handler.handle(DefaultAsyncResult.fail(result));
// return;
// }
//
// String resultValue = result.result();
//
// doSomethingWithTheResults(resultValue);
//
// handler.handle(DefaultAsyncResult.succeed(resultValue));
// });
// }
//
// private void someAsyncMethodThatTakesAHandler(AsyncResultHandler<String> handler) {
// if (!succeed) {
// handler.handle(DefaultAsyncResult.fail(new Exception("Fail")));
// return;
// }
//
// handler.handle(DefaultAsyncResult.succeed("Async result"));
// }
//
// private void doSomethingWithTheResults(String result) {
// this.result = result;
// }
//
// public String result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/RetryExampleTest.java
import org.junit.Test;
import org.simondean.vertx.async.unit.examples.RetryExample;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class RetryExampleTest {
@Test
public void itHandlesSuccess() { | RetryExample example = new RetryExample(true); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/NestedWaterfall.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Waterfall.java
// public interface Waterfall<T> {
// public <R> Waterfall<R> task(BiConsumer<T, AsyncResultHandler<R>> task);
//
// public void run(AsyncResultHandler<T> handler);
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.Waterfall;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.BiConsumer; | package org.simondean.vertx.async.internal;
public class NestedWaterfall<T, R> implements Waterfall<R> {
private final Waterfall<T> parentWaterfall;
private BiConsumer<T, AsyncResultHandler<R>> task;
public NestedWaterfall(Waterfall<T> parentWaterfall, BiConsumer<T, AsyncResultHandler<R>> task) {
this.parentWaterfall = parentWaterfall;
this.task = task;
}
@Override
public <S> Waterfall<S> task(BiConsumer<R, AsyncResultHandler<S>> task) {
return new NestedWaterfall<>(this, task);
}
@Override
public void run(AsyncResultHandler<R> handler) {
parentWaterfall.run(result -> {
if (result.failed()) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Waterfall.java
// public interface Waterfall<T> {
// public <R> Waterfall<R> task(BiConsumer<T, AsyncResultHandler<R>> task);
//
// public void run(AsyncResultHandler<T> handler);
// }
// Path: src/main/java/org/simondean/vertx/async/internal/NestedWaterfall.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.Waterfall;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.BiConsumer;
package org.simondean.vertx.async.internal;
public class NestedWaterfall<T, R> implements Waterfall<R> {
private final Waterfall<T> parentWaterfall;
private BiConsumer<T, AsyncResultHandler<R>> task;
public NestedWaterfall(Waterfall<T> parentWaterfall, BiConsumer<T, AsyncResultHandler<R>> task) {
this.parentWaterfall = parentWaterfall;
this.task = task;
}
@Override
public <S> Waterfall<S> task(BiConsumer<R, AsyncResultHandler<S>> task) {
return new NestedWaterfall<>(this, task);
}
@Override
public void run(AsyncResultHandler<R> handler) {
parentWaterfall.run(result -> {
if (result.failed()) { | handler.handle(DefaultAsyncResult.fail(result)); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/RetryBuilderImpl.java | // Path: src/main/java/org/simondean/vertx/async/RetryBuilder.java
// public interface RetryBuilder {
// <T> RetryTimesBuilder<T> task(Consumer<AsyncResultHandler<T>> task);
// }
//
// Path: src/main/java/org/simondean/vertx/async/RetryTimesBuilder.java
// public interface RetryTimesBuilder<T> {
// Retry<T> times(int times);
// }
| import org.simondean.vertx.async.RetryBuilder;
import org.simondean.vertx.async.RetryTimesBuilder;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer; | package org.simondean.vertx.async.internal;
public class RetryBuilderImpl implements RetryBuilder {
@Override | // Path: src/main/java/org/simondean/vertx/async/RetryBuilder.java
// public interface RetryBuilder {
// <T> RetryTimesBuilder<T> task(Consumer<AsyncResultHandler<T>> task);
// }
//
// Path: src/main/java/org/simondean/vertx/async/RetryTimesBuilder.java
// public interface RetryTimesBuilder<T> {
// Retry<T> times(int times);
// }
// Path: src/main/java/org/simondean/vertx/async/internal/RetryBuilderImpl.java
import org.simondean.vertx.async.RetryBuilder;
import org.simondean.vertx.async.RetryTimesBuilder;
import org.vertx.java.core.AsyncResultHandler;
import java.util.function.Consumer;
package org.simondean.vertx.async.internal;
public class RetryBuilderImpl implements RetryBuilder {
@Override | public <T> RetryTimesBuilder<T> task(Consumer<AsyncResultHandler<T>> task) { |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/RetryTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class RetryTest {
@Test
public void itExecutesTheTask() { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/RetryTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class RetryTest {
@Test
public void itExecutesTheTask() { | FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1"); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/RetryTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class RetryTest {
@Test
public void itExecutesTheTask() {
FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1");
| // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/RetryTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class RetryTest {
@Test
public void itExecutesTheTask() {
FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1");
| ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0); |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/RetryTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat; | package org.simondean.vertx.async.unit;
public class RetryTest {
@Test
public void itExecutesTheTask() {
FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1");
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
| // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/RetryTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat;
package org.simondean.vertx.async.unit;
public class RetryTest {
@Test
public void itExecutesTheTask() {
FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>("Task 1");
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
| Async.retry() |
simondean/vertx-async | src/test/java/org/simondean/vertx/async/unit/RetryTest.java | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
| import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat; | });
assertThat(handlerCallCount.getObject()).isEqualTo(1);
}
@Test
public void itExecutesTheTaskAgainAfterASecondFailure() {
FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>(2, new Throwable("Failed"), "Task 1");
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
Async.retry()
.task(task1)
.times(2)
.run(result -> {
handlerCallCount.setObject(handlerCallCount.getObject() + 1);
assertThat(task1.runCount()).isEqualTo(3);
assertThat(result).isNotNull();
assertThat(result.succeeded()).isTrue();
String resultValue = result.result();
assertThat(resultValue).isNotNull();
assertThat(resultValue).isEqualTo(task1.result());
});
assertThat(handlerCallCount.getObject()).isEqualTo(1);
}
@Test
public void itFailsAfterTheRetryTimes() { | // Path: src/main/java/org/simondean/vertx/async/Async.java
// public final class Async {
// private Async() {}
//
// public static <T> Series<T> series() {
// return new SeriesImpl<>();
// }
//
// public static WaterfallBuilder waterfall() {
// return new WaterfallBuilderImpl();
// }
//
// public static <T> IterableBuilder<T> iterable(Iterable<T> iterable) {
// return new IterableBuilderImpl(iterable);
// }
//
// public static RetryBuilder retry() {
// return new RetryBuilderImpl();
// }
//
// public static ForeverBuilder forever() {
// return new ForeverBuilderImpl();
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncSupplier.java
// public class FakeFailingAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int successCount;
// private final T result;
// private final Throwable cause;
//
// public FakeFailingAsyncSupplier(Throwable cause) {
// this(0, null, cause);
// }
//
// public FakeFailingAsyncSupplier(int successCount, T result, Throwable cause) {
// this.successCount = successCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > successCount) {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// else {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// }
//
// public Throwable cause() {
// return cause;
// }
// }
//
// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeSuccessfulAsyncSupplier.java
// public class FakeSuccessfulAsyncSupplier<T> extends FakeAsyncSupplier<T> {
// private final int failureCount;
// private final T result;
// private final Throwable cause;
//
// public FakeSuccessfulAsyncSupplier(T result) {
// this(0, null, result);
// }
//
// public FakeSuccessfulAsyncSupplier(int failureCount, Throwable cause, T result) {
// this.failureCount = failureCount;
// this.result = result;
// this.cause = cause;
// }
//
// @Override
// public void accept(AsyncResultHandler<T> handler) {
// incrementRunCount();
//
// if (runCount() > failureCount) {
// handler.handle(DefaultAsyncResult.succeed(result));
// }
// else {
// handler.handle(DefaultAsyncResult.fail(cause));
// }
// }
//
// public T result() {
// return result;
// }
// }
// Path: src/test/java/org/simondean/vertx/async/unit/RetryTest.java
import org.junit.Test;
import org.simondean.vertx.async.Async;
import org.simondean.vertx.async.ObjectWrapper;
import org.simondean.vertx.async.unit.fakes.FakeFailingAsyncSupplier;
import org.simondean.vertx.async.unit.fakes.FakeSuccessfulAsyncSupplier;
import static org.assertj.core.api.Assertions.assertThat;
});
assertThat(handlerCallCount.getObject()).isEqualTo(1);
}
@Test
public void itExecutesTheTaskAgainAfterASecondFailure() {
FakeSuccessfulAsyncSupplier<String> task1 = new FakeSuccessfulAsyncSupplier<>(2, new Throwable("Failed"), "Task 1");
ObjectWrapper<Integer> handlerCallCount = new ObjectWrapper<>(0);
Async.retry()
.task(task1)
.times(2)
.run(result -> {
handlerCallCount.setObject(handlerCallCount.getObject() + 1);
assertThat(task1.runCount()).isEqualTo(3);
assertThat(result).isNotNull();
assertThat(result.succeeded()).isTrue();
String resultValue = result.result();
assertThat(resultValue).isNotNull();
assertThat(resultValue).isEqualTo(task1.result());
});
assertThat(handlerCallCount.getObject()).isEqualTo(1);
}
@Test
public void itFailsAfterTheRetryTimes() { | FakeFailingAsyncSupplier<String> task1 = new FakeFailingAsyncSupplier<>(new Throwable("Failed")); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/EachBuilderImpl.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/EachBuilder.java
// public interface EachBuilder {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.EachBuilder;
import org.simondean.vertx.async.ObjectWrapper;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.Vertx;
import java.util.ArrayList;
import java.util.function.BiConsumer; | package org.simondean.vertx.async.internal;
public class EachBuilderImpl<T> implements EachBuilder {
private final Iterable<T> iterable;
private final BiConsumer<T, AsyncResultHandler<Void>> each;
public EachBuilderImpl(Iterable<T> iterable, BiConsumer<T, AsyncResultHandler<Void>> each) {
this.iterable = iterable;
this.each = each;
}
@Override
public void run(Vertx vertx, AsyncResultHandler<Void> handler) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/EachBuilder.java
// public interface EachBuilder {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
// Path: src/main/java/org/simondean/vertx/async/internal/EachBuilderImpl.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.EachBuilder;
import org.simondean.vertx.async.ObjectWrapper;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.Vertx;
import java.util.ArrayList;
import java.util.function.BiConsumer;
package org.simondean.vertx.async.internal;
public class EachBuilderImpl<T> implements EachBuilder {
private final Iterable<T> iterable;
private final BiConsumer<T, AsyncResultHandler<Void>> each;
public EachBuilderImpl(Iterable<T> iterable, BiConsumer<T, AsyncResultHandler<Void>> each) {
this.iterable = iterable;
this.each = each;
}
@Override
public void run(Vertx vertx, AsyncResultHandler<Void> handler) { | final ObjectWrapper<Boolean> failed = new ObjectWrapper<>(false); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/EachBuilderImpl.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/EachBuilder.java
// public interface EachBuilder {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.EachBuilder;
import org.simondean.vertx.async.ObjectWrapper;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.Vertx;
import java.util.ArrayList;
import java.util.function.BiConsumer; | package org.simondean.vertx.async.internal;
public class EachBuilderImpl<T> implements EachBuilder {
private final Iterable<T> iterable;
private final BiConsumer<T, AsyncResultHandler<Void>> each;
public EachBuilderImpl(Iterable<T> iterable, BiConsumer<T, AsyncResultHandler<Void>> each) {
this.iterable = iterable;
this.each = each;
}
@Override
public void run(Vertx vertx, AsyncResultHandler<Void> handler) {
final ObjectWrapper<Boolean> failed = new ObjectWrapper<>(false);
final ObjectWrapper<Integer> finishedCount = new ObjectWrapper<>(0);
ArrayList<T> items = new ArrayList<T>();
for (T item : iterable) {
items.add(item);
}
if (items.size() == 0) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/EachBuilder.java
// public interface EachBuilder {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/ObjectWrapper.java
// public class ObjectWrapper<T> {
// private T object;
//
// public ObjectWrapper() {
// }
//
// public ObjectWrapper(T object) {
// this.object = object;
// }
//
// public void setObject(T object) {
// this.object = object;
// }
//
// public T getObject() {
// return object;
// }
// }
// Path: src/main/java/org/simondean/vertx/async/internal/EachBuilderImpl.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.EachBuilder;
import org.simondean.vertx.async.ObjectWrapper;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.Vertx;
import java.util.ArrayList;
import java.util.function.BiConsumer;
package org.simondean.vertx.async.internal;
public class EachBuilderImpl<T> implements EachBuilder {
private final Iterable<T> iterable;
private final BiConsumer<T, AsyncResultHandler<Void>> each;
public EachBuilderImpl(Iterable<T> iterable, BiConsumer<T, AsyncResultHandler<Void>> each) {
this.iterable = iterable;
this.each = each;
}
@Override
public void run(Vertx vertx, AsyncResultHandler<Void> handler) {
final ObjectWrapper<Boolean> failed = new ObjectWrapper<>(false);
final ObjectWrapper<Integer> finishedCount = new ObjectWrapper<>(0);
ArrayList<T> items = new ArrayList<T>();
for (T item : iterable) {
items.add(item);
}
if (items.size() == 0) { | handler.handle(DefaultAsyncResult.succeed()); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/ForeverImpl.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Forever.java
// public interface Forever {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.Forever;
import org.simondean.vertx.async.FunctionWrapper;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.Vertx;
import java.util.function.Consumer; | package org.simondean.vertx.async.internal;
public class ForeverImpl implements Forever {
private final Consumer<AsyncResultHandler<Void>> task;
public ForeverImpl(Consumer<AsyncResultHandler<Void>> task) {
this.task = task;
}
@Override
public void run(Vertx vertx, AsyncResultHandler<Void> handler) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Forever.java
// public interface Forever {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
// Path: src/main/java/org/simondean/vertx/async/internal/ForeverImpl.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.Forever;
import org.simondean.vertx.async.FunctionWrapper;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.Vertx;
import java.util.function.Consumer;
package org.simondean.vertx.async.internal;
public class ForeverImpl implements Forever {
private final Consumer<AsyncResultHandler<Void>> task;
public ForeverImpl(Consumer<AsyncResultHandler<Void>> task) {
this.task = task;
}
@Override
public void run(Vertx vertx, AsyncResultHandler<Void> handler) { | FunctionWrapper<Runnable> visitor = new FunctionWrapper<>(); |
simondean/vertx-async | src/main/java/org/simondean/vertx/async/internal/ForeverImpl.java | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Forever.java
// public interface Forever {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
| import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.Forever;
import org.simondean.vertx.async.FunctionWrapper;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.Vertx;
import java.util.function.Consumer; | package org.simondean.vertx.async.internal;
public class ForeverImpl implements Forever {
private final Consumer<AsyncResultHandler<Void>> task;
public ForeverImpl(Consumer<AsyncResultHandler<Void>> task) {
this.task = task;
}
@Override
public void run(Vertx vertx, AsyncResultHandler<Void> handler) {
FunctionWrapper<Runnable> visitor = new FunctionWrapper<>();
visitor.wrap(() -> task.accept(result -> {
if (result.failed()) { | // Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
// private Throwable cause;
// private T result;
//
// public DefaultAsyncResult(Throwable cause, T result) {
// this.cause = cause;
// this.result = result;
// }
//
// public static <T> AsyncResult<T> succeed(T result) {
// return new DefaultAsyncResult<>(null, result);
// }
//
// public static AsyncResult<Void> succeed() {
// return succeed(null);
// }
//
// public static <T> AsyncResult<T> fail(Throwable cause) {
// if (cause == null) {
// throw new IllegalArgumentException("cause argument cannot be null");
// }
//
// return new DefaultAsyncResult<>(cause, null);
// }
//
// public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
// return fail(result.cause());
// }
//
// @Override
// public T result() {
// return result;
// }
//
// @Override
// public Throwable cause() {
// return cause;
// }
//
// @Override
// public boolean succeeded() {
// return cause == null;
// }
//
// @Override
// public boolean failed() {
// return cause != null;
// }
// }
//
// Path: src/main/java/org/simondean/vertx/async/Forever.java
// public interface Forever {
// void run(Vertx vertx, AsyncResultHandler<Void> handler);
// }
//
// Path: src/main/java/org/simondean/vertx/async/FunctionWrapper.java
// public class FunctionWrapper<T> {
// private T f;
//
// public void wrap(T f) {
// this.f = f;
// }
//
// public T f() {
// return f;
// }
// }
// Path: src/main/java/org/simondean/vertx/async/internal/ForeverImpl.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.simondean.vertx.async.Forever;
import org.simondean.vertx.async.FunctionWrapper;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.Vertx;
import java.util.function.Consumer;
package org.simondean.vertx.async.internal;
public class ForeverImpl implements Forever {
private final Consumer<AsyncResultHandler<Void>> task;
public ForeverImpl(Consumer<AsyncResultHandler<Void>> task) {
this.task = task;
}
@Override
public void run(Vertx vertx, AsyncResultHandler<Void> handler) {
FunctionWrapper<Runnable> visitor = new FunctionWrapper<>();
visitor.wrap(() -> task.accept(result -> {
if (result.failed()) { | handler.handle(DefaultAsyncResult.fail(result)); |
EasyPost/easypost-java | src/test/java/com/easypost/UserTest.java | // Path: src/main/java/com/easypost/exception/EasyPostException.java
// public class EasyPostException extends Exception {
//
// private static final long serialVersionUID = 1L;
// private final String param;
//
// /**
// * Constructor.
// *
// * @param message the exception message
// */
// public EasyPostException(final String message) {
// super(message, null);
// this.param = null;
// }
//
// /**
// * Constructor.
// *
// * @param message the exception message
// * @param ex the exception cause
// */
// public EasyPostException(final String message, final Throwable ex) {
// super(message, ex);
// this.param = null;
// }
//
// /**
// * Constructor.
// *
// * @param message the exception message
// * @param param the parameter name
// * @param ex the exception cause
// */
// public EasyPostException(final String message, final String param, final Throwable ex) {
// super(message, ex);
// this.param = param;
// }
//
// /**
// * Get the parameter name.
// *
// * @return the parameter name
// */
// public String getParam() {
// return param;
// }
// }
| import com.easypost.model.*;
import java.util.HashMap;
import java.util.Map;
import com.easypost.exception.EasyPostException;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeAll;
import static org.junit.jupiter.api.Assertions.*; | package com.easypost;
public class UserTest {
private static User globalUser;
/**
* Setup the testing environment for this file.
*
* @throws EasyPostException when the request fails.
*/
@BeforeAll | // Path: src/main/java/com/easypost/exception/EasyPostException.java
// public class EasyPostException extends Exception {
//
// private static final long serialVersionUID = 1L;
// private final String param;
//
// /**
// * Constructor.
// *
// * @param message the exception message
// */
// public EasyPostException(final String message) {
// super(message, null);
// this.param = null;
// }
//
// /**
// * Constructor.
// *
// * @param message the exception message
// * @param ex the exception cause
// */
// public EasyPostException(final String message, final Throwable ex) {
// super(message, ex);
// this.param = null;
// }
//
// /**
// * Constructor.
// *
// * @param message the exception message
// * @param param the parameter name
// * @param ex the exception cause
// */
// public EasyPostException(final String message, final String param, final Throwable ex) {
// super(message, ex);
// this.param = param;
// }
//
// /**
// * Get the parameter name.
// *
// * @return the parameter name
// */
// public String getParam() {
// return param;
// }
// }
// Path: src/test/java/com/easypost/UserTest.java
import com.easypost.model.*;
import java.util.HashMap;
import java.util.Map;
import com.easypost.exception.EasyPostException;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeAll;
import static org.junit.jupiter.api.Assertions.*;
package com.easypost;
public class UserTest {
private static User globalUser;
/**
* Setup the testing environment for this file.
*
* @throws EasyPostException when the request fails.
*/
@BeforeAll | public static void setUp() throws EasyPostException{ |
ggeorgovassilis/spring-rest-invoker | src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/MappingAnnotationsInspector.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MappingDeclarationException.java
// public class MappingDeclarationException extends RuntimeException {
// protected Method method;
// protected Annotation annotation;
// protected int parameterIndex;
//
// public MappingDeclarationException(String message, Method method, Annotation annotation, int parameterIndex) {
// super(message);
// this.method = method;
// this.annotation = annotation;
// this.parameterIndex = parameterIndex;
// }
//
// public MappingDeclarationException(String message, Method method, Throwable throwable) {
// super(message, throwable);
// this.method = method;
// }
//
// public MappingDeclarationException(String message, Method method) {
// super(message);
// this.method = method;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/MappingAnnotationResolver.java
// public interface MappingAnnotationResolver<T extends Annotation> {
// UrlMapping resolve(T mappingAnnotation);
//
// boolean supported(Class<T> annotation);
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.MappingDeclarationException;
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import com.github.ggeorgovassilis.springjsonmapper.spring.mapping.MappingAnnotationResolver;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.web.bind.annotation.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream; | package com.github.ggeorgovassilis.springjsonmapper.spring;
/**
* Looks at class and method and extract mapping annotations such as
* {@link DeleteMapping}, {@link GetMapping}, {@link PatchMapping}, {@link PostMapping},
* {@link PutMapping}, {@link RequestMapping}
* <p>
* In case if annotation exists on both levels it will be merged following the spring-web rules
*
* @author minasgull
*/
public class MappingAnnotationsInspector extends BaseAnnotationMethodInspector {
private final List<MappingAnnotationResolver<? extends Annotation>> mappingAnnotationResolvers;
public MappingAnnotationsInspector(List<MappingAnnotationResolver<? extends Annotation>> mappingAnnotationResolvers) {
this.mappingAnnotationResolvers = mappingAnnotationResolvers;
}
@Override | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MappingDeclarationException.java
// public class MappingDeclarationException extends RuntimeException {
// protected Method method;
// protected Annotation annotation;
// protected int parameterIndex;
//
// public MappingDeclarationException(String message, Method method, Annotation annotation, int parameterIndex) {
// super(message);
// this.method = method;
// this.annotation = annotation;
// this.parameterIndex = parameterIndex;
// }
//
// public MappingDeclarationException(String message, Method method, Throwable throwable) {
// super(message, throwable);
// this.method = method;
// }
//
// public MappingDeclarationException(String message, Method method) {
// super(message);
// this.method = method;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/MappingAnnotationResolver.java
// public interface MappingAnnotationResolver<T extends Annotation> {
// UrlMapping resolve(T mappingAnnotation);
//
// boolean supported(Class<T> annotation);
// }
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/MappingAnnotationsInspector.java
import com.github.ggeorgovassilis.springjsonmapper.model.MappingDeclarationException;
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import com.github.ggeorgovassilis.springjsonmapper.spring.mapping.MappingAnnotationResolver;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.web.bind.annotation.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
package com.github.ggeorgovassilis.springjsonmapper.spring;
/**
* Looks at class and method and extract mapping annotations such as
* {@link DeleteMapping}, {@link GetMapping}, {@link PatchMapping}, {@link PostMapping},
* {@link PutMapping}, {@link RequestMapping}
* <p>
* In case if annotation exists on both levels it will be merged following the spring-web rules
*
* @author minasgull
*/
public class MappingAnnotationsInspector extends BaseAnnotationMethodInspector {
private final List<MappingAnnotationResolver<? extends Annotation>> mappingAnnotationResolvers;
public MappingAnnotationsInspector(List<MappingAnnotationResolver<? extends Annotation>> mappingAnnotationResolvers) {
this.mappingAnnotationResolvers = mappingAnnotationResolvers;
}
@Override | public UrlMapping inspect(Method method, Object[] args) { |
ggeorgovassilis/spring-rest-invoker | src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/MappingAnnotationsInspector.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MappingDeclarationException.java
// public class MappingDeclarationException extends RuntimeException {
// protected Method method;
// protected Annotation annotation;
// protected int parameterIndex;
//
// public MappingDeclarationException(String message, Method method, Annotation annotation, int parameterIndex) {
// super(message);
// this.method = method;
// this.annotation = annotation;
// this.parameterIndex = parameterIndex;
// }
//
// public MappingDeclarationException(String message, Method method, Throwable throwable) {
// super(message, throwable);
// this.method = method;
// }
//
// public MappingDeclarationException(String message, Method method) {
// super(message);
// this.method = method;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/MappingAnnotationResolver.java
// public interface MappingAnnotationResolver<T extends Annotation> {
// UrlMapping resolve(T mappingAnnotation);
//
// boolean supported(Class<T> annotation);
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.MappingDeclarationException;
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import com.github.ggeorgovassilis.springjsonmapper.spring.mapping.MappingAnnotationResolver;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.web.bind.annotation.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream; | }
if (methodUrlMapping.getProduces().length == 0) {
methodUrlMapping.setProduces(classUrlMapping.getProduces());
}
if (methodUrlMapping.getHeaders().length == 0) {
methodUrlMapping.setHeaders(classUrlMapping.getHeaders());
}
return methodUrlMapping;
}
private UrlMapping resolveFor(AnnotatedElement annotatedElement) {
return Stream.of(
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, RequestMapping.class),
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, GetMapping.class),
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, PostMapping.class),
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, PutMapping.class),
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, PatchMapping.class),
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, DeleteMapping.class))
.filter(Objects::nonNull)
.findFirst()
.map(a -> getResolver(a).resolve(a))
.orElse(null);
}
private MappingAnnotationResolver getResolver(Annotation annotation) {
for (MappingAnnotationResolver candidate : mappingAnnotationResolvers) {
if (candidate.supported(annotation.getClass())) {
return candidate;
}
} | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MappingDeclarationException.java
// public class MappingDeclarationException extends RuntimeException {
// protected Method method;
// protected Annotation annotation;
// protected int parameterIndex;
//
// public MappingDeclarationException(String message, Method method, Annotation annotation, int parameterIndex) {
// super(message);
// this.method = method;
// this.annotation = annotation;
// this.parameterIndex = parameterIndex;
// }
//
// public MappingDeclarationException(String message, Method method, Throwable throwable) {
// super(message, throwable);
// this.method = method;
// }
//
// public MappingDeclarationException(String message, Method method) {
// super(message);
// this.method = method;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/MappingAnnotationResolver.java
// public interface MappingAnnotationResolver<T extends Annotation> {
// UrlMapping resolve(T mappingAnnotation);
//
// boolean supported(Class<T> annotation);
// }
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/MappingAnnotationsInspector.java
import com.github.ggeorgovassilis.springjsonmapper.model.MappingDeclarationException;
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import com.github.ggeorgovassilis.springjsonmapper.spring.mapping.MappingAnnotationResolver;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.web.bind.annotation.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
}
if (methodUrlMapping.getProduces().length == 0) {
methodUrlMapping.setProduces(classUrlMapping.getProduces());
}
if (methodUrlMapping.getHeaders().length == 0) {
methodUrlMapping.setHeaders(classUrlMapping.getHeaders());
}
return methodUrlMapping;
}
private UrlMapping resolveFor(AnnotatedElement annotatedElement) {
return Stream.of(
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, RequestMapping.class),
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, GetMapping.class),
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, PostMapping.class),
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, PutMapping.class),
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, PatchMapping.class),
AnnotatedElementUtils.getMergedAnnotation(annotatedElement, DeleteMapping.class))
.filter(Objects::nonNull)
.findFirst()
.map(a -> getResolver(a).resolve(a))
.orElse(null);
}
private MappingAnnotationResolver getResolver(Annotation annotation) {
for (MappingAnnotationResolver candidate : mappingAnnotationResolvers) {
if (candidate.supported(annotation.getClass())) {
return candidate;
}
} | throw new MappingDeclarationException("Not implemented resolver for annotation ", null, annotation, -1); |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/model/TestMethodParameterDescriptior.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MethodParameterDescriptor.java
// public enum Type {
// httpParameter, pathVariable, requestBody, requestPart, cookie, httpHeader
// };
| import com.github.ggeorgovassilis.springjsonmapper.model.MethodParameterDescriptor.Type;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Method;
import static org.junit.jupiter.api.Assertions.assertEquals; | package com.github.ggeorgovassilis.springjsonmapper.model;
/**
* Test for {@link MethodParameterDescriptor}
*
* @author george georgovassilis
*
*/
public class TestMethodParameterDescriptior {
@Test
public void testSettersAndGetters() {
MethodParameterDescriptor mpd = new MethodParameterDescriptor();
Method method = mpd.getClass().getMethods()[0];
mpd.setMethod(method);
mpd.setName("someName");
mpd.setParameterOrdinal(3); | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MethodParameterDescriptor.java
// public enum Type {
// httpParameter, pathVariable, requestBody, requestPart, cookie, httpHeader
// };
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/model/TestMethodParameterDescriptior.java
import com.github.ggeorgovassilis.springjsonmapper.model.MethodParameterDescriptor.Type;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Method;
import static org.junit.jupiter.api.Assertions.assertEquals;
package com.github.ggeorgovassilis.springjsonmapper.model;
/**
* Test for {@link MethodParameterDescriptor}
*
* @author george georgovassilis
*
*/
public class TestMethodParameterDescriptior {
@Test
public void testSettersAndGetters() {
MethodParameterDescriptor mpd = new MethodParameterDescriptor();
Method method = mpd.getClass().getMethods()[0];
mpd.setMethod(method);
mpd.setName("someName");
mpd.setParameterOrdinal(3); | mpd.setType(Type.httpHeader); |
ggeorgovassilis/spring-rest-invoker | src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/RequestMappingAnnotationResolver.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; | package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
/**
* Looks at class and method and extract mapping annotations such as
* {@link RequestMapping}
*
* @author minasgull
*/
public class RequestMappingAnnotationResolver extends BaseAnnotationResolver<RequestMapping> {
@Override | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/RequestMappingAnnotationResolver.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
/**
* Looks at class and method and extract mapping annotations such as
* {@link RequestMapping}
*
* @author minasgull
*/
public class RequestMappingAnnotationResolver extends BaseAnnotationResolver<RequestMapping> {
@Override | public UrlMapping resolve(RequestMapping ann) { |
ggeorgovassilis/spring-rest-invoker | src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/GetMappingAnnotationResolver.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.GetMapping; | package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
/**
* Looks at class and method and extract mapping annotations such as
* {@link GetMapping}
*
* @author minasgull
*/
public class GetMappingAnnotationResolver extends BaseAnnotationResolver<GetMapping> {
@Override | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/GetMappingAnnotationResolver.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.GetMapping;
package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
/**
* Looks at class and method and extract mapping annotations such as
* {@link GetMapping}
*
* @author minasgull
*/
public class GetMappingAnnotationResolver extends BaseAnnotationResolver<GetMapping> {
@Override | public UrlMapping resolve(GetMapping ann) { |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/PostMappingAnnotationResolverTest.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PostMapping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows; | package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
class PostMappingAnnotationResolverTest {
private PostMappingAnnotationResolver resolver;
@BeforeEach
void setUp() {
resolver = new PostMappingAnnotationResolver();
}
@Test
void testAmbiguousPath() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousPath.class, "method"));
});
}
@Test
void testNoPath() { | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/PostMappingAnnotationResolverTest.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PostMapping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
class PostMappingAnnotationResolverTest {
private PostMappingAnnotationResolver resolver;
@BeforeEach
void setUp() {
resolver = new PostMappingAnnotationResolver();
}
@Test
void testAmbiguousPath() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousPath.class, "method"));
});
}
@Test
void testNoPath() { | UrlMapping actual = resolver.resolve(getAnnotation(NoPath.class, "method")); |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/PutMappingAnnotationResolverTest.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PutMapping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows; | package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
class PutMappingAnnotationResolverTest {
private PutMappingAnnotationResolver resolver;
@BeforeEach
void setUp() {
resolver = new PutMappingAnnotationResolver();
}
@Test
void testAmbiguousPath() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousPath.class, "method"));
});
}
@Test
void testNoPath() { | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/PutMappingAnnotationResolverTest.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PutMapping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
class PutMappingAnnotationResolverTest {
private PutMappingAnnotationResolver resolver;
@BeforeEach
void setUp() {
resolver = new PutMappingAnnotationResolver();
}
@Test
void testAmbiguousPath() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousPath.class, "method"));
});
}
@Test
void testNoPath() { | UrlMapping actual = resolver.resolve(getAnnotation(NoPath.class, "method")); |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/TestSpringAnnotationMethodInspector.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/MethodInspector.java
// public interface MethodInspector {
//
// UrlMapping inspect(Method method, Object[] args);
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MappingDeclarationException.java
// public class MappingDeclarationException extends RuntimeException {
// protected Method method;
// protected Annotation annotation;
// protected int parameterIndex;
//
// public MappingDeclarationException(String message, Method method, Annotation annotation, int parameterIndex) {
// super(message);
// this.method = method;
// this.annotation = annotation;
// this.parameterIndex = parameterIndex;
// }
//
// public MappingDeclarationException(String message, Method method, Throwable throwable) {
// super(message, throwable);
// this.method = method;
// }
//
// public MappingDeclarationException(String message, Method method) {
// super(message);
// this.method = method;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.MethodInspector;
import com.github.ggeorgovassilis.springjsonmapper.model.MappingDeclarationException;
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringValueResolver;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.lang.reflect.Method;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; | package com.github.ggeorgovassilis.springjsonmapper.spring;
/**
* Tests a few code paths in {@link SpringAnnotationMethodInspector} that are
* not covered by other tests.
*
* @author george georgovassilis
*/
@RequestMapping
public class TestSpringAnnotationMethodInspector {
@RequestMapping
public void someMethod1() {
}
@RequestMapping("/someMethod")
public void someMethod2(String p1, @RequestParam int p2, String p3) {
}
@Test
public void testMissingParameters() throws Exception { | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/MethodInspector.java
// public interface MethodInspector {
//
// UrlMapping inspect(Method method, Object[] args);
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MappingDeclarationException.java
// public class MappingDeclarationException extends RuntimeException {
// protected Method method;
// protected Annotation annotation;
// protected int parameterIndex;
//
// public MappingDeclarationException(String message, Method method, Annotation annotation, int parameterIndex) {
// super(message);
// this.method = method;
// this.annotation = annotation;
// this.parameterIndex = parameterIndex;
// }
//
// public MappingDeclarationException(String message, Method method, Throwable throwable) {
// super(message, throwable);
// this.method = method;
// }
//
// public MappingDeclarationException(String message, Method method) {
// super(message);
// this.method = method;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/TestSpringAnnotationMethodInspector.java
import com.github.ggeorgovassilis.springjsonmapper.MethodInspector;
import com.github.ggeorgovassilis.springjsonmapper.model.MappingDeclarationException;
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringValueResolver;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.lang.reflect.Method;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
package com.github.ggeorgovassilis.springjsonmapper.spring;
/**
* Tests a few code paths in {@link SpringAnnotationMethodInspector} that are
* not covered by other tests.
*
* @author george georgovassilis
*/
@RequestMapping
public class TestSpringAnnotationMethodInspector {
@RequestMapping
public void someMethod1() {
}
@RequestMapping("/someMethod")
public void someMethod2(String p1, @RequestParam int p2, String p3) {
}
@Test
public void testMissingParameters() throws Exception { | assertThrows(MappingDeclarationException.class, () -> { |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/TestSpringAnnotationMethodInspector.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/MethodInspector.java
// public interface MethodInspector {
//
// UrlMapping inspect(Method method, Object[] args);
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MappingDeclarationException.java
// public class MappingDeclarationException extends RuntimeException {
// protected Method method;
// protected Annotation annotation;
// protected int parameterIndex;
//
// public MappingDeclarationException(String message, Method method, Annotation annotation, int parameterIndex) {
// super(message);
// this.method = method;
// this.annotation = annotation;
// this.parameterIndex = parameterIndex;
// }
//
// public MappingDeclarationException(String message, Method method, Throwable throwable) {
// super(message, throwable);
// this.method = method;
// }
//
// public MappingDeclarationException(String message, Method method) {
// super(message);
// this.method = method;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.MethodInspector;
import com.github.ggeorgovassilis.springjsonmapper.model.MappingDeclarationException;
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringValueResolver;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.lang.reflect.Method;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; | package com.github.ggeorgovassilis.springjsonmapper.spring;
/**
* Tests a few code paths in {@link SpringAnnotationMethodInspector} that are
* not covered by other tests.
*
* @author george georgovassilis
*/
@RequestMapping
public class TestSpringAnnotationMethodInspector {
@RequestMapping
public void someMethod1() {
}
@RequestMapping("/someMethod")
public void someMethod2(String p1, @RequestParam int p2, String p3) {
}
@Test
public void testMissingParameters() throws Exception {
assertThrows(MappingDeclarationException.class, () -> { | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/MethodInspector.java
// public interface MethodInspector {
//
// UrlMapping inspect(Method method, Object[] args);
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MappingDeclarationException.java
// public class MappingDeclarationException extends RuntimeException {
// protected Method method;
// protected Annotation annotation;
// protected int parameterIndex;
//
// public MappingDeclarationException(String message, Method method, Annotation annotation, int parameterIndex) {
// super(message);
// this.method = method;
// this.annotation = annotation;
// this.parameterIndex = parameterIndex;
// }
//
// public MappingDeclarationException(String message, Method method, Throwable throwable) {
// super(message, throwable);
// this.method = method;
// }
//
// public MappingDeclarationException(String message, Method method) {
// super(message);
// this.method = method;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/TestSpringAnnotationMethodInspector.java
import com.github.ggeorgovassilis.springjsonmapper.MethodInspector;
import com.github.ggeorgovassilis.springjsonmapper.model.MappingDeclarationException;
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringValueResolver;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.lang.reflect.Method;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
package com.github.ggeorgovassilis.springjsonmapper.spring;
/**
* Tests a few code paths in {@link SpringAnnotationMethodInspector} that are
* not covered by other tests.
*
* @author george georgovassilis
*/
@RequestMapping
public class TestSpringAnnotationMethodInspector {
@RequestMapping
public void someMethod1() {
}
@RequestMapping("/someMethod")
public void someMethod2(String p1, @RequestParam int p2, String p3) {
}
@Test
public void testMissingParameters() throws Exception {
assertThrows(MappingDeclarationException.class, () -> { | MethodInspector mappingInspector = mock(MethodInspector.class); |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/TestSpringAnnotationMethodInspector.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/MethodInspector.java
// public interface MethodInspector {
//
// UrlMapping inspect(Method method, Object[] args);
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MappingDeclarationException.java
// public class MappingDeclarationException extends RuntimeException {
// protected Method method;
// protected Annotation annotation;
// protected int parameterIndex;
//
// public MappingDeclarationException(String message, Method method, Annotation annotation, int parameterIndex) {
// super(message);
// this.method = method;
// this.annotation = annotation;
// this.parameterIndex = parameterIndex;
// }
//
// public MappingDeclarationException(String message, Method method, Throwable throwable) {
// super(message, throwable);
// this.method = method;
// }
//
// public MappingDeclarationException(String message, Method method) {
// super(message);
// this.method = method;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.MethodInspector;
import com.github.ggeorgovassilis.springjsonmapper.model.MappingDeclarationException;
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringValueResolver;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.lang.reflect.Method;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; | package com.github.ggeorgovassilis.springjsonmapper.spring;
/**
* Tests a few code paths in {@link SpringAnnotationMethodInspector} that are
* not covered by other tests.
*
* @author george georgovassilis
*/
@RequestMapping
public class TestSpringAnnotationMethodInspector {
@RequestMapping
public void someMethod1() {
}
@RequestMapping("/someMethod")
public void someMethod2(String p1, @RequestParam int p2, String p3) {
}
@Test
public void testMissingParameters() throws Exception {
assertThrows(MappingDeclarationException.class, () -> {
MethodInspector mappingInspector = mock(MethodInspector.class); | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/MethodInspector.java
// public interface MethodInspector {
//
// UrlMapping inspect(Method method, Object[] args);
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MappingDeclarationException.java
// public class MappingDeclarationException extends RuntimeException {
// protected Method method;
// protected Annotation annotation;
// protected int parameterIndex;
//
// public MappingDeclarationException(String message, Method method, Annotation annotation, int parameterIndex) {
// super(message);
// this.method = method;
// this.annotation = annotation;
// this.parameterIndex = parameterIndex;
// }
//
// public MappingDeclarationException(String message, Method method, Throwable throwable) {
// super(message, throwable);
// this.method = method;
// }
//
// public MappingDeclarationException(String message, Method method) {
// super(message);
// this.method = method;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/TestSpringAnnotationMethodInspector.java
import com.github.ggeorgovassilis.springjsonmapper.MethodInspector;
import com.github.ggeorgovassilis.springjsonmapper.model.MappingDeclarationException;
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringValueResolver;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.lang.reflect.Method;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
package com.github.ggeorgovassilis.springjsonmapper.spring;
/**
* Tests a few code paths in {@link SpringAnnotationMethodInspector} that are
* not covered by other tests.
*
* @author george georgovassilis
*/
@RequestMapping
public class TestSpringAnnotationMethodInspector {
@RequestMapping
public void someMethod1() {
}
@RequestMapping("/someMethod")
public void someMethod2(String p1, @RequestParam int p2, String p3) {
}
@Test
public void testMissingParameters() throws Exception {
assertThrows(MappingDeclarationException.class, () -> {
MethodInspector mappingInspector = mock(MethodInspector.class); | when(mappingInspector.inspect(any(), any())).thenReturn(new UrlMapping()); |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/jaxrs/BankServiceJaxRs.java | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Account.java
// @JsonPropertyOrder({ "accountNumber", "balance", "owner" })
// public class Account implements Serializable {
//
// private static final long serialVersionUID = 3338920622026973343L;
// private String accountNumber;
// private int balance;
// private Customer owner;
//
// public String getAccountNumber() {
// return accountNumber;
// }
//
// public void setAccountNumber(String accountNumber) {
// this.accountNumber = accountNumber;
// }
//
// public int getBalance() {
// return balance;
// }
//
// public void setBalance(int balance) {
// this.balance = balance;
// }
//
// public Customer getOwner() {
// return owner;
// }
//
// public void setOwner(Customer owner) {
// this.owner = owner;
// }
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BankService.java
// public interface BankService {
//
// Account transfer(Account fromAccount, Customer actor, Account toAccount, int amount, boolean sendConfirmationSms);
//
// Boolean checkAccount(Account account);
//
// byte[] updatePhoto(String name, byte[] photo);
//
// Account joinAccounts(Account account1, Account account2);
//
// Customer authenticate(String name, String password, String sessionId);
//
// Account getAccount(int id);
//
// boolean isSessionAlive(String sid);
//
// boolean doesCustomerExist(String name);
//
// boolean doesCustomerExist2(String name);
//
// List<Account> getAllAccounts();
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Customer.java
// public class Customer implements Serializable {
//
// private static final long serialVersionUID = 5450750236224806988L;
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
| import javax.ws.rs.BeanParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.CookieParam;
import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import com.github.ggeorgovassilis.springjsonmapper.jaxrs.Headers;
import com.github.ggeorgovassilis.springjsonmapper.services.Account;
import com.github.ggeorgovassilis.springjsonmapper.services.BankService;
import com.github.ggeorgovassilis.springjsonmapper.services.Customer;
import java.util.List; | package com.github.ggeorgovassilis.springjsonmapper.services.jaxrs;
/**
* Mapping to a hypothetical bank service REST API using JAX-RS annotations
*
* @author george georgovassilis
*
*/
public interface BankServiceJaxRs extends BankService {
@Override
@POST
@Path("/transfer") | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Account.java
// @JsonPropertyOrder({ "accountNumber", "balance", "owner" })
// public class Account implements Serializable {
//
// private static final long serialVersionUID = 3338920622026973343L;
// private String accountNumber;
// private int balance;
// private Customer owner;
//
// public String getAccountNumber() {
// return accountNumber;
// }
//
// public void setAccountNumber(String accountNumber) {
// this.accountNumber = accountNumber;
// }
//
// public int getBalance() {
// return balance;
// }
//
// public void setBalance(int balance) {
// this.balance = balance;
// }
//
// public Customer getOwner() {
// return owner;
// }
//
// public void setOwner(Customer owner) {
// this.owner = owner;
// }
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BankService.java
// public interface BankService {
//
// Account transfer(Account fromAccount, Customer actor, Account toAccount, int amount, boolean sendConfirmationSms);
//
// Boolean checkAccount(Account account);
//
// byte[] updatePhoto(String name, byte[] photo);
//
// Account joinAccounts(Account account1, Account account2);
//
// Customer authenticate(String name, String password, String sessionId);
//
// Account getAccount(int id);
//
// boolean isSessionAlive(String sid);
//
// boolean doesCustomerExist(String name);
//
// boolean doesCustomerExist2(String name);
//
// List<Account> getAllAccounts();
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Customer.java
// public class Customer implements Serializable {
//
// private static final long serialVersionUID = 5450750236224806988L;
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/jaxrs/BankServiceJaxRs.java
import javax.ws.rs.BeanParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.CookieParam;
import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import com.github.ggeorgovassilis.springjsonmapper.jaxrs.Headers;
import com.github.ggeorgovassilis.springjsonmapper.services.Account;
import com.github.ggeorgovassilis.springjsonmapper.services.BankService;
import com.github.ggeorgovassilis.springjsonmapper.services.Customer;
import java.util.List;
package com.github.ggeorgovassilis.springjsonmapper.services.jaxrs;
/**
* Mapping to a hypothetical bank service REST API using JAX-RS annotations
*
* @author george georgovassilis
*
*/
public interface BankServiceJaxRs extends BankService {
@Override
@POST
@Path("/transfer") | Account transfer(@BeanParam @QueryParam("fromAccount") Account fromAccount, |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/jaxrs/BankServiceJaxRs.java | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Account.java
// @JsonPropertyOrder({ "accountNumber", "balance", "owner" })
// public class Account implements Serializable {
//
// private static final long serialVersionUID = 3338920622026973343L;
// private String accountNumber;
// private int balance;
// private Customer owner;
//
// public String getAccountNumber() {
// return accountNumber;
// }
//
// public void setAccountNumber(String accountNumber) {
// this.accountNumber = accountNumber;
// }
//
// public int getBalance() {
// return balance;
// }
//
// public void setBalance(int balance) {
// this.balance = balance;
// }
//
// public Customer getOwner() {
// return owner;
// }
//
// public void setOwner(Customer owner) {
// this.owner = owner;
// }
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BankService.java
// public interface BankService {
//
// Account transfer(Account fromAccount, Customer actor, Account toAccount, int amount, boolean sendConfirmationSms);
//
// Boolean checkAccount(Account account);
//
// byte[] updatePhoto(String name, byte[] photo);
//
// Account joinAccounts(Account account1, Account account2);
//
// Customer authenticate(String name, String password, String sessionId);
//
// Account getAccount(int id);
//
// boolean isSessionAlive(String sid);
//
// boolean doesCustomerExist(String name);
//
// boolean doesCustomerExist2(String name);
//
// List<Account> getAllAccounts();
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Customer.java
// public class Customer implements Serializable {
//
// private static final long serialVersionUID = 5450750236224806988L;
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
| import javax.ws.rs.BeanParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.CookieParam;
import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import com.github.ggeorgovassilis.springjsonmapper.jaxrs.Headers;
import com.github.ggeorgovassilis.springjsonmapper.services.Account;
import com.github.ggeorgovassilis.springjsonmapper.services.BankService;
import com.github.ggeorgovassilis.springjsonmapper.services.Customer;
import java.util.List; | package com.github.ggeorgovassilis.springjsonmapper.services.jaxrs;
/**
* Mapping to a hypothetical bank service REST API using JAX-RS annotations
*
* @author george georgovassilis
*
*/
public interface BankServiceJaxRs extends BankService {
@Override
@POST
@Path("/transfer")
Account transfer(@BeanParam @QueryParam("fromAccount") Account fromAccount, | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Account.java
// @JsonPropertyOrder({ "accountNumber", "balance", "owner" })
// public class Account implements Serializable {
//
// private static final long serialVersionUID = 3338920622026973343L;
// private String accountNumber;
// private int balance;
// private Customer owner;
//
// public String getAccountNumber() {
// return accountNumber;
// }
//
// public void setAccountNumber(String accountNumber) {
// this.accountNumber = accountNumber;
// }
//
// public int getBalance() {
// return balance;
// }
//
// public void setBalance(int balance) {
// this.balance = balance;
// }
//
// public Customer getOwner() {
// return owner;
// }
//
// public void setOwner(Customer owner) {
// this.owner = owner;
// }
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BankService.java
// public interface BankService {
//
// Account transfer(Account fromAccount, Customer actor, Account toAccount, int amount, boolean sendConfirmationSms);
//
// Boolean checkAccount(Account account);
//
// byte[] updatePhoto(String name, byte[] photo);
//
// Account joinAccounts(Account account1, Account account2);
//
// Customer authenticate(String name, String password, String sessionId);
//
// Account getAccount(int id);
//
// boolean isSessionAlive(String sid);
//
// boolean doesCustomerExist(String name);
//
// boolean doesCustomerExist2(String name);
//
// List<Account> getAllAccounts();
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Customer.java
// public class Customer implements Serializable {
//
// private static final long serialVersionUID = 5450750236224806988L;
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/jaxrs/BankServiceJaxRs.java
import javax.ws.rs.BeanParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.CookieParam;
import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import com.github.ggeorgovassilis.springjsonmapper.jaxrs.Headers;
import com.github.ggeorgovassilis.springjsonmapper.services.Account;
import com.github.ggeorgovassilis.springjsonmapper.services.BankService;
import com.github.ggeorgovassilis.springjsonmapper.services.Customer;
import java.util.List;
package com.github.ggeorgovassilis.springjsonmapper.services.jaxrs;
/**
* Mapping to a hypothetical bank service REST API using JAX-RS annotations
*
* @author george georgovassilis
*
*/
public interface BankServiceJaxRs extends BankService {
@Override
@POST
@Path("/transfer")
Account transfer(@BeanParam @QueryParam("fromAccount") Account fromAccount, | @BeanParam @QueryParam("actor") Customer actor, @BeanParam @QueryParam("toAccount") Account toAccount, |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/MappingAnnotationsInspectorTest.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/MappingAnnotationResolver.java
// public interface MappingAnnotationResolver<T extends Annotation> {
// UrlMapping resolve(T mappingAnnotation);
//
// boolean supported(Class<T> annotation);
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import com.github.ggeorgovassilis.springjsonmapper.spring.mapping.MappingAnnotationResolver;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.lang.reflect.Method;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; | package com.github.ggeorgovassilis.springjsonmapper.spring;
class MappingAnnotationsInspectorTest {
private static final Object[] NO_ARGS = new Object[0]; | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/MappingAnnotationResolver.java
// public interface MappingAnnotationResolver<T extends Annotation> {
// UrlMapping resolve(T mappingAnnotation);
//
// boolean supported(Class<T> annotation);
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/MappingAnnotationsInspectorTest.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import com.github.ggeorgovassilis.springjsonmapper.spring.mapping.MappingAnnotationResolver;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.lang.reflect.Method;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
package com.github.ggeorgovassilis.springjsonmapper.spring;
class MappingAnnotationsInspectorTest {
private static final Object[] NO_ARGS = new Object[0]; | private MappingAnnotationResolver<?> resolver; |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/MappingAnnotationsInspectorTest.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/MappingAnnotationResolver.java
// public interface MappingAnnotationResolver<T extends Annotation> {
// UrlMapping resolve(T mappingAnnotation);
//
// boolean supported(Class<T> annotation);
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import com.github.ggeorgovassilis.springjsonmapper.spring.mapping.MappingAnnotationResolver;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.lang.reflect.Method;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; | package com.github.ggeorgovassilis.springjsonmapper.spring;
class MappingAnnotationsInspectorTest {
private static final Object[] NO_ARGS = new Object[0];
private MappingAnnotationResolver<?> resolver;
private MappingAnnotationsInspector inspector;
@BeforeEach
void setUp() {
resolver = mock(MappingAnnotationResolver.class);
inspector = new MappingAnnotationsInspector(Collections.singletonList(resolver));
}
@Test
void testClassLevelOnlyAnnotation() { | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/MappingAnnotationResolver.java
// public interface MappingAnnotationResolver<T extends Annotation> {
// UrlMapping resolve(T mappingAnnotation);
//
// boolean supported(Class<T> annotation);
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/MappingAnnotationsInspectorTest.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import com.github.ggeorgovassilis.springjsonmapper.spring.mapping.MappingAnnotationResolver;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.lang.reflect.Method;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
package com.github.ggeorgovassilis.springjsonmapper.spring;
class MappingAnnotationsInspectorTest {
private static final Object[] NO_ARGS = new Object[0];
private MappingAnnotationResolver<?> resolver;
private MappingAnnotationsInspector inspector;
@BeforeEach
void setUp() {
resolver = mock(MappingAnnotationResolver.class);
inspector = new MappingAnnotationsInspector(Collections.singletonList(resolver));
}
@Test
void testClassLevelOnlyAnnotation() { | UrlMapping expected = new UrlMapping(); |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/spring/BankServiceShortcutSpring.java | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Account.java
// @JsonPropertyOrder({ "accountNumber", "balance", "owner" })
// public class Account implements Serializable {
//
// private static final long serialVersionUID = 3338920622026973343L;
// private String accountNumber;
// private int balance;
// private Customer owner;
//
// public String getAccountNumber() {
// return accountNumber;
// }
//
// public void setAccountNumber(String accountNumber) {
// this.accountNumber = accountNumber;
// }
//
// public int getBalance() {
// return balance;
// }
//
// public void setBalance(int balance) {
// this.balance = balance;
// }
//
// public Customer getOwner() {
// return owner;
// }
//
// public void setOwner(Customer owner) {
// this.owner = owner;
// }
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BankService.java
// public interface BankService {
//
// Account transfer(Account fromAccount, Customer actor, Account toAccount, int amount, boolean sendConfirmationSms);
//
// Boolean checkAccount(Account account);
//
// byte[] updatePhoto(String name, byte[] photo);
//
// Account joinAccounts(Account account1, Account account2);
//
// Customer authenticate(String name, String password, String sessionId);
//
// Account getAccount(int id);
//
// boolean isSessionAlive(String sid);
//
// boolean doesCustomerExist(String name);
//
// boolean doesCustomerExist2(String name);
//
// List<Account> getAllAccounts();
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Customer.java
// public class Customer implements Serializable {
//
// private static final long serialVersionUID = 5450750236224806988L;
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.Header;
import com.github.ggeorgovassilis.springjsonmapper.services.Account;
import com.github.ggeorgovassilis.springjsonmapper.services.BankService;
import com.github.ggeorgovassilis.springjsonmapper.services.Customer;
import org.springframework.web.bind.annotation.*;
import java.util.List; | package com.github.ggeorgovassilis.springjsonmapper.services.spring;
/**
* Mapping to a hypothetical bank service REST API using Spring annotations
*
* @author george georgovassilis
*/
public interface BankServiceShortcutSpring extends BankService {
@Override
@PostMapping("/transfer") | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Account.java
// @JsonPropertyOrder({ "accountNumber", "balance", "owner" })
// public class Account implements Serializable {
//
// private static final long serialVersionUID = 3338920622026973343L;
// private String accountNumber;
// private int balance;
// private Customer owner;
//
// public String getAccountNumber() {
// return accountNumber;
// }
//
// public void setAccountNumber(String accountNumber) {
// this.accountNumber = accountNumber;
// }
//
// public int getBalance() {
// return balance;
// }
//
// public void setBalance(int balance) {
// this.balance = balance;
// }
//
// public Customer getOwner() {
// return owner;
// }
//
// public void setOwner(Customer owner) {
// this.owner = owner;
// }
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BankService.java
// public interface BankService {
//
// Account transfer(Account fromAccount, Customer actor, Account toAccount, int amount, boolean sendConfirmationSms);
//
// Boolean checkAccount(Account account);
//
// byte[] updatePhoto(String name, byte[] photo);
//
// Account joinAccounts(Account account1, Account account2);
//
// Customer authenticate(String name, String password, String sessionId);
//
// Account getAccount(int id);
//
// boolean isSessionAlive(String sid);
//
// boolean doesCustomerExist(String name);
//
// boolean doesCustomerExist2(String name);
//
// List<Account> getAllAccounts();
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Customer.java
// public class Customer implements Serializable {
//
// private static final long serialVersionUID = 5450750236224806988L;
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/spring/BankServiceShortcutSpring.java
import com.github.ggeorgovassilis.springjsonmapper.model.Header;
import com.github.ggeorgovassilis.springjsonmapper.services.Account;
import com.github.ggeorgovassilis.springjsonmapper.services.BankService;
import com.github.ggeorgovassilis.springjsonmapper.services.Customer;
import org.springframework.web.bind.annotation.*;
import java.util.List;
package com.github.ggeorgovassilis.springjsonmapper.services.spring;
/**
* Mapping to a hypothetical bank service REST API using Spring annotations
*
* @author george georgovassilis
*/
public interface BankServiceShortcutSpring extends BankService {
@Override
@PostMapping("/transfer") | Account transfer(@RequestBody @RequestParam("fromAccount") Account fromAccount, |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/spring/BankServiceShortcutSpring.java | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Account.java
// @JsonPropertyOrder({ "accountNumber", "balance", "owner" })
// public class Account implements Serializable {
//
// private static final long serialVersionUID = 3338920622026973343L;
// private String accountNumber;
// private int balance;
// private Customer owner;
//
// public String getAccountNumber() {
// return accountNumber;
// }
//
// public void setAccountNumber(String accountNumber) {
// this.accountNumber = accountNumber;
// }
//
// public int getBalance() {
// return balance;
// }
//
// public void setBalance(int balance) {
// this.balance = balance;
// }
//
// public Customer getOwner() {
// return owner;
// }
//
// public void setOwner(Customer owner) {
// this.owner = owner;
// }
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BankService.java
// public interface BankService {
//
// Account transfer(Account fromAccount, Customer actor, Account toAccount, int amount, boolean sendConfirmationSms);
//
// Boolean checkAccount(Account account);
//
// byte[] updatePhoto(String name, byte[] photo);
//
// Account joinAccounts(Account account1, Account account2);
//
// Customer authenticate(String name, String password, String sessionId);
//
// Account getAccount(int id);
//
// boolean isSessionAlive(String sid);
//
// boolean doesCustomerExist(String name);
//
// boolean doesCustomerExist2(String name);
//
// List<Account> getAllAccounts();
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Customer.java
// public class Customer implements Serializable {
//
// private static final long serialVersionUID = 5450750236224806988L;
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.Header;
import com.github.ggeorgovassilis.springjsonmapper.services.Account;
import com.github.ggeorgovassilis.springjsonmapper.services.BankService;
import com.github.ggeorgovassilis.springjsonmapper.services.Customer;
import org.springframework.web.bind.annotation.*;
import java.util.List; | package com.github.ggeorgovassilis.springjsonmapper.services.spring;
/**
* Mapping to a hypothetical bank service REST API using Spring annotations
*
* @author george georgovassilis
*/
public interface BankServiceShortcutSpring extends BankService {
@Override
@PostMapping("/transfer")
Account transfer(@RequestBody @RequestParam("fromAccount") Account fromAccount, | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Account.java
// @JsonPropertyOrder({ "accountNumber", "balance", "owner" })
// public class Account implements Serializable {
//
// private static final long serialVersionUID = 3338920622026973343L;
// private String accountNumber;
// private int balance;
// private Customer owner;
//
// public String getAccountNumber() {
// return accountNumber;
// }
//
// public void setAccountNumber(String accountNumber) {
// this.accountNumber = accountNumber;
// }
//
// public int getBalance() {
// return balance;
// }
//
// public void setBalance(int balance) {
// this.balance = balance;
// }
//
// public Customer getOwner() {
// return owner;
// }
//
// public void setOwner(Customer owner) {
// this.owner = owner;
// }
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BankService.java
// public interface BankService {
//
// Account transfer(Account fromAccount, Customer actor, Account toAccount, int amount, boolean sendConfirmationSms);
//
// Boolean checkAccount(Account account);
//
// byte[] updatePhoto(String name, byte[] photo);
//
// Account joinAccounts(Account account1, Account account2);
//
// Customer authenticate(String name, String password, String sessionId);
//
// Account getAccount(int id);
//
// boolean isSessionAlive(String sid);
//
// boolean doesCustomerExist(String name);
//
// boolean doesCustomerExist2(String name);
//
// List<Account> getAllAccounts();
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Customer.java
// public class Customer implements Serializable {
//
// private static final long serialVersionUID = 5450750236224806988L;
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/spring/BankServiceShortcutSpring.java
import com.github.ggeorgovassilis.springjsonmapper.model.Header;
import com.github.ggeorgovassilis.springjsonmapper.services.Account;
import com.github.ggeorgovassilis.springjsonmapper.services.BankService;
import com.github.ggeorgovassilis.springjsonmapper.services.Customer;
import org.springframework.web.bind.annotation.*;
import java.util.List;
package com.github.ggeorgovassilis.springjsonmapper.services.spring;
/**
* Mapping to a hypothetical bank service REST API using Spring annotations
*
* @author george georgovassilis
*/
public interface BankServiceShortcutSpring extends BankService {
@Override
@PostMapping("/transfer")
Account transfer(@RequestBody @RequestParam("fromAccount") Account fromAccount, | @RequestBody @RequestParam("actor") Customer actor, |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/PatchMappingAnnotationResolverTest.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PatchMapping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows; | package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
class PatchMappingAnnotationResolverTest {
private PatchMappingAnnotationResolver resolver;
@BeforeEach
void setUp() {
resolver = new PatchMappingAnnotationResolver();
}
@Test
void testAmbiguousPath() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousPath.class, "method"));
});
}
@Test
void testNoPath() { | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/PatchMappingAnnotationResolverTest.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PatchMapping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
class PatchMappingAnnotationResolverTest {
private PatchMappingAnnotationResolver resolver;
@BeforeEach
void setUp() {
resolver = new PatchMappingAnnotationResolver();
}
@Test
void testAmbiguousPath() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousPath.class, "method"));
});
}
@Test
void testNoPath() { | UrlMapping actual = resolver.resolve(getAnnotation(NoPath.class, "method")); |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/RequestMappingAnnotationResolverTest.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows; | package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
class RequestMappingAnnotationResolverTest {
private RequestMappingAnnotationResolver resolver;
@BeforeEach
void setUp() {
resolver = new RequestMappingAnnotationResolver();
}
@Test
void testAmbiguousMethod() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousMethod.class, "method"));
});
}
@Test
void testAmbiguousPath() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousPath.class, "method"));
});
}
@Test
void testDuplicatedMethod() { | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/RequestMappingAnnotationResolverTest.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
class RequestMappingAnnotationResolverTest {
private RequestMappingAnnotationResolver resolver;
@BeforeEach
void setUp() {
resolver = new RequestMappingAnnotationResolver();
}
@Test
void testAmbiguousMethod() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousMethod.class, "method"));
});
}
@Test
void testAmbiguousPath() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousPath.class, "method"));
});
}
@Test
void testDuplicatedMethod() { | UrlMapping actual = resolver.resolve(getAnnotation(DuplicatedMethod.class, "method")); |
ggeorgovassilis/spring-rest-invoker | src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/DeleteMappingAnnotationResolver.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.DeleteMapping; | package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
/**
* Looks at class and method and extract mapping annotations such as
* {@link DeleteMapping}
*
* @author minasgull
*/
public class DeleteMappingAnnotationResolver extends BaseAnnotationResolver<DeleteMapping> {
@Override | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/DeleteMappingAnnotationResolver.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.DeleteMapping;
package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
/**
* Looks at class and method and extract mapping annotations such as
* {@link DeleteMapping}
*
* @author minasgull
*/
public class DeleteMappingAnnotationResolver extends BaseAnnotationResolver<DeleteMapping> {
@Override | public UrlMapping resolve(DeleteMapping ann) { |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/tests/BankServiceSpringTest.java | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/spring/BankServiceSpring.java
// public interface BankServiceSpring extends BankService {
//
// @Override
// @RequestMapping(value = "/transfer", method = RequestMethod.POST)
// Account transfer(@RequestBody @RequestParam("fromAccount") Account fromAccount,
// @RequestBody @RequestParam("actor") Customer actor,
// @RequestBody @RequestParam("toAccount") Account toAccount, @RequestBody @RequestParam("amount") int amount,
// @RequestParam("sendConfirmationSms") boolean sendConfirmationSms);
//
// @Override
// @RequestMapping(value = "/verify", method = RequestMethod.POST)
// Boolean checkAccount(@RequestBody Account account);
//
// @Override
// @RequestMapping(value = "/photo", method = RequestMethod.POST, consumes = { "image/gif", "image/jpeg",
// "image/png" }, produces = { "image/jpeg" })
// byte[] updatePhoto(@RequestParam("name") String name, @RequestBody byte[] photo);
//
// @Override
// @RequestMapping(value = "/join-accounts", method = RequestMethod.POST)
// Account joinAccounts(@RequestPart @RequestParam("account1") Account account1,
// @RequestPart @RequestParam("account2") Account account2);
//
// @Override
// @RequestMapping(value = "/authenticate", method = RequestMethod.POST)
// Customer authenticate(@RequestPart @RequestParam("name") String name,
// @RequestPart @RequestParam("password") String password, @CookieValue("sid") String sessionId);
//
// @Override
// @RequestMapping(value = "/accounts/{id}")
// Account getAccount(@PathVariable("id") int id);
//
// @Override
// @RequestMapping(value = "/session/check")
// boolean isSessionAlive(@Header("X-SessionId") String sid);
//
// @Override
// @RequestMapping(value = "/${domain}/customer/{name}")
// boolean doesCustomerExist(@PathVariable("name") String name);
//
// @Override
// @RequestMapping(value = "/${domain}/customer/{name}", headers={"X-header-1=value1","X-header-2=value2"})
// boolean doesCustomerExist2(@PathVariable("name") String name);
//
// @Override
// @RequestMapping(value = "/accounts")
// List<Account> getAllAccounts();
//
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/SpringRestInvokerProxyFactoryBean.java
// public class SpringRestInvokerProxyFactoryBean extends BaseRestInvokerProxyFactoryBean {
//
// @Override
// protected MethodInspector constructDefaultMethodInspector() {
// List<MappingAnnotationResolver<? extends Annotation>> mappings = Arrays.asList(new RequestMappingAnnotationResolver(),
// new PutMappingAnnotationResolver(),
// new PostMappingAnnotationResolver(),
// new PatchMappingAnnotationResolver(),
// new GetMappingAnnotationResolver(),
// new DeleteMappingAnnotationResolver());
//
// MappingAnnotationsInspector mappingAnnotationsInspector = new MappingAnnotationsInspector(mappings);
// SpringAnnotationMethodInspector inspector = new SpringAnnotationMethodInspector(mappingAnnotationsInspector);
// inspector.setEmbeddedValueResolver(expressionResolver);
// return inspector;
// }
//
// }
| import org.springframework.test.context.ContextConfiguration;
import com.github.ggeorgovassilis.springjsonmapper.services.spring.BankServiceSpring;
import com.github.ggeorgovassilis.springjsonmapper.spring.SpringRestInvokerProxyFactoryBean; | package com.github.ggeorgovassilis.springjsonmapper.tests;
/**
* Tests a more complex scenario with recorded HTTP requests and responses using
* the {@link SpringRestInvokerProxyFactoryBean}
*
* @author george georgovassilis
*
*/
@ContextConfiguration("classpath:test-context-bank-spring.xml")
public class BankServiceSpringTest extends AbstractBankServiceTest {
@Override
protected String getExpectedServiceName() { | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/spring/BankServiceSpring.java
// public interface BankServiceSpring extends BankService {
//
// @Override
// @RequestMapping(value = "/transfer", method = RequestMethod.POST)
// Account transfer(@RequestBody @RequestParam("fromAccount") Account fromAccount,
// @RequestBody @RequestParam("actor") Customer actor,
// @RequestBody @RequestParam("toAccount") Account toAccount, @RequestBody @RequestParam("amount") int amount,
// @RequestParam("sendConfirmationSms") boolean sendConfirmationSms);
//
// @Override
// @RequestMapping(value = "/verify", method = RequestMethod.POST)
// Boolean checkAccount(@RequestBody Account account);
//
// @Override
// @RequestMapping(value = "/photo", method = RequestMethod.POST, consumes = { "image/gif", "image/jpeg",
// "image/png" }, produces = { "image/jpeg" })
// byte[] updatePhoto(@RequestParam("name") String name, @RequestBody byte[] photo);
//
// @Override
// @RequestMapping(value = "/join-accounts", method = RequestMethod.POST)
// Account joinAccounts(@RequestPart @RequestParam("account1") Account account1,
// @RequestPart @RequestParam("account2") Account account2);
//
// @Override
// @RequestMapping(value = "/authenticate", method = RequestMethod.POST)
// Customer authenticate(@RequestPart @RequestParam("name") String name,
// @RequestPart @RequestParam("password") String password, @CookieValue("sid") String sessionId);
//
// @Override
// @RequestMapping(value = "/accounts/{id}")
// Account getAccount(@PathVariable("id") int id);
//
// @Override
// @RequestMapping(value = "/session/check")
// boolean isSessionAlive(@Header("X-SessionId") String sid);
//
// @Override
// @RequestMapping(value = "/${domain}/customer/{name}")
// boolean doesCustomerExist(@PathVariable("name") String name);
//
// @Override
// @RequestMapping(value = "/${domain}/customer/{name}", headers={"X-header-1=value1","X-header-2=value2"})
// boolean doesCustomerExist2(@PathVariable("name") String name);
//
// @Override
// @RequestMapping(value = "/accounts")
// List<Account> getAllAccounts();
//
// }
//
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/SpringRestInvokerProxyFactoryBean.java
// public class SpringRestInvokerProxyFactoryBean extends BaseRestInvokerProxyFactoryBean {
//
// @Override
// protected MethodInspector constructDefaultMethodInspector() {
// List<MappingAnnotationResolver<? extends Annotation>> mappings = Arrays.asList(new RequestMappingAnnotationResolver(),
// new PutMappingAnnotationResolver(),
// new PostMappingAnnotationResolver(),
// new PatchMappingAnnotationResolver(),
// new GetMappingAnnotationResolver(),
// new DeleteMappingAnnotationResolver());
//
// MappingAnnotationsInspector mappingAnnotationsInspector = new MappingAnnotationsInspector(mappings);
// SpringAnnotationMethodInspector inspector = new SpringAnnotationMethodInspector(mappingAnnotationsInspector);
// inspector.setEmbeddedValueResolver(expressionResolver);
// return inspector;
// }
//
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/tests/BankServiceSpringTest.java
import org.springframework.test.context.ContextConfiguration;
import com.github.ggeorgovassilis.springjsonmapper.services.spring.BankServiceSpring;
import com.github.ggeorgovassilis.springjsonmapper.spring.SpringRestInvokerProxyFactoryBean;
package com.github.ggeorgovassilis.springjsonmapper.tests;
/**
* Tests a more complex scenario with recorded HTTP requests and responses using
* the {@link SpringRestInvokerProxyFactoryBean}
*
* @author george georgovassilis
*
*/
@ContextConfiguration("classpath:test-context-bank-spring.xml")
public class BankServiceSpringTest extends AbstractBankServiceTest {
@Override
protected String getExpectedServiceName() { | return BankServiceSpring.class.getName(); |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/DeleteMappingAnnotationResolverTest.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.DeleteMapping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows; | package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
class DeleteMappingAnnotationResolverTest {
private DeleteMappingAnnotationResolver resolver;
@BeforeEach
void setUp() {
resolver = new DeleteMappingAnnotationResolver();
}
@Test
void testAmbiguousPath() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousPath.class, "method"));
});
}
@Test
void testNoPath() { | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/DeleteMappingAnnotationResolverTest.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.DeleteMapping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
class DeleteMappingAnnotationResolverTest {
private DeleteMappingAnnotationResolver resolver;
@BeforeEach
void setUp() {
resolver = new DeleteMappingAnnotationResolver();
}
@Test
void testAmbiguousPath() {
assertThrows(AmbiguousMappingException.class, () -> {
resolver.resolve(getAnnotation(AmbiguousPath.class, "method"));
});
}
@Test
void testNoPath() { | UrlMapping actual = resolver.resolve(getAnnotation(NoPath.class, "method")); |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/jaxrs/BookServiceJaxRs.java | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BookService.java
// public interface BookService {
//
// QueryResult findBooksByTitle(String q);
//
// Item findBookById(String id);
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Item.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Item implements Serializable {
//
// private static final long serialVersionUID = -6854695261165137027L;
// String id;
// String selfLink;
// VolumeInfo volumeInfo;
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getSelfLink() {
// return selfLink;
// }
//
// public void setSelfLink(String selfLink) {
// this.selfLink = selfLink;
// }
//
// public VolumeInfo getVolumeInfo() {
// return volumeInfo;
// }
//
// public void setVolumeInfo(VolumeInfo volumeInfo) {
// this.volumeInfo = volumeInfo;
// }
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/QueryResult.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class QueryResult implements Serializable {
//
// private static final long serialVersionUID = 8453337880965373284L;
// private int totalItems;
// List<Item> items;
//
// public int getTotalItems() {
// return totalItems;
// }
//
// public void setTotalItems(int totalItems) {
// this.totalItems = totalItems;
// }
//
// public List<Item> getItems() {
// return items;
// }
//
// public void setItems(List<Item> items) {
// this.items = items;
// }
//
// }
| import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import com.github.ggeorgovassilis.springjsonmapper.services.BookService;
import com.github.ggeorgovassilis.springjsonmapper.services.Item;
import com.github.ggeorgovassilis.springjsonmapper.services.QueryResult; | package com.github.ggeorgovassilis.springjsonmapper.services.jaxrs;
/**
* Mapping to the google books API by using JAX-RS annotations
* https://developers.google.com/books/
*
* @author george georgovassilis
*
*/
public interface BookServiceJaxRs extends BookService {
@Override
@Path("/volumes") | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BookService.java
// public interface BookService {
//
// QueryResult findBooksByTitle(String q);
//
// Item findBookById(String id);
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Item.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Item implements Serializable {
//
// private static final long serialVersionUID = -6854695261165137027L;
// String id;
// String selfLink;
// VolumeInfo volumeInfo;
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getSelfLink() {
// return selfLink;
// }
//
// public void setSelfLink(String selfLink) {
// this.selfLink = selfLink;
// }
//
// public VolumeInfo getVolumeInfo() {
// return volumeInfo;
// }
//
// public void setVolumeInfo(VolumeInfo volumeInfo) {
// this.volumeInfo = volumeInfo;
// }
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/QueryResult.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class QueryResult implements Serializable {
//
// private static final long serialVersionUID = 8453337880965373284L;
// private int totalItems;
// List<Item> items;
//
// public int getTotalItems() {
// return totalItems;
// }
//
// public void setTotalItems(int totalItems) {
// this.totalItems = totalItems;
// }
//
// public List<Item> getItems() {
// return items;
// }
//
// public void setItems(List<Item> items) {
// this.items = items;
// }
//
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/jaxrs/BookServiceJaxRs.java
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import com.github.ggeorgovassilis.springjsonmapper.services.BookService;
import com.github.ggeorgovassilis.springjsonmapper.services.Item;
import com.github.ggeorgovassilis.springjsonmapper.services.QueryResult;
package com.github.ggeorgovassilis.springjsonmapper.services.jaxrs;
/**
* Mapping to the google books API by using JAX-RS annotations
* https://developers.google.com/books/
*
* @author george georgovassilis
*
*/
public interface BookServiceJaxRs extends BookService {
@Override
@Path("/volumes") | QueryResult findBooksByTitle(@QueryParam("q") String q); |
ggeorgovassilis/spring-rest-invoker | src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/jaxrs/BookServiceJaxRs.java | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BookService.java
// public interface BookService {
//
// QueryResult findBooksByTitle(String q);
//
// Item findBookById(String id);
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Item.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Item implements Serializable {
//
// private static final long serialVersionUID = -6854695261165137027L;
// String id;
// String selfLink;
// VolumeInfo volumeInfo;
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getSelfLink() {
// return selfLink;
// }
//
// public void setSelfLink(String selfLink) {
// this.selfLink = selfLink;
// }
//
// public VolumeInfo getVolumeInfo() {
// return volumeInfo;
// }
//
// public void setVolumeInfo(VolumeInfo volumeInfo) {
// this.volumeInfo = volumeInfo;
// }
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/QueryResult.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class QueryResult implements Serializable {
//
// private static final long serialVersionUID = 8453337880965373284L;
// private int totalItems;
// List<Item> items;
//
// public int getTotalItems() {
// return totalItems;
// }
//
// public void setTotalItems(int totalItems) {
// this.totalItems = totalItems;
// }
//
// public List<Item> getItems() {
// return items;
// }
//
// public void setItems(List<Item> items) {
// this.items = items;
// }
//
// }
| import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import com.github.ggeorgovassilis.springjsonmapper.services.BookService;
import com.github.ggeorgovassilis.springjsonmapper.services.Item;
import com.github.ggeorgovassilis.springjsonmapper.services.QueryResult; | package com.github.ggeorgovassilis.springjsonmapper.services.jaxrs;
/**
* Mapping to the google books API by using JAX-RS annotations
* https://developers.google.com/books/
*
* @author george georgovassilis
*
*/
public interface BookServiceJaxRs extends BookService {
@Override
@Path("/volumes")
QueryResult findBooksByTitle(@QueryParam("q") String q);
@Override
@Path("/volumes/{id}") | // Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/BookService.java
// public interface BookService {
//
// QueryResult findBooksByTitle(String q);
//
// Item findBookById(String id);
//
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/Item.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Item implements Serializable {
//
// private static final long serialVersionUID = -6854695261165137027L;
// String id;
// String selfLink;
// VolumeInfo volumeInfo;
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getSelfLink() {
// return selfLink;
// }
//
// public void setSelfLink(String selfLink) {
// this.selfLink = selfLink;
// }
//
// public VolumeInfo getVolumeInfo() {
// return volumeInfo;
// }
//
// public void setVolumeInfo(VolumeInfo volumeInfo) {
// this.volumeInfo = volumeInfo;
// }
// }
//
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/QueryResult.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class QueryResult implements Serializable {
//
// private static final long serialVersionUID = 8453337880965373284L;
// private int totalItems;
// List<Item> items;
//
// public int getTotalItems() {
// return totalItems;
// }
//
// public void setTotalItems(int totalItems) {
// this.totalItems = totalItems;
// }
//
// public List<Item> getItems() {
// return items;
// }
//
// public void setItems(List<Item> items) {
// this.items = items;
// }
//
// }
// Path: src/test/java/com/github/ggeorgovassilis/springjsonmapper/services/jaxrs/BookServiceJaxRs.java
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import com.github.ggeorgovassilis.springjsonmapper.services.BookService;
import com.github.ggeorgovassilis.springjsonmapper.services.Item;
import com.github.ggeorgovassilis.springjsonmapper.services.QueryResult;
package com.github.ggeorgovassilis.springjsonmapper.services.jaxrs;
/**
* Mapping to the google books API by using JAX-RS annotations
* https://developers.google.com/books/
*
* @author george georgovassilis
*
*/
public interface BookServiceJaxRs extends BookService {
@Override
@Path("/volumes")
QueryResult findBooksByTitle(@QueryParam("q") String q);
@Override
@Path("/volumes/{id}") | Item findBookById(@PathParam("id") String id); |
ggeorgovassilis/spring-rest-invoker | src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MethodParameterDescriptor.java
// public enum Type {
// httpParameter, pathVariable, requestBody, requestPart, cookie, httpHeader
// };
| import org.springframework.http.HttpMethod;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import static com.github.ggeorgovassilis.springjsonmapper.model.MethodParameterDescriptor.Type; | return url;
}
public void setUrl(String url) {
this.url = url;
}
public HttpMethod getHttpMethod() {
return httpMethod;
}
public void setHttpMethod(HttpMethod httpMethod) {
this.httpMethod = httpMethod;
}
public List<MethodParameterDescriptor> getParameters() {
return parameters;
}
public void setParameters(List<MethodParameterDescriptor> parameters) {
this.parameters = parameters;
}
public void addDescriptor(MethodParameterDescriptor descriptor) {
parameters.add(descriptor);
}
public boolean hasRequestBody(String parameter) {
for (MethodParameterDescriptor descriptor : parameters)
if (parameter.equals(descriptor.getName()) | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/MethodParameterDescriptor.java
// public enum Type {
// httpParameter, pathVariable, requestBody, requestPart, cookie, httpHeader
// };
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
import org.springframework.http.HttpMethod;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import static com.github.ggeorgovassilis.springjsonmapper.model.MethodParameterDescriptor.Type;
return url;
}
public void setUrl(String url) {
this.url = url;
}
public HttpMethod getHttpMethod() {
return httpMethod;
}
public void setHttpMethod(HttpMethod httpMethod) {
this.httpMethod = httpMethod;
}
public List<MethodParameterDescriptor> getParameters() {
return parameters;
}
public void setParameters(List<MethodParameterDescriptor> parameters) {
this.parameters = parameters;
}
public void addDescriptor(MethodParameterDescriptor descriptor) {
parameters.add(descriptor);
}
public boolean hasRequestBody(String parameter) {
for (MethodParameterDescriptor descriptor : parameters)
if (parameter.equals(descriptor.getName()) | && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart))) |
ggeorgovassilis/spring-rest-invoker | src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/PutMappingAnnotationResolver.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PutMapping; | package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
/**
* Looks at class and method and extract mapping annotations such as
* {@link PutMapping}
*
* @author minasgull
*/
public class PutMappingAnnotationResolver extends BaseAnnotationResolver<PutMapping> {
@Override | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/PutMappingAnnotationResolver.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PutMapping;
package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
/**
* Looks at class and method and extract mapping annotations such as
* {@link PutMapping}
*
* @author minasgull
*/
public class PutMappingAnnotationResolver extends BaseAnnotationResolver<PutMapping> {
@Override | public UrlMapping resolve(PutMapping ann) { |
ggeorgovassilis/spring-rest-invoker | src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/PatchMappingAnnotationResolver.java | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
| import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PatchMapping; | package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
/**
* Looks at class and method and extract mapping annotations such as
* {@link PatchMapping}
*
* @author minasgull
*/
public class PatchMappingAnnotationResolver extends BaseAnnotationResolver<PatchMapping> {
@Override | // Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/model/UrlMapping.java
// public class UrlMapping {
//
// protected HttpMethod httpMethod = HttpMethod.GET;
// protected String url = "/";
// protected List<MethodParameterDescriptor> parameters = new ArrayList<MethodParameterDescriptor>();
// protected String[] headers = new String[0];
// protected String[] consumes = new String[0];
// protected String[] produces = new String[0];
// protected String[] cookies = new String[0];
//
// public String[] getCookies() {
// return cookies;
// }
//
// public void setCookies(String[] cookies) {
// this.cookies = cookies;
// }
//
// public String[] getConsumes() {
// return consumes;
// }
//
// public void setConsumes(String[] consumes) {
// this.consumes = consumes;
// }
//
// public String[] getProduces() {
// return produces;
// }
//
// public void setProduces(String[] produces) {
// this.produces = produces;
// }
//
// public String[] getHeaders() {
// return headers;
// }
//
// public void setHeaders(String[] headers) {
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public void setHttpMethod(HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// }
//
// public List<MethodParameterDescriptor> getParameters() {
// return parameters;
// }
//
// public void setParameters(List<MethodParameterDescriptor> parameters) {
// this.parameters = parameters;
// }
//
// public void addDescriptor(MethodParameterDescriptor descriptor) {
// parameters.add(descriptor);
// }
//
// public boolean hasRequestBody(String parameter) {
// for (MethodParameterDescriptor descriptor : parameters)
// if (parameter.equals(descriptor.getName())
// && (descriptor.getType().equals(Type.requestBody) || descriptor.getType().equals(Type.requestPart)))
// return true;
// return false;
// }
// }
// Path: src/main/java/com/github/ggeorgovassilis/springjsonmapper/spring/mapping/PatchMappingAnnotationResolver.java
import com.github.ggeorgovassilis.springjsonmapper.model.UrlMapping;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PatchMapping;
package com.github.ggeorgovassilis.springjsonmapper.spring.mapping;
/**
* Looks at class and method and extract mapping annotations such as
* {@link PatchMapping}
*
* @author minasgull
*/
public class PatchMappingAnnotationResolver extends BaseAnnotationResolver<PatchMapping> {
@Override | public UrlMapping resolve(PatchMapping ann) { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.