From 7f376d8e358b8fdd40b45eb420144e1cd394c23a Mon Sep 17 00:00:00 2001 From: shuyangzhou Date: Tue, 25 Feb 2020 11:17:09 -0800 Subject: [PATCH] LPS-107396 Avoid powermock --- .../liferay/portal/dao/db/OracleDBTest.java | 54 ++++--------------- 1 file changed, 10 insertions(+), 44 deletions(-) diff --git a/modules/dxp/apps/portal/portal-dao-db/src/test/java/com/liferay/portal/dao/db/OracleDBTest.java b/modules/dxp/apps/portal/portal-dao-db/src/test/java/com/liferay/portal/dao/db/OracleDBTest.java index 4a4269cd9a5c5f..06145baac3bc31 100644 --- a/modules/dxp/apps/portal/portal-dao-db/src/test/java/com/liferay/portal/dao/db/OracleDBTest.java +++ b/modules/dxp/apps/portal/portal-dao-db/src/test/java/com/liferay/portal/dao/db/OracleDBTest.java @@ -15,27 +15,15 @@ package com.liferay.portal.dao.db; import com.liferay.portal.kernel.dao.db.DB; -import com.liferay.portal.kernel.dao.db.DBInspector; import com.liferay.portal.kernel.dao.db.test.BaseDBTestCase; -import com.liferay.portal.kernel.dao.jdbc.DataAccess; import org.junit.Assert; import org.junit.Test; -import org.junit.runner.RunWith; - -import org.mockito.stubbing.OngoingStubbing; - -import org.powermock.api.mockito.PowerMockito; -import org.powermock.api.mockito.expectation.ConstructorExpectationSetup; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; /** * @author Shinn Lok * @author Alberto Chaparro */ -@PrepareForTest({DataAccess.class, OracleDB.class}) -@RunWith(PowerMockRunner.class) public class OracleDBTest extends BaseDBTestCase { @Test @@ -61,8 +49,6 @@ public void testRewordAlterColumnTypeNoSemicolon() throws Exception { @Test public void testRewordAlterColumnTypeNotNullWhenNotNull() throws Exception { - _mockIsNullable(false); - Assert.assertEquals( "alter table DLFolder modify userName VARCHAR2(75 CHAR);\n", buildSQL( @@ -71,7 +57,7 @@ public void testRewordAlterColumnTypeNotNullWhenNotNull() throws Exception { @Test public void testRewordAlterColumnTypeNotNullWhenNull() throws Exception { - _mockIsNullable(true); + _isNullable = true; Assert.assertEquals( "alter table DLFolder modify userName VARCHAR2(75 CHAR) not " + @@ -82,8 +68,6 @@ public void testRewordAlterColumnTypeNotNullWhenNull() throws Exception { @Test public void testRewordAlterColumnTypeNullWhenNotNull() throws Exception { - _mockIsNullable(false); - Assert.assertEquals( "alter table DLFolder modify userName VARCHAR2(75 CHAR) null;\n", buildSQL("alter_column_type DLFolder userName VARCHAR(75) null;")); @@ -91,7 +75,7 @@ public void testRewordAlterColumnTypeNullWhenNotNull() throws Exception { @Test public void testRewordAlterColumnTypeNullWhenNull() throws Exception { - _mockIsNullable(true); + _isNullable = true; Assert.assertEquals( "alter table DLFolder modify userName VARCHAR2(75 CHAR);\n", @@ -107,34 +91,16 @@ public void testRewordAlterColumnTypeString() throws Exception { @Override protected DB getDB() { - return new OracleDB(0, 0); - } - - private void _mockIsNullable(boolean nullable) throws Exception { - PowerMockito.mockStatic(DataAccess.class); + return new OracleDB(0, 0) { - PowerMockito.when( - DataAccess.getConnection() - ).thenReturn( - null - ); + @Override + protected boolean isNullable(String tableName, String columnName) { + return _isNullable; + } - DBInspector dbInspector = PowerMockito.mock(DBInspector.class); - - ConstructorExpectationSetup - dbInspectorConstructorExpectationSetup = PowerMockito.whenNew( - DBInspector.class); - - OngoingStubbing dbInspectorOngoingStubbing = - dbInspectorConstructorExpectationSetup.withAnyArguments(); - - dbInspectorOngoingStubbing.thenReturn(dbInspector); - - PowerMockito.when( - dbInspector.isNullable("DLFolder", "userName") - ).thenReturn( - nullable - ); + }; } + private boolean _isNullable; + } \ No newline at end of file