Skip to content
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
164 changes: 164 additions & 0 deletions group24/120509419/JUnitTest/ArrayUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaclass;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author CJ
*/
public class ArrayUtilTest {

public ArrayUtilTest() {
}

@BeforeClass
public static void setUpClass() {
}

@AfterClass
public static void tearDownClass() {
}

@Before
public void setUp() {
}

@After
public void tearDown() {
}

/**
* Test of reverseArray method, of class ArrayUtil.
*/
@Test
public void testReverseArray() {
System.out.println("reverseArray");
int[] origin = new int[]{1,2,3,4,5};
int[] expecteds = new int[]{5,4,3,2,1};
ArrayUtil instance = new ArrayUtil();
instance.reverseArray(origin);
Assert.assertArrayEquals(expecteds, origin);
// TODO review the generated test code and remove the default call to fail.
//fail("The test case is a prototype.");
}

/**
* Test of removeZero method, of class ArrayUtil.
*/
@Test
public void testRemoveZero() {
System.out.println("removeZero");
int[] oldArray = new int[]{1,2,3,4,5,6,0,0,0,0};
ArrayUtil instance = new ArrayUtil();
int[] expResult = new int[]{1,2,3,4,5,6};
int[] result = instance.removeZero(oldArray);
assertArrayEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
// fail("The test case is a prototype.");
}

/**
* Test of merge method, of class ArrayUtil.
*/
@Test
public void testMerge() {
System.out.println("merge");
int[] array1 = new int[]{3, 5, 7,8};
int[] array2 = new int[]{4, 5, 6,7};
ArrayUtil instance = new ArrayUtil();
int[] expResult = new int[]{3,4,5,6,7,8};
int[] result = instance.merge(array1, array2);
assertArrayEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
// fail("The test case is a prototype.");
}

/**
* Test of grow method, of class ArrayUtil.
*/
@Test
public void testGrow() {
System.out.println("grow");
int[] oldArray = new int[]{1,2,3,4,5};
int size = 5;
ArrayUtil instance = new ArrayUtil();
int[] expResult = new int[]{1,2,3,4,5,0,0,0,0,0};
int[] result = instance.grow(oldArray, size);
assertArrayEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
// fail("The test case is a prototype.");
}

/**
* Test of fibonacci method, of class ArrayUtil.
*/
@Test
public void testFibonacci() {
System.out.println("fibonacci");
int max = 15;
ArrayUtil instance = new ArrayUtil();
int[] expResult = new int[]{1,1,2,3,5,8,13};
int[] result = instance.fibonacci(max);
assertArrayEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
// fail("The test case is a prototype.");
}

/**
* Test of getPrimes method, of class ArrayUtil.
*/
@Test
public void testGetPrimes() {
System.out.println("getPrimes");
int max = 23;
ArrayUtil instance = new ArrayUtil();
int[] expResult = new int[]{2,3,5,7,11,13,17,19};
int[] result = instance.getPrimes(max);
assertArrayEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
// fail("The test case is a prototype.");
}

/**
* Test of getPerfectNumbers method, of class ArrayUtil.
*/
@Test
public void testGetPerfectNumbers() {
System.out.println("getPerfectNumbers");
int max = 10;
ArrayUtil instance = new ArrayUtil();
int[] expResult = new int[]{6};
int[] result = instance.getPerfectNumbers(max);
assertArrayEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
// fail("The test case is a prototype.");
}

/**
* Test of join method, of class ArrayUtil.
*/
@Test
public void testJoin() {
System.out.println("join");
int[] array = new int[]{1,2,3,4,5};
String seperator = "";
ArrayUtil instance = new ArrayUtil();
String expResult = "1-2-3-4-5";
String result = instance.join(array, seperator);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
// fail("The test case is a prototype.");
}

}
46 changes: 46 additions & 0 deletions group24/120509419/JUnitTest/struts/StrutsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaclass.struts;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;

public class StrutsTest {

@Test
public void testLoginActionSuccess() throws IOException, FileNotFoundException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {

String actionName = "login";

Map<String, String> params = new HashMap<String, String>();
params.put("name", "test");
params.put("password", "1234");

View view = Struts.runAction(actionName, params);

Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
Assert.assertEquals("login successful", view.getParameters().get("message"));
}

@Test
public void testLoginActionFailed() throws IOException, FileNotFoundException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
String actionName = "login";
Map<String, String> params = new HashMap<String, String>();
params.put("name", "test");
params.put("password", "123456"); //密码和预设的不一致

View view = Struts.runAction(actionName, params);

Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
}
}
Loading