瀏覽代碼

warnings & tests

Ranides Atterwim 9 年之前
父節點
當前提交
5b7300e820

+ 0 - 63
assira.asm/dependency-reduced-pom.xml

@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <artifactId>assira.project</artifactId>
-    <groupId>net.ranides</groupId>
-    <version>2.1.0</version>
-    <relativePath>..</relativePath>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>net.ranides</groupId>
-  <artifactId>assira.asm</artifactId>
-  <version>5.0.4</version>
-  <build>
-    <plugins>
-      <plugin>
-        <artifactId>maven-shade-plugin</artifactId>
-        <version>1.4</version>
-        <executions>
-          <execution>
-            <phase>package</phase>
-            <goals>
-              <goal>shade</goal>
-            </goals>
-            <configuration>
-              <shadedArtifactAttached>false</shadedArtifactAttached>
-              <createDependencyReducedPom>true</createDependencyReducedPom>
-              <minimizeJar>false</minimizeJar>
-              <createSourcesJar>true</createSourcesJar>
-              <artifactSet>
-                <includes>
-                  <include>org.ow2.asm:*</include>
-                </includes>
-              </artifactSet>
-              <filters>
-                <filter>
-                  <artifact>org.ow2.asm:*</artifact>
-                  <excludes>
-                    <exclude>META-INF/**</exclude>
-                  </excludes>
-                </filter>
-              </filters>
-              <relocations>
-                <relocation>
-                  <pattern>org.objectweb.asm</pattern>
-                  <shadedPattern>net.ranides.asm</shadedPattern>
-                </relocation>
-              </relocations>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-  <dependencies>
-    <dependency>
-      <groupId>cglib</groupId>
-      <artifactId>cglib</artifactId>
-      <version>3.2.4</version>
-      <scope>compile</scope>
-    </dependency>
-  </dependencies>
-</project>
-

+ 1 - 3
assira/pom.xml

@@ -51,15 +51,13 @@
                                 <include>net/ranides/assira/events/EventObserver*</include>
                                 
                                 <!-- <include>net/ranides/assira/io/PathUtils*</include>-->
-                                <include>net/ranides/assira/io/uri/**</include>
+                                <include>net/ranides/assira/io/uri/impl/**</include>
                                 <include>net/ranides/assira/io/IOStreams*</include>
                                 
                                 <include>net/ranides/assira/lexer/**</include>
                                 
                                 <include>net/ranides/assira/math/Bitwise*</include>
                                 
-                                <include>net/ranides/assira/text/IOStrings*</include>
-                                <include>net/ranides/assira/text/StringUtils*</include>
                                 <include>net/ranides/assira/text/ResolveDialect*</include>
                                 <include>net/ranides/assira/text/LexicalCast*</include>
                                 <include>net/ranides/assira/text/format/**</include>

+ 1 - 1
assira/src/main/java/net/ranides/assira/reflection/IClass.java

@@ -47,7 +47,7 @@ public interface IClass<T> extends IElement, Comparable<IClass<?>> {
         }
     }
     
-    static <R> IClass<?> typefor(Object object) {
+    static IClass<?> typefor(Object object) {
         return IContext.DEFAULT.typefor(object);
     }
     

+ 2 - 0
assira/src/main/java/net/ranides/assira/reflection/impl/AClass.java

@@ -99,6 +99,7 @@ public abstract class AClass<T> implements IClass<T> {
         return construct(EMPTY_ARGS);
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public final T construct(Object... arguments) {
         return (T)constructors()
@@ -144,6 +145,7 @@ public abstract class AClass<T> implements IClass<T> {
         return true;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public T cast(Object value) {
         if(!isInstance(value)) {

+ 5 - 1
assira/src/main/java/net/ranides/assira/text/StringUtils.java

@@ -1064,7 +1064,11 @@ public final class StringUtils {
         public CharSequence subSequence(int begin, int end) {
             return new CSSub(text, this.begin+begin, this.begin+end);
         }
-        
+
+        @Override
+        public String toString() {
+            return text.subSequence(begin,end).toString();
+        }
     }
     
 }

+ 10 - 10
assira/src/test/java/net/ranides/assira/collection/maps/IndexTreeMapTest.java

@@ -125,16 +125,16 @@ public class IndexTreeMapTest {
         db.put(new Person("Andrew", null, 42));
         db.put(new Person(null, null, 43));
         
-        System.out.println("" + db.find().eq("name", "Tom").sort().list());
-        System.out.println("" + db.find().eq("surname", "S").sort().list());
-        
-        System.out.println("" + db.find().require().eq("name", "Tom").sort().list());
-        System.out.println("" + db.find().require().eq("surname", "S").sort().list());
-        
-        System.out.println("" + db.find().optional().eq("name", "Tom").sort().list());
-        System.out.println("" + db.find().optional().eq("surname", "S").sort().list());
-        
-        System.out.println("" + db.find()
+        assertEquals("[{Tom A 17}, {Tom B 23}]", "" + db.find().eq("name", "Tom").sort().list());
+        assertEquals("[{Andrew S 23}]","" + db.find().eq("surname", "S").sort().list());
+
+        assertEquals("[{Tom A 17}, {Tom B 23}]", "" + db.find().require().eq("name", "Tom").sort().list());
+        assertEquals("[{Andrew S 23}]", "" + db.find().require().eq("surname", "S").sort().list());
+
+        assertEquals("[{null null 43}, {null A 41}, {Tom A 17}, {Tom B 23}]", "" + db.find().optional().eq("name", "Tom").sort().list());
+        assertEquals("[{null null 43}, {Andrew null 42}, {Andrew S 23}]", "" + db.find().optional().eq("surname", "S").sort().list());
+
+        assertEquals("[{null null 43}, {Andrew null 42}, {null A 41}]", "" + db.find()
             .optional().eq("surname", "A")
             .optional().eq("name", "Andrew")
             .sort().list()

+ 0 - 4
assira/src/test/java/net/ranides/assira/io/PathUtilsTest.java

@@ -30,7 +30,6 @@ public class PathUtilsTest {
         assertEquals(".txt", PathUtils.getExtension("/base/file.log.txt"));
     }
     
-    @Ignore
     @Test
     public void testChangeExtension() {
         assertEquals(Paths.get("file.txt"), PathUtils.changeExtension("file.txt", ".txt"));
@@ -44,7 +43,6 @@ public class PathUtilsTest {
         assertEquals(Paths.get("/base","name","file.dat"), PathUtils.changeExtension("/base/name\\file.txt", ".dat"));
     }
     
-    @Ignore
     @Test
     public void testChangeExtensionP() {
         assertEquals(Paths.get("file.txt"), pce("file.txt", ".txt"));
@@ -62,7 +60,6 @@ public class PathUtilsTest {
         return PathUtils.changeExtension(Paths.get(path), ext);
     }
     
-    @Ignore
     @Test
     public void testGetSimpleName() {
         assertEquals("file", PathUtils.getSimpleName("c:/ms/file"));
@@ -78,7 +75,6 @@ public class PathUtilsTest {
         assertEquals("file.info", PathUtils.getSimpleName("/ms/file.info.txt"));
     }
     
-    @Ignore
     @Test
     public void testFromURL() throws MalformedURLException {
         assertThrows(FileSystemNotFoundException.class, ()->{

+ 0 - 41
assira/src/test/java/net/ranides/assira/io/URIReaderTest.java

@@ -1,41 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira
- */
-package net.ranides.assira.io;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import net.ranides.assira.text.StringTraits;
-import net.ranides.assira.text.StringUtils;
-import org.junit.Test;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public class URIReaderTest {
-    
-    public URIReaderTest() {
-    }
-
-    @Test
-    public void testSomeMethod() throws URISyntaxException {
-        new URI("file://c:/data");
-        
-        System.out.printf("%s%n", getFile(new URI("file://c:/windows/system/file.txt")));
-        System.out.printf("%s%n", getFile(new URI("file://c:/windows/system/")));
-        System.out.printf("%s%n", getFile(new URI("file://c:/windows/system/file.txt?")));
-        System.out.printf("%s%n", getFile(new URI("file://c:/windows/system/file.txt?charset=UTF-8&endl=unix")));
-    }
-    
-    private static final String getFile(URI uri) {
-        String p = uri.getSchemeSpecificPart();
-        String q = uri.getQuery();
-        int qs = (null==q ? 0 : q.length()+1);
-        return p.substring(2, p.length() - qs);
-    }
-    
-}

