id
stringlengths
36
36
text
stringlengths
1
1.25M
fb1f7b0f-f89c-42ff-a3c8-1a2fa610085c
@Override public Map<String,Object> getProperties() { return delegate.getProperties(); }
f50e638e-8ff1-4935-b555-113d290c7ad9
@Override public <T>TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery) { return delegate.createQuery(criteriaQuery); }
b12e5412-7c71-4955-ae15-6a6af66dc229
@Override public <T>TypedQuery<T> createQuery(String qlString, Class<T> resultClass) { return delegate.createQuery(qlString, resultClass); }
6a2a85e6-12ac-4a51-8a4e-be0500d721cc
@Override public <T>TypedQuery<T> createNamedQuery(String name, Class<T> resultClass) { return delegate.createNamedQuery(name, resultClass); }
327bbf1f-ee51-4667-825e-31f1be1acbb3
@Override public <T>T unwrap(Class<T> cls) { return delegate.unwrap(cls); }
050713ae-5469-4db8-9a3b-532a445bebd6
@Override public EntityManagerFactory getEntityManagerFactory() { return delegate.getEntityManagerFactory(); }
8fee8e0e-7adf-4771-beb3-7410ca3fc7e2
@Override public CriteriaBuilder getCriteriaBuilder() { return delegate.getCriteriaBuilder(); }
cead6d86-b6fa-4aad-b88c-febb2e8828d2
@Override public Metamodel getMetamodel() { return delegate.getMetamodel(); }
a8c687c3-5116-40e2-aa97-3a2eb8a08068
public void setScopedListener(ScopedListener listener) { this.listener = listener; }
b9490af5-eb86-48c9-95b6-a9000e2cca33
public String getName() { return emName; }
1b7b02e6-ae02-48ff-ad07-617c18734975
public long getOwnerId() { return ownerId; }
679a8cd3-841e-4780-bc40-1059878d1f4b
public long getCreated() { return tsCreated; }
a0d9b102-d05b-4f48-89d1-aaa844281ae1
public Object getAttribute(String name) { // attributes variable is set to NULL in close() function return attributes != null ? attributes.get(name) : null; }
1a63f0f3-8ee7-456a-9548-e4de7c148fca
public void setAttribute(String name, Object value) { //if (value==null) { // removeAttribute(name); // FIXME do not keep null attributes? //} else { if (attributes==null) attributes = new HashMap<String,Object>(); attributes.put(name, value); //} }
b907029a-f6a8-4cda-a893-f59382e72d99
public Object removeAttribute(String name) { return attributes!=null ? attributes.remove(name) : null; }
aabb2a6f-a585-4ba6-845e-cd1924c24ac6
public Iterator<String> getAttributeNames() { return attributes != null ? attributes.keySet().iterator() : Collections.<String>emptySet().iterator(); }
9c5fb243-165d-402a-8030-d1e4a05693f7
public void lazilyClosed(ScopedEntityManager em);
1aa77df3-0ae7-4cd2-8e38-a07e35bef932
@Override public void contextInitialized(ServletContextEvent evt) { // Read JPA persistence unit name from xml file, // value is <persistence-unit name="myjpaunit" ...> attribute. InputStream is=null; try { is = evt.getServletContext().getResourceAsStream("/WEB-INF/classes/META-INF/persistence.xml"); if (is==null) is = evt.getServletContext().getResourceAsStream("/META-INF/persistence.xml"); String name = null; if (is != null) { // hack: no love for XML parser for this one use-case only byte[] bytes = new byte[is.available()]; is.read(bytes); String data = new String(bytes); int idx = data.indexOf("<persistence-unit"); idx = idx>0 ? data.indexOf(" name", idx+1) : -1; if (idx>0) { idx = data.indexOf('"', idx); int idxEnd = data.indexOf('"', idx+1); name = data.substring(idx+1, idxEnd); } } if (name==null) evt.getServletContext().log("persistence-unit name attribute not found, use default name"); PersistenceManager.getInstance().setPersistenceUnit(name!=null ? name : "default"); } catch (Exception ex) { evt.getServletContext().log(ex.getMessage(), ex); } finally { try { if (is!=null) is.close(); } catch (Exception ex) { } } }
1c46c3ca-e8af-4909-97b6-8ac7628e6331
@Override public void contextDestroyed(ServletContextEvent evt) { // close factory instance, its one instance per application try { PersistenceManager.getInstance().closeEntityManagerFactory(); } catch (Exception ex) { evt.getServletContext().log(ex.getMessage(), ex); } }
60d4cafa-bc1a-40f5-8fcd-864c81e37693
@Override public void requestInitialized(ServletRequestEvent evt) { //System.out.println("reqInit="+Thread.currentThread().getId()); }
3574d072-cd9b-4a77-93c9-c195dd572c1e
@Override public void requestDestroyed(ServletRequestEvent evt) { //System.out.println("reqDest="+Thread.currentThread().getId()); PersistenceManager.getInstance().closeEntityManagers(Thread.currentThread().getId()); }
c93f02db-76b6-4154-b1df-e9dd512d9542
@Override public void init(FilterConfig fc) throws ServletException { }
9aa65f5d-6cbf-4d27-95e9-14d94f13583a
@Override public void destroy() { }
c9fe645c-fee9-4b77-9aa6-8fd8f3757695
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc) throws IOException, ServletException { //System.out.println("reqInit="+Thread.currentThread().getId()); try { fc.doFilter(req, res); } finally { PersistenceManager.getInstance().closeEntityManagers(Thread.currentThread().getId()); } //System.out.println("reqDest="+Thread.currentThread().getId()); }
96d4a1ed-bfb8-4151-b9c0-ef2c353f5e7c
public static PersistenceManager getInstance() { return singleton; }
c47c9787-4b22-46b4-bba6-fd2b772a26b6
protected PersistenceManager() { emList = new HashMap<Long,List<ScopedEntityManager>>(32); scopedListener = new ScopedEntityManager.ScopedListener() { @Override public void lazilyClosed(ScopedEntityManager em) { //System.out.println(String.format("lazilyClosed %s ownerId=%d em=%d", em.getName(), em.getOwnerId(), em.hashCode() )); PersistenceManager.this.lazilyClosed(em); } }; }
6326fb74-b38c-458d-8cb4-cf6230a48698
@Override public void lazilyClosed(ScopedEntityManager em) { //System.out.println(String.format("lazilyClosed %s ownerId=%d em=%d", em.getName(), em.getOwnerId(), em.hashCode() )); PersistenceManager.this.lazilyClosed(em); }
ac6b7e76-9c98-48c3-8c15-91ecbf53ad0d
public EntityManagerFactory getEntityManagerFactory() { // http://stackoverflow.com/questions/70689/what-is-an-efficient-way-to-implement-a-singleton-pattern-in-java // use volatile-doublecheck-lazy-singleton if (emf == null) { synchronized(this) { if (emf==null) emf = Persistence.createEntityManagerFactory(persistenceUnit); } } return emf; }
15b9e3e4-6163-4bef-8872-9241c97a3228
protected synchronized void closeEntityManagerFactory() { closeEntityManagers(0); if (emf != null) { emf.close(); emf = null; } }
985b1719-abcb-4e10-93bf-287501e665af
public EntityManager getEntityManager() { return getEntityManager(Thread.currentThread().getId(), null, DEFAULT_NAME, null); }
7421156f-56c9-49e9-8213-fb01643e216b
@SuppressWarnings("rawtypes") public synchronized EntityManager getEntityManager(long ownerId, String dbName, String emName, Map map) { Long tid = Long.valueOf(ownerId); List<ScopedEntityManager> ems = emList.get(tid); ScopedEntityManager em=null; if (ems==null) { ems = new ArrayList<ScopedEntityManager>(4); emList.put(tid, ems); } else if (emName!=null) { for(int idx=0; idx<ems.size(); idx++) { em = ems.get(idx); if (emName.equals(em.getName())) return em; } } EntityManager delegate = map!=null ? getEntityManagerFactory().createEntityManager(map) : getEntityManagerFactory().createEntityManager(); em = new ScopedEntityManager(delegate, emName, ownerId); //ownerId 1..n=automanaged em.setScopedListener(scopedListener); ems.add(em); return em; }
ac900729-b04e-491f-986d-bd820d4a4f2e
public void closeEntityManagers(long ownerId) { List<ScopedEntityManager> ems; if (ownerId==0) { // close all instances, entire app context was destroyed ems = new ArrayList<ScopedEntityManager>(); synchronized(this) { for(List<ScopedEntityManager> list : emList.values()) ems.addAll(list); emList.clear(); } } else { // close instances owned by this thread, httprequest context was destroyed Long tid = Long.valueOf(ownerId); synchronized(this) { ems = emList.remove(tid); } } if (ems!=null) { for(int idx=ems.size()-1; idx>=0; idx--) try { ems.get(idx).lazyClose(); } catch(Exception ex){} } }
b0372457-3bb3-43c4-8c61-8120c706a8f5
private synchronized void lazilyClosed(ScopedEntityManager em) { Long tid = Long.valueOf(em.getOwnerId()); List<ScopedEntityManager> ems = emList.get(tid); if (ems!=null) { for(int idx=ems.size()-1; idx>=0; idx--) { if (ems.get(idx)==em) { ems.remove(idx); break; } } if (ems.isEmpty()) emList.remove(tid); } }
fc8565c4-0ad5-4086-9b5d-1be2c1f3ce15
protected void setPersistenceUnit(String name) { persistenceUnit = name; }
b79c61d6-6d65-4bf7-9803-2a22113112bd
public synchronized Map<String,String> getStatistics() { long now = System.currentTimeMillis(); Map<String,String> stats = new LinkedHashMap<String, String>(); stats.put("em.ownerCount", ""+emList.size()); int idx=-1; for(Long key : emList.keySet()) { idx++; List<ScopedEntityManager> list = emList.get(key); stats.put("em"+idx+".ownerId", ""+key); // owner ThreadId if (list!=null) { for(int idxb=0; idxb<list.size(); idxb++) { ScopedEntityManager em = list.get(idxb); stats.put("em"+idx+"."+idxb+".name", ""+em.getName()); stats.put("em"+idx+"."+idxb+".createdUTC", ""+em.getCreated()); stats.put("em"+idx+"."+idxb+".createdSince", ""+(now-em.getCreated()) ); } } } return stats; }
ba95e3b2-1fa2-48fe-a0a8-c89433107004
public static void premain(String agentArgs, Instrumentation inst) { if (agentArgs != null) { System.getProperties().put(AGENT_ARGS_KEY, agentArgs); } System.getProperties().put(INSTRUMENTATION_KEY, inst); }
bc3ddf96-ca67-4249-a1c8-bd88164eda12
public static Instrumentation getInstrumentation() { return (Instrumentation) System.getProperties().get(INSTRUMENTATION_KEY); }
eab37f40-e742-49e3-ad0b-ed53c2187eb7
public static void main(String[] args) { if (args.length <= 0) { throw new IllegalArgumentException("Directory with source files must be set"); } File file = new File(args[0]); if (!file.exists()) { try { throw new IllegalArgumentException("File not found in path '" + file.getCanonicalPath() + "'"); } catch (IOException e) { throw new IllegalArgumentException(e); } } ClassAnalyser analyser = new SimpleAnalyser(); analyser.analyse(new DirectoryAnalysisContext(file)); for (ClassDescription classDescription : analyser.classes()) { System.out.println("Class " + classDescription); } System.out.println("Total number of methods: " + analyser.totalNumberOfMethods()); }
9dd235ec-30b3-4442-ad16-73f58e463737
List<Class> getClasses() throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, IOException;
5e59cae5-52dd-4122-b220-1f77389f984b
public DirectoryAnalysisContext(File file) { this(file, file.isDirectory() ? file : file.getParentFile()); }
e8d20c7c-94b9-441e-b606-3009e9dc3bb4
public DirectoryAnalysisContext(File file, File compiledCodeDirectory) { this.path = file; this.compiledCodeDirectory = compiledCodeDirectory; }
cd4f380b-76c8-4908-b016-3f70db0eb6b0
@Override public List<Class> getClasses() throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, IOException { List<Class> classes = new ArrayList<Class>(); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); if (path.isDirectory()) { // Process directory Iterator<File> it = FileUtils.iterateFiles(path, ALLOWED_EXTENSIONS, true); File sourceFile; while (it.hasNext()) { sourceFile = it.next(); // Compile source file. compiler.run(null, null, null, sourceFile.getPath()); } } else { // Process single file compiler.run(null, null, null, path.getPath()); } // Load and instantiate compiled class. URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { compiledCodeDirectory.toURI().toURL() }, null); // System.out.println("Loaded class 1: " + classLoader.loadClass("co._7bit.dev.java.javametrics.analyse.DirectoryAnalysisContext")); System.out.println("Loaded class 2: " + classLoader.loadClass("Perm")); System.out.println("Resources:"); Enumeration<URL> resources = classLoader.getResources(""); while (resources.hasMoreElements()) { URL res = resources.nextElement(); System.out.println(" * " + res); } // Hack: wait for GC try { Thread.sleep(1000l); } catch (InterruptedException e) { e.printStackTrace(); } // Get a list of loaded classes short type = 2; Collection<Class> loadedClasses; if (type == 1) { // Use Reflections lib Reflections reflections = new Reflections("co._7bit"); for (Class clazz : reflections.getSubTypesOf(Object.class)) { if (clazz.equals(Object.class)) { System.out.println("WARN Skip class [" + clazz.getName() + "]"); continue; } try { classLoader.loadClass(clazz.getName()); classes.add(clazz); } catch (ClassNotFoundException e) { System.out.println("WARN Class [" + clazz.getName() + "] belongs to another class loader, skipping"); } } } else if (type == 2) { // Use Instrument agent Instrumentation instrumentation = InstrumentHook.getInstrumentation(); for (Class clazz : instrumentation.getInitiatedClasses(classLoader)) { // for (Class clazz : instrumentation.getAllLoadedClasses()) { if (clazz.equals(Object.class)) { continue; } try { classLoader.loadClass(clazz.getName()); classes.add(clazz); } catch (ClassNotFoundException e) { System.out.println("WARN Class [" + clazz.getName() + "] belongs to another class loader, skipping"); } } } else { // Oldschool method Field f = ClassLoader.class.getDeclaredField("classes"); f.setAccessible(true); loadedClasses = (Vector<Class>) f.get(classLoader); classes.addAll(loadedClasses); } System.out.println("Loaded classes for directory '" + compiledCodeDirectory.getCanonicalPath() + "': " + classes); return classes; }
f77d1a77-d0a8-4295-a838-238ebb5133da
@Override public void analyse(AnalysisContext context) { try { classes = new ArrayList<ClassDescription>(); for (Class clazz : context.getClasses()) { classes.add(new ClassDescription(clazz)); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
716f6b2d-84cc-47a5-b50c-5a5605f67c2a
@Override public int totalNumberOfMethods() { int cnt = 0; for (ClassDescription clazz : classes()) { cnt += clazz.methodsNumber(); } return cnt; }
2ecbe58a-1606-4835-b779-f4c5d2be27fa
@Override public Collection<ClassDescription> classes() { return classes; }
68836f15-2c59-4bcc-a401-22067e1b90cb
public ClassDescription(Class clazz) { this.name = clazz.getSimpleName(); this.uniqueName = clazz.getName(); this.methodsNumber = clazz.getDeclaredMethods().length; }
9b18a8a8-9190-4305-a23f-9ed7034bf831
public ClassDescription(String name, String uniqueName, int methodsNumber) { this.name = name; this.uniqueName = uniqueName; this.methodsNumber = methodsNumber; }
9bbcc00b-3771-46e9-98c8-bf77fc3418a8
public String name() { return name; }
f117b5ef-a87d-49e6-80e8-85ca5831e6e1
public String uniqueName() { return uniqueName; }
d48ee9e4-3cdb-461c-ae35-9de56e2bbda2
public int methodsNumber() { return methodsNumber; }
288bf704-b95d-483c-b69d-0939ba921968
@Override public String toString() { return name + "{'" + "uniqueName='" + uniqueName + '\'' + ", methodsNumber=" + methodsNumber + '}'; }
df45e0d6-1fbf-48c4-8d9b-1c8f08a2fdb4
void analyse(AnalysisContext context);
a6ee6dee-3e76-4b47-8b3b-918d95451530
int totalNumberOfMethods();
5bdd5f7b-0f05-4038-8199-562f9741dc3b
Collection<ClassDescription> classes();
44dbbd4f-51a2-4fdc-ae17-491c31108abe
private Reflections() { }
17b07b23-f5f2-413d-bf23-78eed3c5ec8e
@SuppressWarnings("unchecked") public static <T> T[] arrayFromList(final List<T> list, final Class<T> typeClass) { final T[] array = (T[]) Array.newInstance(typeClass, list.size()); return list.toArray(array); }
473bb64f-7718-400f-9da5-a833559faa33
public static <T> T createObject(final String name, final Class<? extends T> typeClass) throws Exception { final Class<?> clazz = Class.forName(name); final Class<? extends T> typedClazz = clazz.asSubclass(typeClass); return typedClazz.newInstance(); }
0744c22f-f190-4b5e-a800-45834a21e166
public static <E extends Exception> E createException(final Class<E> exceptionClass, final Throwable cause) { return createException(exceptionClass, null, cause); }
30f8c36e-d85d-45da-b101-f4b03475ba2b
public static <E extends Exception> E createException(final Class<E> exceptionClass, final String message) { return createException(exceptionClass, message, null); }
07dfcf57-c2f3-4fbd-b517-0d6979efeda4
public static <E extends Exception> E createException(final Class<E> exceptionClass, final String message, final Throwable cause) { if (message == null && cause == null) { try { return exceptionClass.newInstance(); // CHECKSTYLE:OFF } catch (InstantiationException | IllegalAccessException e) { // CHECKSTYLE:ON throw new IllegalStateException("No constructor with no arguments found for class='" + exceptionClass.getCanonicalName() + "'"); } } Constructor<E> constructor = null; try { constructor = exceptionClass.getConstructor(String.class, Throwable.class); } catch (NoSuchMethodException | SecurityException e) { throw new IllegalStateException("Constructor with single 'String-argument' expected"); } try { return constructor.newInstance(message, cause); // CHECKSTYLE:OFF } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // CHECKSTYLE:ON throw new IllegalStateException(new StringBuilder().append("Could not create exception-object. Message='") .append(message).append("', cause='").append(cause).append("'").toString()); } }
c6693e39-b557-4a38-8405-8c4a627d529a
private Asserts() { }
4a40362c-b55c-4a00-8849-cf4a112014d9
public static <T> T notNullSimple(final T arg, final String argName) { if (arg == null) { throw new NullPointerException(String.format("'%s' must not be null", argName)); } return arg; }
c4382026-93d4-45f6-a1bb-c5bb60e888c1
public static <T> T notNull(final T arg, final String message) { if (arg == null) { throw new NullPointerException(message); } return arg; }
3cd8a41f-7e0a-4c86-b64b-71c0526b2b76
public static <T, E extends Exception> T notNullSimple(final T arg, final String argName, final Class<E> exceptionClass) throws E { if (arg == null) { throw Reflections.createException(exceptionClass, String.format("'%s' must not be null", argName), null); } return arg; }
31651831-6076-42dd-84c5-28cacfaa02cf
public static <T, E extends Exception> T notNull(final T arg, final String message, final Class<E> exceptionClass) throws E { if (arg == null) { throw Reflections.createException(exceptionClass, message, null); } return arg; }
63b44e2b-c322-4265-aecf-1553ddb847dc
public static <E extends Exception, S extends CharSequence> S notNullOrEmptySimple(final S arg, final String argName, final Class<E> exceptionClass) throws E { if (arg == null || arg.length() == 0) { throw Reflections.createException(exceptionClass, String.format("'%s' must not be null||empty", argName), null); } return arg; }
08b7b4ef-812e-45a0-9405-3b7b4949de6d
public static <E extends Exception, S extends CharSequence> S notNullOrEmpty(final S arg, final String message, final Class<E> exceptionClass) throws E { if (arg == null || arg.length() == 0) { throw Reflections.createException(exceptionClass, message, null); } return arg; }
383b22d8-cfa1-4d75-afc4-03878b4189e6
public static void state(final boolean expression, final String message) { if (!expression) { throw new IllegalStateException(message); } }
6e169388-8e8e-4573-8c0c-affc2981f9d8
public static <E extends Exception> void state(final boolean expression, final String message, final Class<E> exceptionClass) throws E { if (!expression) { throw Reflections.createException(exceptionClass, message); } }
9e950d22-399e-4a6c-93e0-871e6e54d92d
public Tuple(final F first, final S second) { this.first = first; this.second = second; }
d0446779-c7ec-4efd-a703-c12cd6cef4df
public F getFirst() { return this.first; }
0d16806e-61d6-4891-9d81-9420263f9c63
public void setFirst(final F first) { this.first = first; }
8854b351-27c4-4034-9934-8957d67c71c7
public S getSecond() { return this.second; }
19c7a242-3ec7-4e2f-9414-e124aab2c23a
public void setSecond(final S second) { this.second = second; }
3fa632c4-3723-4089-98d7-1b04a705d094
@Test public void testNotNullSimple() throws Exception { this.ee.expect(NullPointerException.class); this.ee.expectMessage("'string' must not be null"); final String string = null; Asserts.notNullSimple(string, "string"); }
c0576ab6-130b-47ed-8847-908675f8b8b6
@Test public void testNotNullSimpleWithEx() throws Exception { this.ee.expect(IllegalArgumentException.class); this.ee.expectMessage("'string' must not be null"); final String string = null; Asserts.notNullSimple(string, "string", IllegalArgumentException.class); }
497e6ca7-ec6d-4a6a-ad96-68c04a1c5aee
@Test public void testNotNullSimpleTestPassed() throws Exception { final String string = "hallo"; Asserts.notNullSimple(string, "string"); }
71cd925a-1029-4027-9218-722b4cb2b90a
@Test public void testNotNullSimpleWithExTestPassed() throws Exception { final String string = "hallo"; Asserts.notNullSimple(string, "string", IllegalArgumentException.class); }
cfa28361-5098-41c7-9a33-ea739c1e1a22
@Test public void testNotNull() throws Exception { this.ee.expect(NullPointerException.class); this.ee.expectMessage("no good idea that 'string' is null"); final String string = null; Asserts.notNull(string, "no good idea that 'string' is null"); }
b46971df-8826-433b-943f-6c694fd16879
@Test public void testNotNullWithEx() throws Exception { this.ee.expect(IllegalArgumentException.class); this.ee.expectMessage("no good idea that 'string' is null"); final String string = null; Asserts.notNull(string, "no good idea that 'string' is null", IllegalArgumentException.class); }
004be2bb-61ab-4507-b2e3-ff72615b0c19
@Test public void testNotNullPassed() throws Exception { final String string = "hallo"; Asserts.notNull(string, "This test should throw no ex"); }
e942b664-3772-4e4f-91c2-f84188c57598
@Test public void testNotNullWithExPassed() throws Exception { final String string = "hallo"; Asserts.notNull(string, "This test should throw no ex", IllegalArgumentException.class); }
4b5064c3-a788-403c-a318-d4e442ab2050
@Test public void testNotNullOrEmptySimpleIsEmpty() throws Exception { this.ee.expect(IllegalStateException.class); this.ee.expectMessage("'string' must not be null||empty"); Asserts.notNullOrEmptySimple("", "string", IllegalStateException.class); }
638b87cf-0daf-48b9-9e8a-f6c364c2d436
@Test public void testNotNullOrEmptySimpleIsNull() throws Exception { this.ee.expect(IllegalArgumentException.class); this.ee.expectMessage("'string' must not be null||empty"); Asserts.notNullOrEmptySimple(null, "string", IllegalArgumentException.class); }
fb2f3c7c-53c8-47a0-8dee-0e048b24607f
@Test public void testNotNullOrEmptySimplePassed() throws Exception { Asserts.notNullOrEmptySimple("xyz", "string", IllegalArgumentException.class); }
1d782240-f6df-4ff4-86ed-a4989371cb0a
@Test public void testNotNullOrEmptyIsEmpty() throws Exception { this.ee.expect(IllegalStateException.class); this.ee.expectMessage("string must not be empty"); Asserts.notNullOrEmpty("", "string must not be empty", IllegalStateException.class); }
b17f519f-7dea-4234-a253-e06865493261
@Test public void testNotNullOrEmptyIsNull() throws Exception { this.ee.expect(IllegalArgumentException.class); this.ee.expectMessage("string must not be null"); Asserts.notNullOrEmpty(null, "string must not be null", IllegalArgumentException.class); }
0c297332-0868-4029-bd8e-f9dbacb78770
@Test public void testNotNullOrEmptyPassed() throws Exception { Asserts.notNullOrEmpty("xyz", "string", IllegalArgumentException.class); }
42dab4b3-d97b-4ecb-a611-85b1a15e3327
@Test public void testState() throws Exception { this.ee.expect(IllegalStateException.class); this.ee.expectMessage("'1' is not the same as '2'"); Asserts.state(1 == 2, "'1' is not the same as '2'"); }
2e4571de-6d14-4eee-8470-a5e12c9ded44
@Test public void testStateWithEx() throws Exception { this.ee.expect(IllegalArgumentException.class); this.ee.expectMessage("'1' is not the same as '2'"); Asserts.state(1 == 2, "'1' is not the same as '2'", IllegalArgumentException.class); }
b4bd42db-b4a8-4dfa-aa16-1d966784514c
@Test public void testStatePassed() throws Exception { final String string = "s"; Asserts.state("s".equals(string), "This test should throw no ex"); }
71d2d686-7a46-4fea-804c-bdbfec402ec4
@Test public void testStateWithExPassed() throws Exception { final String string = "s"; Asserts.state("s".equals(string), "This test should throw no ex", IllegalArgumentException.class); }
111455f2-0720-45cd-a819-6c218fad8653
@Test public void testArrayFromList() { final List<String> listOfString = Arrays.asList("one", "two", "three"); final String[] arrayOfString = Reflections.arrayFromList(listOfString, String.class); assertEquals("one", arrayOfString[0]); assertEquals("two", arrayOfString[1]); assertEquals("three", arrayOfString[2]); }
70c0064d-3b1a-4adc-9bdb-e54d286f5d0c
@Test public void testCreateObject() throws Exception { final CharSequence seq = Reflections.createObject("java.lang.StringBuilder", CharSequence.class); assertTrue(seq instanceof StringBuilder); }
994ed417-19a4-4611-9f07-de3f8ccef700
@Test public void testCreateException() throws Exception { final RuntimeException exception = Reflections.createException(IllegalStateException.class, "some message"); assertTrue(exception.getClass().equals(IllegalStateException.class)); assertEquals("some message", exception.getMessage()); }
908d3d8b-2b38-4b61-8361-705e5d5a3063
@Test public void testCreateExceptionThrowIt() { this.ee.expect(IllegalStateException.class); this.ee.expectMessage("some message"); final RuntimeException exception = Reflections.createException(IllegalStateException.class, "some message"); throw exception; }
e68018c1-7a4b-469e-a4f0-553af4f0f235
@Test public void testCreateExceptionNoRuntimeThrowIt() throws Exception { this.ee.expect(IOException.class); this.ee.expectMessage("some message"); final Exception exception = Reflections.createException(IOException.class, "some message"); throw exception; }
cac0b5da-354b-4876-be21-ef425f6df018
@Test public void testCreateExceptionWithCause() throws Exception { final RuntimeException exception = Reflections.createException(IllegalStateException.class, "some message", new FileNotFoundException()); assertTrue(exception.getClass().equals(IllegalStateException.class)); assertEquals("some message", exception.getMessage()); assertTrue(exception.getCause().getClass().equals(FileNotFoundException.class)); }
fa6f5939-c1ae-4e87-aa4d-a5742b2d74bb
@Test public void testCreateExceptionWithCauseNullMessage() throws Exception { final RuntimeException exception = Reflections.createException(IllegalStateException.class, null, new IllegalArgumentException()); assertTrue(exception.getClass().equals(IllegalStateException.class)); assertTrue(exception.getCause().getClass().equals(IllegalArgumentException.class)); }
6740cff5-ead4-445d-8068-a8c408c96691
@Test public void testCreateExceptionNullCause() throws Exception { final RuntimeException exception = Reflections.createException(IllegalStateException.class, "some message", null); assertTrue(exception.getClass().equals(IllegalStateException.class)); assertEquals("some message", exception.getMessage()); }