Skip to content

fix checkstyle errors in calculator tests and News class #137

Merged
merged 1 commit into from
May 18, 2026
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
96 changes: 74 additions & 22 deletions src/main/java/edu/ntnu/idi/idatt2003/gruppe42/model/News.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,34 @@
import java.util.List;
import java.util.Random;

/**
* Represents generated news related to a company and its market trend.
*
* <p>This class creates random news headlines and authors based on whether the
* company has a positive or negative trend.
*/
public class News {
private final String company;
private final int trend;
private final Random random = new Random();
public News(String company, int trend){

/**
* Constructs a News object for a given company and trend.
*
* @param company the company the news is related to
* @param trend a numeric indicator of market trend (positive = good news, negative = bad news)
*/
public News(String company, int trend) {
this.company = company;
this.trend = trend;
}
public String generateAuthor(){

/**
* Generates a random author email for the news article.
*
* @return a randomly selected fictional author email
*/
public String generateAuthor() {
List<String> authors = new ArrayList<>();
authors.add("market@stocks.com");
authors.add("myfatherworksatmicrosoft@hotmail.com");
Expand All @@ -36,34 +55,67 @@ public String generateAuthor(){
authors.add("nsa.definitely.not.reading.this@nsa.gov");
return authors.get(random.nextInt(authors.size()));
}
public String generateNews(){

/**
* Generates a random news headline based on the company's trend.
*
* <p>If the trend is positive, good news headlines are generated.
* If the trend is negative or zero, bad news headlines are generated.
*
* @return a randomly generated news headline
*/
public String generateNews() {
if (trend > 0) {
List<String> goodNews = new ArrayList<>();
goodNews.add("Turns out the product of " + company + " is good for the environment.");
goodNews.add("Beaver population increased due to the efforts of " + company + ".");
goodNews.add("Eminem dropped new hit single, namedropping " + company + ".");
goodNews.add("Founder of " + company + " seen feeding the homeless.");
goodNews.add(company + " got frontpage in new forbes magazine, on top companies to invest in.");
goodNews.add("IShowSpeed seen using " + company + " products in the background of viral livestream.");
goodNews.add("New studies show that " + company + " took part in inventing the rainbow back in 4,542,997,974 BC");
goodNews.add(company + " has made breakthroughs in the field of artificial intelligence.");
goodNews.add("After the release of the brand new logo of " + company + ", the logo has been called the \"a glimpse of the future\".");
goodNews.add("EX-EMPLOYEES of " + company + " REVEAL that the work environment and safety regulations are not up to basic standards but far surpassing them.");
goodNews.add("Founder of " + company + " seen rudely pushing a homeless man out of the road, saving his life.");
List<String> goodNews = getStringsGood();

return goodNews.get(random.nextInt(goodNews.size()));
}
List<String> badNews = getStringsBad();
return badNews.get(random.nextInt(badNews.size()));
}

private List<String> getStringsGood() {
List<String> goodNews = new ArrayList<>();
goodNews.add("Turns out the product of " + company + " is good for the environment.");
goodNews.add("Beaver population increased due to the efforts of " + company + ".");
goodNews.add("Eminem dropped new hit single, namedropping " + company + ".");
goodNews.add("Founder of " + company + " seen feeding the homeless.");
goodNews.add(company + " got frontpage in new forbes magazine, "
+ "on top companies to invest in.");
goodNews.add("IShowSpeed seen using " + company
+ " products in the background of viral livestream.");
goodNews.add("New studies show that " + company
+ " took part in inventing the rainbow back in 4,542,997,974 BC");
goodNews.add(company + " has made breakthroughs in the field of artificial intelligence.");
goodNews.add("After the release of the brand new logo of " + company
+ ", the logo has been called the \"a glimpse of the future\".");
goodNews.add("EX-EMPLOYEES of " + company + " REVEAL that the work environment "
+ "and safety regulations are not up to basic standards but far surpassing them.");
goodNews.add("Founder of " + company
+ " seen rudely pushing a homeless man out of the road, saving his life.");
return goodNews;
}

private List<String> getStringsBad() {
List<String> badNews = new ArrayList<>();
badNews.add("Turns out the product of " + company + " is bad for the environment.");
badNews.add("Founder of " + company + " seen rudely pushing a homeless man out of the way.");
badNews.add(company + " mentioned in epstein files.");
badNews.add(company + " has created many dams for beavers, causing them to lay around in the sun all day and die of laziness.");
badNews.add(company + " initiated a campaign to feed the homeless with burgers, using dog meat. This has decreased the number of starvation deaths among the homeless.");
badNews.add("Turns out " + company + " created the first covid-19 vaccines, which are not safe for humans.");
badNews.add(company + " has created many dams for beavers, causing them to lay"
+ " around in the sun all day and die of laziness.");
badNews.add(company + " initiated a campaign to feed the homeless with burgers, using dog meat."
+ "This has decreased the number of starvation deaths among the homeless.");
badNews.add("Turns out " + company + " created the first covid-19 vaccines, "
+ "which are not safe for humans.");
badNews.add("Extensive research of " + company + " shows financial holes in the company.");
badNews.add("Founder of " + company + " heiling at press conference discussing great ideas.");
badNews.add("EX-EMPLOYEES of " + company + " REVEAL that the work environment and safety regulations are not up to basic standards.");
badNews.add("US-Army found using " + company + " issued weapons that malfunctioned causing mass civilian casualties.");
badNews.add(company + " got frontpage in new forbes magazine, on top companies not to invest in.");
return badNews.get(random.nextInt(badNews.size()));
badNews.add("EX-EMPLOYEES of " + company + " REVEAL that the work environment"
+ " and safety regulations are not up to basic standards.");
badNews.add("US-Army found using " + company
+ " issued weapons that malfunctioned causing mass civilian casualties.");
badNews.add(company + " got frontpage in new forbes magazine, "
+ "on top companies not to invest in.");

return badNews;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link PurchaseCalculator}.
*
* <p>Verifies correct calculation of gross value, commission, tax, and total
* for a stock purchase transaction.
*/
public class PurchaseCalculatorTest {
private PurchaseCalculator calculator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link SaleCalculator}.
*
* <p>Verifies correct calculation of gross value, commission, tax, and total
* for a stock sale transaction.
*/
public class SaleCalculatorTest {
private SaleCalculator calculator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link TransactionArchive}.
*
* <p>Verifies correct storage, filtering, and analysis of transactions
* including purchases and sales.
*/
public class TransactionArchiveTest {
private TransactionArchive archive;
private Purchase purchase;
Expand Down