+ 12 - 3
assira/src/test/java/net/ranides/assira/reflection/impl/CDParametersTest.java

@@ -10,10 +10,14 @@ import java.io.IOException;
 import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import net.ranides.assira.reflection.IClass;
 import net.ranides.assira.reflection.mockup.ForBeanModel;
 import org.junit.Test;
 
+import static net.ranides.assira.junit.NewAssert.*;
+
 /**
  *
  * @author Ranides Atterwim <ranides@gmail.com>
@@ -26,14 +30,19 @@ public class CDParametersTest {
     @Test
     public void testSomeMethod() throws IOException {
         IClass<?> ic = IClass.typeinfo(ForBeanModel.class);
-        
+        AtomicBoolean connect = new AtomicBoolean();
+
         ic.methods().each(m -> {
             String[] names = CDParameters.getParams(m.reflective());
             if(null == names) {
-                System.out.printf(" - %s %s%n", m, Arrays.toString(names));
+                if("void net.ranides.assira.reflection.mockup.ForBeanModel.connect()".equals(m.toString())) {
+                    connect.set(true);
+                    return;
+                }
+                assertEquals(IClass.OBJECT, m.parent());
             }
         });
-        
+        assertTrue(connect.get());
     }
     
 }

+ 30 - 1
assira/src/test/java/net/ranides/assira/text/IOStringsTest.java

@@ -127,7 +127,36 @@ public class IOStringsTest {
 		assertNotEquals(TEXT, IOStrings.read(file2, Charsets.PL_DOS));
 		assertEquals(TEXT, IOStrings.read(file2, Charsets.PL_ISO));
 	}
-	
+
+    @Test
+    public void testLinesToFile() throws Exception {
+        File file1 = File.createTempFile("StringIOF2", ".txt");
+        List<String> expected = Arrays.asList("1","2", "3", "4", "5");
+
+        IOStrings.writeLines(file1, Charsets.UTF8, expected);
+
+        assertEquals(expected, IOStrings.readLines(file1, Charsets.UTF8));
+    }
+
+    @Test
+    public void testLinesToWriter() throws Exception {
+        StringWriter writer = new StringWriter();
+        List<String> expected = Arrays.asList("1", "2", "3", "4", "5");
+
+        IOStrings.writeLines(writer, expected);
+
+        assertEquals(expected, IOStrings.readLines(new StringReader(writer.toString())));
+    }
+
+    @Test
+    public void testLinesToStream() throws Exception {
+        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
+        List<String> expected = Arrays.asList("1", "2", "3", "4", "5");
+
+        IOStrings.writeLines(ostream, Charsets.UTF8, expected);
+        assertEquals(expected, IOStrings.readLines(new ByteArrayInputStream(ostream.toByteArray()), Charsets.UTF8));
+    }
+
     private String random(int size) {
         Random rand = new Random(777);
         char[] c = new char[size];

+ 13 - 0
assira/src/test/java/net/ranides/assira/text/StringUtilsTest.java

@@ -574,4 +574,17 @@ c*/
         assertEquals("Hello wORLD!", StringUtils.swapcase("hELLO World!"));
     }
 
+    @Test
+    public void testLimit() throws Exception {
+        assertLimitEquals("Hello", StringUtils.limit("Hello world", 5));
+        assertLimitEquals("Hello", StringUtils.limit("Hello", 10));
+    }
+
+    private static void assertLimitEquals(String expected, CharSequence value) {
+	    assertEquals(expected, value.toString());
+	    assertEquals(expected.length(), value.length());
+	    for(int i=0, n=expected.length(); i<n; i++) {
+	        assertEquals(expected.charAt(i), value.charAt(i));
+        }
+    }
 }