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

Fix issue with DataTransferHashMap handling missing data #3141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
Expand Down
25 changes: 25 additions & 0 deletions update-header.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
#!/bin/bash
#
# This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
#
# The MIT License
# Copyright © 2014-2022 Ilkka Seppälä
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#


# Find all README.md files in subdirectories one level deep
# and replace "### " with "## " at the beginning of lines
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.iluwatar.visitor.example;
import java.util.HashMap;
import java.util.Map;

public class DataTransferHashMap {
private Map<String, String> dataMap;

public DataTransferHashMap() {
// Initialize the map
dataMap = new HashMap<>();
}

// Method to add data
public void addData(String key, String value) {
dataMap.put(key, value);
}

// Method to retrieve data
public String getData(String key) {
return dataMap.get(key);
}

// Method to remove data
public void removeData(String key) {
dataMap.remove(key);
}

// Method to display all data in the map
public void displayData() {
for (Map.Entry<String, String> entry : dataMap.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}

public static void main(String[] args) {
// Creating an instance of the DataTransferHashMap class
DataTransferHashMap transfer = new DataTransferHashMap();

// Adding some data
transfer.addData("Name", "John");
transfer.addData("Age", "25");
transfer.addData("Location", "New York");

// Displaying all data
transfer.displayData();

// Retrieve a single value
System.out.println("Retrieved Name: " + transfer.getData("Name"));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.iluwatar.visitor.example.datatransfer;
import com.iluwatar.visitor.example.DataTransferHashMap;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

public class DataTransferHashMapTest {

@Test
public void testAddData() {
DataTransferHashMap transferHash = new DataTransferHashMap();
transferHash.addData("Name", "Alice");

// Assert that the data is added correctly
assertEquals("Alice", transferHash.getData("Name"));
}

@Test
public void testGetData() {
DataTransferHashMap transferHash = new DataTransferHashMap();
transferHash.addData("City", "Paris");

// Assert that the correct value is retrieved
assertEquals("Paris", transferHash.getData("City"));
}

@Test
public void testRemoveData() {
DataTransferHashMap transferHash = new DataTransferHashMap();
transferHash.addData("Country", "France");
transferHash.removeData("Country");

// Assert that the data is removed
assertNull(transferHash.getData("Country"));
}

@Test
public void testDisplayData() {
DataTransferHashMap transferHash = new DataTransferHashMap();
transferHash.addData("Name", "John");
transferHash.addData("Age", "30");


// Mock a console output if needed (or just visually verify it during test runs)
transferHash.displayData();

}
}
Loading