MessageValidatorTest.kt (1109B)
1 package org.gnunet.gnunetmessenger.logic 2 3 // Import the tools we need from the JUnit testing library 4 import org.junit.Assert.assertEquals 5 import org.junit.Test 6 7 class MessageValidatorTest { 8 9 // The @Test annotation tells the system this is a test function 10 @Test 11 fun `isValid returns true for a normal message`() { 12 // 1. Arrange: Set up your test 13 val validator = MessageValidator() 14 val message = "Hello, world!" 15 16 // 2. Act: Call the function you want to test 17 val result = validator.isValid(message) 18 19 // 3. Assert: Check if the result is what you expected 20 // We expect 'true' because the message is valid 21 assertEquals(true, result) 22 } 23 24 // Test case 2: Check an empty message 25 @Test 26 fun `isValid returns false for an empty message`() { 27 // Arrange 28 val validator = MessageValidator() 29 val message = "" // Empty string 30 31 // Act 32 val result = validator.isValid(message) 33 34 // Assert 35 // This time, we expect the result to be 'false' 36 assertEquals(false, result) 37 } 38 }