Mocked List Adder

This commit is contained in:
Adam Ding 2020-11-30 16:42:50 -05:00
parent f5d71a0fff
commit bf1b0e0a98
10 changed files with 85 additions and 15 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

BIN
Lambdas/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,33 @@
<idea-plugin>
<id>com.your.company.unique.plugin.id</id>
<name>Plugin display name here</name>
<version>1.0</version>
<vendor email="support@yourcompany.com" url="http://www.yourcompany.com">YourCompany</vendor>
<description><![CDATA[
Enter short description for your plugin here.<br>
<em>most HTML tags may be used</em>
]]></description>
<change-notes><![CDATA[
Add change notes here.<br>
<em>most HTML tags may be used</em>
]]>
</change-notes>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<idea-version since-build="173.0"/>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<depends>com.intellij.modules.platform</depends>
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
</extensions>
<actions>
<!-- Add your actions here -->
</actions>
</idea-plugin>

View File

@ -83,14 +83,16 @@ public class List {
return uiPosition; return uiPosition;
} }
public void setUiPosition(Integer uiPosition) { // public void setUiPosition(Integer uiPosition) {
this.uiPosition = uiPosition; // this.uiPosition = uiPosition;
//
public ItemEntry[] getEntries() { // public ItemEntry[] getEntries() {
return entries.toArray(new ItemEntry[entries.size()]); // //return entries.toArray(new ItemEntry[entries.size()]);
} // return;
// }
public void addItemEntry(ItemEntry entry) { //
entries.add(entry); // public void addItemEntry(ItemEntry entry) {
} // //entries.add(entry);
// return;
// }
} }

View File

@ -72,7 +72,7 @@ public class ListGetter implements CallHandler{
getListEntries.setInt(1, id); getListEntries.setInt(1, id);
ResultSet getEntryResults = getListEntries.executeQuery(); ResultSet getEntryResults = getListEntries.executeQuery();
while (getEntryResults.next()) { while (getEntryResults.next()) {
retrievedList.addItemEntry(new ItemEntry(id, getEntryResults)); //retrievedList.addItemEntry(new ItemEntry(id, getEntryResults));
} }
System.out.println(retrievedList); System.out.println(retrievedList);
return retrievedList; return retrievedList;

View File

@ -1,4 +1,7 @@
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.configuration.IMockitoConfiguration;
import static org.mockito.Mockito.*;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
@ -13,8 +16,8 @@ public class TestListAdder {
} }
@Test @Test
public void testListAdderError() { public void testListAdderError() throws SQLException {
testListAdderCore(true); testListAdderCoreMock(true);
} }
public void testListAdderCore(boolean shouldThrow) { public void testListAdderCore(boolean shouldThrow) {
@ -46,4 +49,25 @@ public class TestListAdder {
throwables.printStackTrace(); throwables.printStackTrace();
} }
} }
public void testListAdderCoreMock(boolean shouldThrow) throws SQLException {
StatementInjector injector;
ArrayList<Object> rsReturns = new ArrayList<>();
rsReturns.add(1); //new listID
injector = mock(StatementInjector.class);
injector.returnedStatement = null;
injector.rsReturns = new ArrayList(rsReturns);
injector.shouldThrow = shouldThrow;
ListAdder listAdder = new ListAdder(injector, "cognitoID");
Map<String, Object> ignore = new HashMap<>();
Map<String, Object> body = TestInputUtils.addBody(ignore);
body.put("name", "aname");
if(injector.getStatementString() == null) {
assert(false);
return;
}
when(injector.getStatementString().contains("INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?);INSERT INTO ListSharee(listID, userID) VALUES(?, ?);[1, cognitoID]")).thenReturn(true);
assert (injector.getStatementString().contains("INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?);INSERT INTO ListSharee(listID, userID) VALUES(?, ?);[1, cognitoID]"));
}
} }

View File

@ -110,6 +110,11 @@
<version>4.13</version> <version>4.13</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.2.4</version>
</dependency>
</dependencies> </dependencies>
<properties> <properties>
<maven.compiler.source>1.11</maven.compiler.source> <maven.compiler.source>1.11</maven.compiler.source>

View File

@ -4,10 +4,15 @@
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="delegatedBuild" value="false" /> <option name="delegatedBuild" value="false" />
<option name="testRunner" value="PLATFORM" /> <option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="/usr/local/Cellar/gradle/6.6.1/libexec" />
<option name="gradleJvm" value="9" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />
@ -15,6 +20,7 @@
</set> </set>
</option> </option>
<option name="resolveModulePerSourceSet" value="false" /> <option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings> </GradleProjectSettings>
</option> </option>
</component> </component>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="9" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">