Skip to content

feat: adds Chanels objects and class lesson 16 #517

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

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.codedifferently.lesson16.comedian;

import java.util.List;
import java.util.Map;

public class Comedians {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be named Comedian singular since it represents a single individual.

private final String fullName;
private final String nationality;
private final String activeYears;
private final List<String> famousWorks;
private final double netWorth;
private final Map<String, Integer> socialMediaFollowers; // e.g., {"Instagram": 1000000}
private final boolean isStillActive;
private final ComedyGenre comedyGenre;

public enum ComedyGenre {
OBSERVATIONAL,
SATIRE,
IMPROV,
SLAPSTICK,
DARK,
PARODY
}

public Comedians(
String fullName,
String nationality,
String activeYears,
List<String> famousWorks,
double netWorth,
Map<String, Integer> socialMediaFollowers,
boolean isStillActive,
ComedyGenre comedyGenre) {
this.fullName = fullName;
this.nationality = nationality;
this.activeYears = activeYears;
this.famousWorks = famousWorks;
this.netWorth = netWorth;
this.socialMediaFollowers = socialMediaFollowers;
this.isStillActive = isStillActive;
this.comedyGenre = comedyGenre;
}

public String getFullName() {
return fullName;
}

public String getNationality() {
return nationality;
}

public String getActiveYears() {
return activeYears;
}

public ComedyGenre getGenre() {
return comedyGenre;
}

public List<String> getFamousWorks() {
return famousWorks;
}

public double getNetWorth() {
return netWorth;
}

public Map<String, Integer> getSocialMediaFollowers() {
return socialMediaFollowers;
}

public boolean isStillActive() {
return isStillActive;
}

public void validateNetWorth() throws InvalidNetWorthException {
if (netWorth < 0) {
throw new InvalidNetWorthException("Net worth cannot be negative!");
}
}

public String getCareerStatus() {
return isStillActive ? "Still active" : "Retired";
}

public void printFamousWorks() {
System.out.println("Famous Works:");
for (String work : famousWorks) {
System.out.println("- " + work);
}
}

public int totalFollowers() {
int total = 0;
for (int count : socialMediaFollowers.values()) {
total += count;
}
return total;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.codedifferently.lesson16.comedian;

public class InvalidNetWorthException extends Exception {
public InvalidNetWorthException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.codedifferently.lesson16.comedianstest;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package name is incorrect, should be the same as the class under test.


import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.codedifferently.lesson16.comedian.Comedians;
import com.codedifferently.lesson16.comedian.Comedians.ComedyGenre;
import com.codedifferently.lesson16.comedian.InvalidNetWorthException;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class ComediansTest {

private Comedians testComedian;

@BeforeEach
public void setUp() {
testComedian =
new Comedians(
"Dave Chappelle",
"USA",
"1991–present",
List.of("Killing Them Softly", "Sticks & Stones"),
50000000,
Map.of("Instagram", 1000000, "Twitter", 500000),
true,
ComedyGenre.SATIRE);
}

@Test
public void testFullName() {
assertEquals("Dave Chappelle", testComedian.getFullName());
}

@Test
public void testCareerStatus() {
assertEquals("Still active", testComedian.getCareerStatus());
}

@Test
public void testTotalFollowers() {
assertEquals(1500000, testComedian.totalFollowers());
}

@Test
public void testFamousWorksSize() {
assertEquals(2, testComedian.getFamousWorks().size());
}

@Test
public void testInvalidNetWorthThrowsException() {
Comedians brokeComedian =
new Comedians(
"Test Comic",
"USA",
"2010–present",
List.of("Set A"),
-1000.0,
Map.of("Instagram", 10000),
true,
ComedyGenre.DARK);

assertThrows(InvalidNetWorthException.class, brokeComedian::validateNetWorth);
}

@Test
public void testPrintFamousWorksOutput() {
// comments for CH to explain method from chatGPT Set up to capture System.out
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
PrintStream originalOut = System.out;
System.setOut(new PrintStream(outContent));

// Call the method
testComedian.printFamousWorks();

// Restore original System.out
System.setOut(originalOut);

// Expected output (make sure to include newline characters properly)
String expectedOutput = "Famous Works:\n- Killing Them Softly\n- Sticks & Stones\n";

// Compare output
assertEquals(expectedOutput, outContent.toString());
}

@Test
public void testGetNationality() {
assertEquals("USA", testComedian.getNationality());
}

@Test
public void testGetActiveYears() {
assertEquals("1991–present", testComedian.getActiveYears());
}

@Test
public void testGetGenre() {
assertEquals(ComedyGenre.SATIRE, testComedian.getGenre());
}
}