Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check in test plan #340

Merged
merged 4 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ src/**
tsconfig.json
gulpfile.js
.gitignore
images/**
testprojects/**
TestPlan.md
.github/**
412 changes: 412 additions & 0 deletions TestPlan.md

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions testprojects/1.helloworld/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions testprojects/1.helloworld/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>1.helloworld</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
13 changes: 13 additions & 0 deletions testprojects/1.helloworld/src/main/java/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class HelloWorld {
public static void main(String[] args) {
System.out.print("hello");
if (args != null && args.length > 0) {
for (String arg : args) {
System.out.print(" " + arg);
}
System.out.println();
} else {
System.out.println(" world");
}
}
}
9 changes: 9 additions & 0 deletions testprojects/10.junit/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry sourcepath="lib/junit-4.12-sources.jar" kind="lib" path="lib/junit-4.12.jar"/>
<classpathentry sourcepath="lib/hamcrest-core-1.3-sources.jar" kind="lib" path="lib/hamcrest-core-1.3.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions testprojects/10.junit/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>10.junit</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
39 changes: 39 additions & 0 deletions testprojects/10.junit/build.gradle_
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

buildscript {
repositories {
mavenCentral()
}
dependencies { classpath "commons-io:commons-io:2.5" }
}

import org.apache.commons.io.FilenameUtils;

sourceSets {
main.java.srcDirs = ['src/main/java']
}
dependencies {
testCompile 'junit:junit:4.12'
}


repositories {
mavenCentral()
}

def getShortJar = { e -> FilenameUtils.getName(e) }
eclipse.classpath.file {
withXml{xml ->
def node = xml.asNode()

node.classpathentry.each{
if (it.@kind == 'lib') {
it.@path = 'lib/' + getShortJar(it.@path);
it.@sourcepath = 'lib/' + getShortJar(it.@sourcepath);
}

}
}
}
Binary file not shown.
Binary file not shown.
Binary file added testprojects/10.junit/lib/junit-4.12-sources.jar
Binary file not shown.
Binary file added testprojects/10.junit/lib/junit-4.12.jar
Binary file not shown.
17 changes: 17 additions & 0 deletions testprojects/10.junit/src/main/java/MyClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Microsoft Corporation - initial API and implementation
*******************************************************************************/

public class MyClass {
public int multiply(int x, int y) {
if (x > 999) {
throw new IllegalArgumentException("X should be less than 1000");
}
return x * y;
}
}
18 changes: 18 additions & 0 deletions testprojects/10.junit/src/test/java/MyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class MyTest {

@Test(expected = IllegalArgumentException.class)
public void testExceptionIsThrown() {
MyClass tester = new MyClass();
tester.multiply(1000, 5);
}

@Test
public void testMultiply() {
MyClass tester = new MyClass();
assertEquals("10 x 5 must be 50", 50, tester.multiply(10, 5));
}
}
18 changes: 18 additions & 0 deletions testprojects/11.maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
13 changes: 13 additions & 0 deletions testprojects/11.maven/src/main/java/com/mycompany/app/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mycompany.app;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
38 changes: 38 additions & 0 deletions testprojects/11.maven/src/test/java/com/mycompany/app/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.mycompany.app;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}

/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}

/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
6 changes: 6 additions & 0 deletions testprojects/12.gradle/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apply plugin: 'java'


sourceSets {
main.java.srcDirs = ['src/main/java']
}
5 changes: 5 additions & 0 deletions testprojects/12.gradle/src/main/java/GradleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class GradleTest {
public static void main(String[] args) {
System.out.println("This is a sample gradle project");
}
}
6 changes: 6 additions & 0 deletions testprojects/13.customcl/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry path="bin" kind="output"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
</classpath>
17 changes: 17 additions & 0 deletions testprojects/13.customcl/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>13.customcl</name>
<comment></comment>
<projects/>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments/>
</buildCommand>
</buildSpec>
<linkedResources/>
<filteredResources/>
</projectDescription>
Binary file added testprojects/13.customcl/replacement/Foo.class
Binary file not shown.
56 changes: 56 additions & 0 deletions testprojects/13.customcl/src/main/java/CustomCL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

class CustomCL extends ClassLoader {
private String baseFolder;

public CustomCL(String baseFolder) {
super(null);
this.baseFolder = baseFolder;
}

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
// load from parent
Class<?> result = findLoadedClass(name);
if (result != null) {
return result;
}

try {
File classFile = new File(baseFolder, name + ".class");
if (classFile.exists()) {
byte[] bytes = Files.readAllBytes(Paths.get(classFile.getAbsolutePath()));
return defineClass(name, bytes, 0, bytes.length);
}
} catch (IOException e) {
e.printStackTrace();
}
return getSystemClassLoader().loadClass(name);

}

@Override
protected Class loadClass(String name, boolean resolve)
throws ClassNotFoundException {
Class cls;

cls = findLoadedClass(name);
if (cls == null) {
cls = findClass(name);
}

if (cls == null) {
throw new ClassNotFoundException(name);
}

if (resolve)
resolveClass(cls);
return cls;
}

}
26 changes: 26 additions & 0 deletions testprojects/13.customcl/src/main/java/CustomClassLoaderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.io.File;

public class CustomClassLoaderTest {
public static void main(String[] args) {
File replacement = new File(new File("").getAbsolutePath(), "replacement");
if (!replacement.exists()) {
replacement = new File(new File("").getAbsolutePath(), "../replacement");
}


final String replacementFolder = replacement.getAbsolutePath();
new Thread(()-> {
try {
System.out.println("Using " + replacementFolder);
CustomCL cl = new CustomCL(replacementFolder);
Class cls = cl.loadClass("Foo");

IFoo foo = (IFoo)cls.newInstance();
new Foo().sayHello();
foo.sayHello();
} catch(Exception ex) {
ex.printStackTrace();
}
}).start();
}
}
5 changes: 5 additions & 0 deletions testprojects/13.customcl/src/main/java/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Foo implements IFoo {
public void sayHello() {
System.out.println("hello world! (version one)");
}
}
3 changes: 3 additions & 0 deletions testprojects/13.customcl/src/main/java/IFoo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface IFoo {
void sayHello();
}
6 changes: 6 additions & 0 deletions testprojects/14.encoding/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry path="bin" kind="output"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
</classpath>
17 changes: 17 additions & 0 deletions testprojects/14.encoding/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>14.encoding</name>
<comment></comment>
<projects/>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments/>
</buildCommand>
</buildSpec>
<linkedResources/>
<filteredResources/>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//src/main/java/EncodingTest.java=gbk
Loading