????Refactoring??????XP??????????????????????????????????????б????????????????????????????ù?????Ч?????????????????????????????????????????????á???java?????價????Junit Framework??????????????java????????ú?????????????????????г???Junit Framework?????????????Junit Framework????д????????????????????????????????????????????????????Junit??????????ù?????????????????????????????????????????????????????????????????????????????????Junit???????????????????????????????????и??o??????????????????????????????????????????????????Junit??????????????н????????????????Junit??????????????????????????????Refactoring??XP?????????????????????????

?????????д???

????Junit??????????о????????????????????????????????е??????????????????????????????????Junit???????????????????????????????????????????Junit?μ????????????????Ч????????????????????????????м???????????????α?д??Щ?????????????Щ?????????????????????????????Junit?μ?????????д??
??????Junit????????????????????????趨?????????????
??????????????????д?????????????????????????????????д??
???????????????????????????
????????????????????ü??е????????д????????
???????????????????????????????????????????????????????е??????????????????????????????????????????????????????????д????????????????????????????????????????á?


?????????????


???????????????????У????????????????????????????????????????磬????????д???????????????????????????????????????????μ????????
????? ?????????????????????????????н????????????????????????
????? ????????????????????????????????????????????????????????????μ??????
????? ??????????????????????????????????????????????????????
????? ???Housekeeping??????????????????????????????????
????? ????????????????????Housekeeping???????????????????????????
?????????г???????????????????????б??????????????????????????????????????????????????????????????????????????????????????????????Χ?????????????????????????????????????????????Use Case????壬???????????????????????Use Case??????С???????????????????Use Case???????????????????????????????????????????????????????????????????????????????л???????????????????????????????
?????????????????????ó???????????????????????????????????????д????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????÷??????????????任???

??????????????????е???????????????????д?????????????????????????????????м????????????????JUnitTest Infected: Programmers Love Writing Tests????е???????????????????????п?????????????????????????????Щ????????????????????????????????????????????????????С???????Щ???????????д???????????????????Щ??????????????????????????д?????????????????????????????Junit????б??????????????????
???????????????????д??????????????????????????д??????Щ????????????????а??????????????????????????Щ????????????????????????????????????????????????????????????????????????????????????д?????????????????????????????????????????????????????????????????????????????д???
???????????????????????д???????????????????


??α?д???????


??????XP???????????????????????д??????д?????????????????趨????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????У????????????????????????????????????????????????????????????????Щ?????????????????????????????????д???????????????????????????????????????????????????????????????У????????????????????Щ????????????????Junit?????и????á?
????????????????????????????????????????й????е??????????????????????????д???????????????????????????????????????????????????????????????????????????μ????????????????????趨??????????????????????????????????????????????????????y??????а???????????趨???????????????????????????????????????????????????????У?????????????????????????????????????????????仯??????????????????????????????????????????仯????磺??????????????Щ???????????????????????????????к???????????????????????????μ????????????????????????????????????????????????????????????????Щ????????????????С?
?????????????????????????????е??????????и???????????????????????????????У????????????????????????趨????????????????????????????????????е????????????????????????????????з???????????????????????????????????е????????????????????д????????????????????仯?????????????????????????????????????????????????????????????????????????Щ??????????????????????????????????У??????????????DefaultConnectionProxy?????任???з?????????????????????OracleConnectionCacheImpl???????????????μ?????


????
/**
* ????????????oracle???????????????????
*
*/
public class DefaultConnectionProxy extends ConnectionProxy {
private static final String name = "Default Connection Proxy";
private static final String description =
"????????????oracle???????????????????";
private static final String author = "Ion-Global.com";

private static final int major_version = 0;
private static final int minor_version = 9;
private static final boolean pooled = true;
private ConnectionBroker connectionBroker = null;
private Properties props;
private Properties propDescriptions;
private Object initLock = new Object();
// Test Code Begin...
/*
????????????????仯???????????????????????仯???????б????????????????
???????????????????????????????????????????Ч???ж??????????
???????ж?????OracleConnectionCacheImpl?????????????
*/
OracleConnectionCacheImpl getConnectionCache() {
if (connectionBroker == null) {
throw new IllegalStateException("You need start the server
first.");
}

return connectionBroker.getConnectionCache();
}
// Test Code End...
???????????????????????????д??????????????????????????????????????????????????????????????????????????????assert????????????error??????????????????????assert???????????ж??????????????????????? ????

??????????????????????????????????DefaultConnectionProxyTest????????????test case?????£?


?????
/**
* ???????????е?????м???????
*
*/
public class DefaultConnectionProxyTest extends TestCase {
private DefaultConnectionProxy conProxy = null;
private OracleConnectionCacheImpl cacheImpl = null;
private Connection con = null;
/** ???ò????fixture???????????????????????
*/
protected void setUp() {
conProxy = new DefaultConnectionProxy();
conProxy.start();
cacheImpl = conProxy.getConnectionCache();
}
/** ???????е??????з????????????????????????????????
?????????????????????
*/
public void testConnectionProxyStart() {
int minConnections = 0;
int maxConnections = 0;
assertNotNull(cacheImpl);
try {
minConnections =
Integer.parseInt(PropertyManager.getProperty
("DefaultConnectionProxy.minConnections"));
maxConnections =
Integer.parseInt(PropertyManager.getProperty
("DefaultConnectionProxy.maxConnections"));
} catch (Exception e) {
// ignore the exception
}
assertEquals(cacheImpl.getMinLimit()?? minConnections);
assertEquals(cacheImpl.getMaxLimit()?? maxConnections);
assertEquals(cacheImpl.getCacheSize()?? minConnections);
}
/** ???????е??????л??????????????????????????????Ч????????????
?????????????????????????????????????б仯??????assert???????????
error?????????????assert????????????????????в??????????????????
???????????Ч??????????
*/
public void testGetConnection() {
int cacheSize = cacheImpl.getCacheSize();
int activeSize = cacheImpl.getActiveSize();
int cacheSizeAfter = 0;
int activeSizeAfter = 0;
con = conProxy.getConnection();
if (con != null) {
activeSizeAfter = cacheImpl.getActiveSize();
cacheSizeAfter = cacheImpl.getCacheSize();
try {
con.close();
} catch (SQLException e) {
}
} else {
assertNotNull(con);
}
/*?????????е?????????????С?????????????????????μ????????????
??????л??????????????????μ?????
*/
if (cacheSize > activeSize) {
assertEquals(activeSize + 1?? activeSizeAfter);
assertEquals(cacheSize?? cacheSizeAfter);

} else {
assertEquals(activeSize + 1?? cacheSizeAfter);
}
}
/** ???????е??????????????????????????????????????????
????????????????б仯??????assert???????????error??????????
???assert????????????????????в??????????????????
???????????Ч??????????
*/
public void testConnectionClose() {
int minConnections = cacheImpl.getMinLimit();
int cacheSize = 0;
int activeSize = 0;
int cacheSizeAfter = 0;
int activeSizeAfter = 0;
con = conProxy.getConnection();
if (con != null) {
cacheSize = cacheImpl.getCacheSize();
activeSize = cacheImpl.getActiveSize();
try {
con.close();
} catch (SQLException e) {
}
activeSizeAfter = cacheImpl.getActiveSize();
cacheSizeAfter = cacheImpl.getCacheSize();
} else {
assertNotNull(con);
}
assertEquals(activeSize?? activeSizeAfter + 1);
/*?????????е??????????????????????????????????????????????????????????????????????????????????????????????????
*/
if (cacheSize > minConnections) {
assertEquals(cacheSize?? cacheSizeAfter + 1);
} else {
assertEquals(cacheSize?? minConnections);
}
}
/** ?????????????????????????
*/
protected void tearDown() {
cacheImpl = null;
conProxy.destroy();
}
public DefaultConnectionProxyTest(String name) {
super(name);
}
/** ?????????????????????????????????????????в????
*/
public static void main(String args[]) {
junit.textui.TestRunner.run(DefaultConnectionProxyTest.class);
}
}
??????????????????????????Junit????TestSuite?????????????????????????????????????????????????


?????????????

????????????????????????????д????????????????????????????仯????????????????????????????仯????????????????????????????????????????????????????????????????????????????????仯??????????????????е??ù????????????????б仯???????????????????????????????????????仯?????????????????????????????????????????Ч??????????????????????????


????????

???????????1973????????????????????????μ??????????????????????????н??????????飬???Java??????????μ???????????????OOA??OOD???????á?